Solidus supports split shipments out of the box. This feature addresses the needs of complex Solidus stores who require detailed inventory management, and sophisticated shipping and warehouse logic. It also allows you to manage shipments from multiple stock locations.
Spree::Stock::SimpleCoordinator
contains all of the
business logic for how stock should be packaged. If your store requires a
specialized flow for handling split shipments, the simple coordinator should
provide a good starting point for customizations.
An order's shipments are determined by
Spree::Stock::SimpleCoordinator
while the
Spree::Order
's' state is set to delivery
. This occurs before the customer
has completed their order at checkout.
The SimpleCoordinator
takes an order and builds as many shipments as are
necessary to fulfill it.
The simple coordinator performs a number of tasks in order to create shipment proposals:
Spree::Shipment
object that is associated with
the current order.After the proposed shipments have been determined, the customer can continue the
checkout process and take the order from the delivery
state to the payment
state.
Stock locations considered while building shipments are configurable via a Stock Locations Filter class. Since the order of stock locations is important to determine which stock items needs to be picked up first, there is also a Stock Locations Sorter class that is easily customizable as well.
In order to split shipments, Solidus runs a series of splitters in sequence. The first splitter in the sequence takes the array of packages from the order, splits the order into packages according to its rules, then passes the packages on to the next splitter in the sequence.
For each generated shipment, a shipping method can be assigned.
Solidus comes with three built-in splitters:
Spree::Stock::Splitter::Weight.threshold
value in an initializer. (It
defaults to 150
.)Note that splitters can be customized. Create you own splitter by inheriting the
Spree::Stock::Splitter::Base
class.
For an example of a simple splitter, take a look at Solidus's
weight
splitter
. This splitter ensures that items that weigh
more than 150
are split into their own shipment.
After you create your splitter, you need to add it to the array of splitters
that Solidus uses. To do this, add the following to your
config/initializers/spree.rb
file:
Rails.application.config.spree.stock_splitters << Spree::Stock::Splitter::CustomSplitter
You can also override the splitters used in Solidus, rearrange them, or
otherwise customize them from the config/initializers/spree.rb
:
Rails.application.config.spree.stock_splitters = [
Spree::Stock::Splitter::CustomSplitter,
Spree::Stock::Splitter::ShippingCategory
]
If you want to add different splitters for each of your Spree::StockLocation
s,
you can decorate the Spree::Stock::SimpleCoordinator
class and override the
splitters
method.
If you don't want to split packages in any case, you can set the
config.spree.stock_splitters
option to an empty array:
Rails.application.config.spree.stock_splitters = []
Solidus is an open source platform supported by the community. We encourage everyone using Solidus to contribute back to the documentation and the code.
If you’re interested in contributing to the docs, get started with the contributing guidelines. If you see something that needs fixing and can’t do it yourself, please send us an email.