Order processing with Inventory Management
Step 11. Run the Source Selection Algorithms
One of the most significant parts of Inventory Management is the Source Selection Algorithm (SSA). The Source Priority SSA analyzes and determines the best match for sources and shipping based on the priorities you specified in Step 4. Link stocks and sources . The Distance Priority SSA calculates the distance between the sources and the shipping address. Both algorithms also provide a list of source items with quantities to deduct per each source item.
For more information about shipping and SSAs, see About Source Selection Algorithm and Reservations in the Magento User Guide.
Get the list of algorithms
Currently, Magento supports SSAs based on priority and on distance. Third-party developers and future releases may add support for additional algorithms.
Endpoint:
GET <host>/rest/us/V1/inventory/source-selection-algorithm-list
Scope:
us
store view
Headers:
Content-Type
application/json
Authorization
Bearer <admin token>
Payload:
Not applicable
Response:
1
2
3
4
5
6
7
8
9
10
11
12
[
{
"code": "distance",
"title": "Distance Priority",
"description": "Algorithm which provides Source Selections based on shipping address distance from the source"
},
{
"code": "priority",
"title": "Source Priority",
"description": "Algorithm which provides Source Selections based on predefined priority of Source"
}
]
Run an SSA
The POST V1/inventory/source-selection-algorithm-result
endpoint uses the algorithm defined by the algorithmCode
attribute to calculate the recommended sources and quantities for each item defined in the items
array. In this example, we’ll select the priority
SSA. Manage source selection algorithms includes an example using the distance
priority.
This tutorial does not consider complications such selling out of products or back ordering. We can ask the SSA to determine the best way to immediately ship all the items ordered (20 items of product 24-WB01
and 50 items of product 24-WB03
). If the shippable
attribute in the response is false
, there are not enough salable items to complete a full shipment, but the merchant can still perform a partial shipment.
Endpoint:
POST <host>/rest/us/V1/inventory/source-selection-algorithm-result
Scope:
us
store view
Headers:
Content-Type
: application/json
Authorization
: Bearer <admin token>
Payload:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"inventoryRequest": {
"stockId": 2,
"items": [{
"sku": "24-WB01",
"qty": 20
},
{
"sku": "24-WB03",
"qty": 50
}]
},
"algorithmCode": "priority"
}
Response:
The SSA recommends shipping from the following sources:
Product | Source | Quantity |
---|---|---|
24-WB01 |
Baltimore | 20 |
24-WB03 |
Baltimore | 19 |
24-WB03 |
Reno | 31 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
"source_selection_items": [
{
"source_code": "baltimore_wh",
"sku": "24-WB01",
"qty_to_deduct": 20,
"qty_available": 35
},
{
"source_code": "austin_wh",
"sku": "24-WB01",
"qty_to_deduct": 0,
"qty_available": 10
},
{
"source_code": "reno_wh",
"sku": "24-WB01",
"qty_to_deduct": 0,
"qty_available": 25
},
{
"source_code": "baltimore_wh",
"sku": "24-WB03",
"qty_to_deduct": 19,
"qty_available": 19
},
{
"source_code": "reno_wh",
"sku": "24-WB03",
"qty_to_deduct": 31,
"qty_available": 42
}
],
"shippable": true
}
Verify this step
- Click Sales > Orders.
- Click the View link in the Action column for the order.
- Click Ship.
- Select different sources from the Sources menu.