美文网首页
Magento2怎么批量修改商品的可售库存?

Magento2怎么批量修改商品的可售库存?

作者: 程序员的自我修养 | 来源:发表于2020-07-24 14:27 被阅读0次

    通过下面两行代码可以获取sku 的可售库存:

    $this->_getSalableQuantityDataBySku = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku');

    $salable = $this->_getSalableQuantityDataBySku->execute($sku);

    从这段代码可以知道,上面方法获取到的可售库存,为多个仓库的qty,二维数组;

    从这段代码可以看到,qty可售库存的计算方式,如果$productQtyInstock为我需要修改后得到的值,那么实际写入表字段的值为:productQtyInstock+$minQty-$this->getReservatiionsQuantity->execute($sku,$stockId);

    涉及到的表:

    inventory_reservation

    cataloginventory_stock_item

    cataloginventory_stock_status

    相关文章

      网友评论

          本文标题:Magento2怎么批量修改商品的可售库存?

          本文链接:https://www.haomeiwen.com/subject/eqmjlktx.html