inventory icon indicating copy to clipboard operation
inventory copied to clipboard

Solve problem with \Magento\InventoryCatalog\Plugin\CatalogInventory\Model\ResourceModel\Stock\Status\AdaptAddStockDataToCollectionPlugin

Open p-bystritsky opened this issue 7 years ago • 2 comments

In Magento without MSI, when method \Magento\CatalogInventory\Model\ResourceModel\Stock\Status::addStockDataToCollection is called with $isFilterInStock = false, it is left joining cataloginventory_stock_status table. Even if some product is absent in this table (e.g. Bundle product without any options), it is present in collection selection.

In Magento with MSI, plugin method \Magento\InventoryCatalog\Plugin\CatalogInventory\Model\ResourceModel\Stock\Status\AdaptAddStockDataToCollectionPlugin::aroundAddStockDataToCollection is inner joining inventory_stock_X tables. So, if some product is absent in this table (e.g. Bundle product without any options), it will be absent in collection selection. But, if we will use left join, collection selection will contain all products, present in database.

This problem must be solved.

Also unskip test variation in \Magento\Bundle\Model\Product\FixedBundleWithSpecialPriceCalculatorTest::testPriceForFixedBundle.

p-bystritsky avatar Jun 20 '18 13:06 p-bystritsky

The best temporary fix I found is to update Model/ResourceModel/AddStockDataToCollection.php

The fix works the same way the addStockDataToCollection() does - if $isFilterInStock is "false", joinLeft is used. Otherwise, 'join' is used.

Determine method: $method = $isFilterInStock ? 'join' : 'joinLeft';

Then, instead of $collection->getSelect()->join()

use the new method: $collection->getSelect()->$method()

This can be done with a composer patch.

dmitriyzov avatar Dec 07 '20 18:12 dmitriyzov

Hi, this PR seems to solve the problem in a partial way: https://github.com/magento/inventory/pull/3085 however, the same logic should also apply to the case

$stockId === $this->defaultStockProvider->getId()

in the if statement

mizzimizzi avatar Jun 10 '21 12:06 mizzimizzi