How to programatically transfer qty from one to other source
-
17-02-2021 - |
質問
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.
解決
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);
所属していません magento.stackexchange