2

How to get qty from all assigned sources (Multi warehouse inventory) programmatically i.e sources and corresponding quantities.

2

You need to use Source Item management APIs: https://devdocs.magento.com/guides/v2.3/rest/modules/inventory/manage-source-items.html

For example, to retrieve all Quantities among all Sources where SKU = new_product2 located

you can do with next REST request: GET /V1/inventory/source-items?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=new_product2&searchCriteria[filter_groups][0][filters][0][condition_type]=eq

Or in the code you can just call next service: namespace Magento\InventoryApi\Api;

/**
 * Sugar service for find SourceItems by SKU
 *
 * @api
 */
interface GetSourceItemsBySkuInterface
{
    /**
     * @param string $sku
     * @return \Magento\InventoryApi\Api\Data\SourceItemInterface[]
     */
    public function execute(string $sku): array;
}

https://github.com/magento-engcom/msi/blob/2.3-develop/app/code/Magento/InventoryApi/Api/GetSourceItemsBySkuInterface.php

1
$sourceItemsBySku = $this->getSourceItemsBySku->execute($product->getSku());
$config['stockData'][$productId] = [];

foreach ($sourceItemsBySku as $sourceItem) {
    $source = $sourceItem->getSourceCode();
    $quantity = $sourceItem->getQuantity();

    $config['stockData'][$productId][$source] = $quantity;
}

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.