如果有 bundle 产品,那么 MSI 就不能用了。这个很坑爹啊。
我们需要使用自己创建的 stock。最终,我们创建了一个 workaround extension 绕过了这个限制,改动不是很多,还是比较幸运的。
主要的矛盾在 vendor\magento\module-bundle\Model\Product\Type.php#isSalable
中。它查询的是 cataloginventory_stock_item
表,如果使用的不是 default stock ,那么 cataloginventory_stock_item
中的库存信息是不对的,这时候要去 inventory_stock_{stockId}
表找库存信息。
我们的解决方案是:如果产品在其他库,那么就使用 inventory_stock_{stockId}
表中 quantity 和 is_salable 来代替 cataloginventory_stock_item
表上对应的字段。