6

Does anyone has idea how to update product qty from one source to other programmatically ?

Basically I've 2 sources in my magento setup. Let say currently Salable Qty = 50 and first source has 20 qty and other has 30 qty.

I want to transfer qty from first to other programmatically ?

 Like, First contains 19 qty and other has 31 qty.
1

Try following way:


use Magento\InventoryCatalogAdminUi\Observer\SourceItemsProcessor;

Di:


private $sourceItemsProcessor;

public function __construct(
    SourceItemsProcessor $sourceItemsProcessor
) {
    $this->sourceItemsProcessor = $sourceItemsProcessor;
}

Now use:


$assignedSources = [
    [
        'source_code' => 'default',
        'quantity' => '90',
        'status' => 1,
        'name' => 'Default Source',
        'source_status' => true,
        'notify_stock_qty' => 1,
        'notify_stock_qty_use_default' => 1,
        'initialize' => 1,
        'record_id' => 'default'
    ],
    [
        'source_code' => 'new_source',
        'quantity' => '15',
        'status' => 1,
        'name' => 'New Source',
        'source_status' => true,
        'notify_stock_qty' => 1,
        'notify_stock_qty_use_default' => 1,
        'initialize' => 1,
        'record_id' => 'new_source'
    ]
];

$this->sourceItemsProcessor->process($product->getSku(), $assignedSources);

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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