I'm new to M2, and I am in a hurry to migrate my site from M1. In M1 I made my own MSI functionality, but now I would like to use the built in MSI functionality in M2. For some of the backend logic (like moving item stock from one source to another when needed), I have created my own module. The logic works, but I need to be able to update the quantity on a specific source.

I would like to know how to set new qty to a specific source for a specific sku in a custom module.

I've been at it for a week with no success. I have found answers to similar questions, but the answers are quote code, but do not say specifically where to put the code.

Seems like I should be able to use SourceItemsProcessor, but I don't know the basics in M2 on how to set it up.

1 Answer 1


You can use below code

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_sourceItemsSaveInterface = $objectManager->get('\Magento\InventoryApi\Api\SourceItemsSaveInterface');
$_sourceItemFactory = $objectManager->get('Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory');
$sourceItem = $_sourceItemFactory->create();
$sourceItem->setSourceCode('store_code'); // default : stock source

hope this helps you. accept solution if works for you.

  • Thanks a bunch!
    – Dandy
    May 26, 2021 at 11:34
  • I have, but since I am new to the forum, it will not show the upvote yet.
    – Dandy
    May 26, 2021 at 19:26
  • ok..no worries ..happy to hear it helps ..thanx for accept answer. :) May 27, 2021 at 3:56
  • @GohilRajesh, I am trying this in Magento\Catalog\Model\Product\Copier.php file's copy function so the duplicate product not copy the qty from main product and I will set my custom qty there but it is not working, Kindly suggest what I can use. I am using M2.4.2
    – Yogita
    Nov 29, 2021 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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