Skip to content

Create Warehouse Selection Algorithm for the Shipping #5

Closed
@vrann

Description

@vrann

Overview

Multiple Nodes Inventory implies that the products will be stored in multiple locations. When Customer buys the product, it should be shipped from the particular location. A customer usually does not care what location product was shipped from, as soon as this is the cheapest option. For the Merchant, it is important to have minimal overhead for the inventory storage and shipping costs. An algorithm which assigns the particular inventory to the order item should take all these considerations into account and select the best possible options.

Use-Case

To visualize the process of the warehouse selection let's describe the following use-case. Customers create an Order to buy products A, B and C:

Product Qty
A 5
B 2
C 7

Merchant has following stock quantities in warehouses X, Y and Z

Product Warehouse Qty
A X 10
A Y 10
A Z 10
B X 1
B Y 1
B Z 1
C X 5
C Y 2
C Z 7

There are multiple possible options on how to fulfill the order:

  1. Ship 10xA from the Warehouse X, 1xB from the X and 1xB from Z, 5xC from the X and 2xC from Y
  2. Ship 5xA from X and 5xA from Y, 1xB from the X and 1xB from Z, 7xC from the Z
  3. etc

As you can see there are multiple possible strategies on how to optimize order fulfillment:

  • try to ship as much as possible from one warehouse. This minimizes packaging costs and possibly shipping cost
  • try to distribute the load between warehouses. This minimizes storage cost
  • select warehouse based on the cost of shipment to the merchant address for the particular Carrier
  • select warehouse based on the shipment time

The order fulfillment algorithm should pick the location of the product and use it to calculate the shipping cost.

Problem

Earlier implementations of MNI identified the problems with the advanced algorithms of the warehouse selection. For example, if the warehouse selected based on the delivery cost, for every possible combination of warehouses system should perform the API call to the carrier to retrieve the shipping cost.

Approach

It is impossible for the Magento platform to predict all the circumstances which affect inventory and shipping costs for the particular merchant. That's why instead of implementing all possible optimizations of the algorithm selection, the framework will contain the interface which is used to resolve the Source for the order item. Different implementations of the algorithm will contain
Implementations, provided by the 3-d party extensions will allow affecting the priorities of the warehouse selection depending on the particular case where Magento is used.

Magento framework will provide the default, rule-based algorithm which allows configuring the priority of warehouses depending on the source origin, shipping address and the selected carrier.

Interfaces

Following interface will be called by the Magento framework at the point of shipment calculation. Changing the implementation of the interface allows affecting the algorithm of the Warehouse resolution.

use Magento\Quote\Model\Quote\Address\RateRequest;

/**
 * SourceShippingResolverInterface
 */
interface SourceResolverInterface
{
    /**
     * Resolve source shipping data
     *
     * @param RateRequest $request
     * @param ShippingRateCalculator $shippingRateCalculator
     * @return array
     */
    public function resolve(RateRequest $request, ShippingRateCalculator $shippingRateCalculator);
}

Default Algorithm

Magento will allow creating rules of selecting the fulfillment warehouse based on following pieces of information:

  • warehouses addresses
  • customer shipping address
  • carrier

The rules will be defined in the format: (Customer State, Carrier) -> Warehouse
The rules will be configured in the CSV file and imported to the Magento.

Implementation Items

Following items need to be implemented in order to make Warehouse selection work in Magento:

  • Create interface of the Warehouse resolution
  • Inject interface to the Magento framework and use it during shipping rate calculation. Implement it for complex cases such as Bundle or Grouped products.
  • Make information on selected warehouse reflected on the Order and be available during the fulfillment
  • Implement default algorithm which works based on configured rules
  • implement import of rules via CSV File

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions