- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2019
08:42 AM
03-13-2019
08:42 AM
How to set qty for multiple sources (Multi source inventory) programmatically
Hello,
Can anyone help me for How to set qty for multiple sources (Multi-source inventory) programmatically in magento 2.
Currently, I am using this code but it's not working.
$sourceItem = $objectManager->get('\Magento\InventoryApi\Api\Data\SourceInterface')->create();
$sourceItem->setSourceCode('default');
$sourceItem->setSku($productcode);
$sourceItem->setQuantity(111);
$sourceItem->setStatus(1);
$sourceItems[] = $sourceItem;
$sourceItem->execute($sourceItems);
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2019
07:01 AM
03-14-2019
07:01 AM
Re: How to set qty for multiple sources (Multi source inventory) programmatically
Can anyone help to figure out How to Save Multiple Source item data Programmatically in Magento 2.3?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2020
12:08 AM
08-19-2020
12:08 AM
Re: How to set qty for multiple sources (Multi source inventory) programmatically
hi,
you can use the code like below to set the qty for multi source inventory.
<?php
namespace vendor\module;
use Magento\InventoryApi\Api\SourceItemsSaveInterface;
use Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory;
class class_name
{
public function __construct(
SourceItemsSaveInterface $sourceItemsSaveInterface,
SourceItemInterfaceFactory $sourceItemFactory
){
$this->_sourceItemsSaveInterface = $sourceItemsSaveInterface;
$this->_sourceItemFactory = $sourceItemFactory;
}
public function fun_name(){
$sourceItem = $this->_sourceItemFactory->create();
$sourceItem->setSourceCode('default');
$sourceItem->setSku('111');
$sourceItem->setQuantity(2);
$sourceItem->setStatus(1);
$this->_sourceItemsSaveInterface->execute([$sourceItem]);
}
}