0

I am using MSI.

When trying to create a shipment with a source code, the shipment uses the "default source" instead of the one I'm providing.

My Request: [POST] /rest/default/V1/order/5/ship

{
    "items": [
        {
            "order_item_id": 14,
            "qty": 1
        }
    ],
    "extension_attributes" : {
        "source_code" : "3"
    }
}

I've used this documentation to create my request: https://devdocs.magento.com/swagger/index_23.html#/salesShipmentRepositoryV1/salesShipmentRepositoryV1SavePost

The source "3" has sufficient stock, so this shouldn't be the issue

  • When "default source" has stock, the shipment is created uses stock from "default source"

  • When "default source" has no stock, I get the following: Shipment Document Validation Error(s):\nThe order does not allow a shipment to be created.\nYou can't create a shipment without products.

So it definitely tries to use the default source, which is what I don't want.

My question: How can I tell Magento to use my source code? Do I need to provide the source code in a different way?

0

I think you pass the wrong source code.

"source_code" : "3"

If you open the following class:

vendor/magento/module-inventory-shipping/Plugin/Sales/Shipment/AssignSourceCodeToShipmentPlugin.php

Following code snippet resolve correct source:

if (empty($sourceCode)) {
    $websiteId = $order->getStore()->getWebsiteId();
    $stockId = $this->stockByWebsiteIdResolver->execute((int)$websiteId)->getStockId();
    $sources = $this->getSourcesAssignedToStockOrderedByPriority->execute((int)$stockId);
    //TODO: need ro rebuild this logic | create separate service
    if (!empty($sources) && count($sources) == 1) {
        $sourceCode = $sources[0]->getSourceCode();
    } else {
        $sourceCode = $this->defaultSourceProvider->getCode();
    }
}

So following code returns nothing and tried from the default source.

$sources = $this->getSourcesAssignedToStockOrderedByPriority->execute((int)$stockId);

|improve this answer|||||
  • Good to know Sohel! This helped me find my issue, as specified in my own answer. It had to do with how I structured my JSON request – Toine H Dec 16 '19 at 9:31
0

The issue lies in the JSON structure. You should use arguments.extension_attributes.source_code, instead of extension_attributes.source_code as shown below:

{
    "items": [
        {
            "order_item_id": 14,
            "qty": 1
        }
    ],
    "arguments": {
        "extension_attributes" : {
            "source_code" : "3"
        }
    }
}

Then, it will create the shipment (using the specified source) and return the shipment_id as the response.

I have tested this in Magento 2.3.2-p2

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.