File tree 1 file changed +8
-4
lines changed
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 19
19
20
20
function setProductQty ($ objectManager )
21
21
{
22
- $ productId = ["193206 " ];
23
- foreach ($ productId as $ itemId ) {
22
+ $ productCollection = $ objectManager ->get ('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory ' )->create ();
23
+ $ productCollection ->addAttributeToSelect (['name, sku ' ]);
24
+ $ qty = 100 ;
25
+ foreach ($ productCollection as $ product ) {
24
26
try {
27
+ $ productId = $ product ->getId ();
25
28
$ stockModel = $ objectManager ->get ('Magento\CatalogInventory\Model\Stock\ItemFactory ' )->create ();
26
29
$ stockResource = $ objectManager ->get ('Magento\CatalogInventory\Model\ResourceModel\Stock\Item ' );
27
- $ stockResource ->load ($ stockModel , $ itemId ,"product_id " );
28
- $ stockModel ->setQty (" 90 " );
30
+ $ stockResource ->load ($ stockModel , $ productId ,"product_id " );
31
+ $ stockModel ->setQty ($ qty );
29
32
$ stockResource ->save ($ stockModel );
33
+ echo __ ("Successfully updated Qty for product SKU %1 " , $ product ->getSku ()) . PHP_EOL ;
30
34
} catch (Exception $ e ) {
31
35
echo $ e ->getMessage ();
32
36
}
You can’t perform that action at this time.
0 commit comments