inventory
inventory copied to clipboard
Configurable products marked out of stock incorrectly
Preconditions (*)
- Non-default inventory source and stock has been set up
- Configurable product set up with one or more simple products
- Simple products are all out of stock at
default
source - At least one simple product in stock (with plenty of stock) at other sources
Steps to reproduce (*)
- Create and ship an order with a configurable product using a source other than the default source.
- Wait for stock reindexing and check the salable status of the configurable product
Expected result (*)
- Configurable product remains salable, as simple products are still salable at non-default sources
Actual result (*)
- Configurable product is marked as not salable
Additional information
I believe this is caused by https://github.com/magento/inventory/blob/e08a47c3501de2cbff42b3ac05058ce15d620e75/InventoryConfigurableProduct/Plugin/InventoryApi/UpdateParentStockStatusInLegacyStockPlugin.php
This plugin updates the status of configurable products based on the stock status of their simple components, but it does not take the inventory setup into account at all. In our case, the default source has not been updated at all, yet the result is that the cataloginventory_stock_item
table is updated for the configurable product. As a result of this, the inventory stock indexer takes this changed value into account and subsequently marks the configurable as not salable for any non-default stocks.
There is an additional plugin https://github.com/magento/inventory/blob/e08a47c3501de2cbff42b3ac05058ce15d620e75/InventoryConfigurableProduct/Plugin/InventoryApi/UpdateConfigurableProductParentStockStatus.php that was added later that appears to be for much the same purpose, but with additional checks that single source mode and a single store are being used.
Hi @aligent-lturner. Thank you for your report. To speed up processing of this issue, make sure that you provided sufficient information.
Add a comment to assign the issue: @magento I am working on this
- Join Magento Community Engineering Slack and ask your questions in #github channel.
I have the same problem. Any temporal solution available? Thanks
HI @aligent-lturner ,
We are also facing similar issue, when we installed either 2.4.4 CE/EE the MSI modules will be installed as part Magento Core application through composer and enabled by default.
When MSI modules are enabled the configurable parent product stock status are not updating correctly and always stays in Out Of Stock (OOS) once the stock status changed from Is In stock to OOS (either by updating child product stock status or parent).
If we disable MSI Inventory modules then configurable parent product stock status updating as expected.
I already reported this below, so please refer for information. https://github.com/magento/magento2/issues/35494#issuecomment-1143465470 https://github.com/magento/magento2/issues/35494#issuecomment-1138697607
Expecting, someone going to address this ASAP as it is Major bug for all vendors. Please let me know if anyone needs additional information.
Hello, I have a temporal solution that is working for me. We are override \Magento\ConfigurableProduct\Model\Inventory\ChangeParentStockStatus The problem is the variable $childrenIsInStock is initialized a false and then never change the value. We are calculated the value of this variable with the sum of sources quantities. This is incorrect if you use stock for websites, but this is a fastest solution for us to resolve the problem in production environment. This is my function processStockForParent
private function processStockForParent(int $productId): void
{
$criteria = $this->criteriaInterfaceFactory->create();
$criteria->setScopeFilter($this->stockConfiguration->getDefaultScopeId());
$criteria->setProductsFilter($productId);
$stockItemCollection = $this->stockItemRepository->getList($criteria);
$allItems = $stockItemCollection->getItems();
if (empty($allItems)) {
return;
}
$parentStockItem = array_shift($allItems);
$childrenIds = $this->configurableType->getChildrenIds($productId);
$criteria->setProductsFilter($childrenIds);
$stockItemCollection = $this->stockItemRepository->getList($criteria);
$allItems = $stockItemCollection->getItems();
$childrenIsInStock = false;
$childs = array();
if(isset($childrenIds[0])){
$childs = $this->productCollection->addAttributeToSelect('sku')
->addFieldToFilter('entity_id', array('in' => $childrenIds[0]));
}
foreach ($childs as $childItem) {
$salableQty = $this->getSalableQuantityDataBySku->execute($childItem->getSku());
$qty = 0;
foreach($salableQty as $source){
$qty += $source['qty'];
}
if ($qty > 0) {
$childrenIsInStock = true;
break;
}
}
if ($this->isNeedToUpdateParent($parentStockItem, $childrenIsInStock)) {
$parentStockItem->setIsInStock($childrenIsInStock);
$parentStockItem->setStockStatusChangedAuto(1);
$this->stockItemRepository->save($parentStockItem);
}
}
Is this related to https://support.magento.com/hc/en-us/articles/4428085214093-MDVA-42584-Stock-status-of-configurable-product-not-updated-automatically? It might not be as the patch mentioned the issues is via simple product being updated via API or import.
Hi, has anyone looking in to this issue?
solved in quality patch: MDVA-41061-V4 and ACSD-45488
https://devdocs.magento.com/quality-patches/tool.html#patch-grid
ACSD-45488
Seems like it wasn't solved. Still experiencing an issue with it. Configurable goes OOS
Experienced the same. Below patches didn't solve the issue. Any recent update? MDVA-41061-V4 and ACSD-45488
After shipment, the configurable product goes OOS just because of https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/ConfigurableProduct/Model/Inventory/ChangeParentStockStatus.php#L100. 2.4.4 introduced with https://github.com/magento/inventory/blob/e08a47c3501de2cbff42b3ac05058ce15d620e75/InventoryConfigurableProduct/Plugin/InventoryApi/UpdateParentStockStatusInLegacyStockPlugin.php. When you have more than one source, cataloginventory_stock_item table stock status never update and your entire things will broken. Made adjustment with MSI like @IvanVizcaino did.
Hello there, I am facing this issue too, now I think the problem stays in this file " "vendor/magento/module-inventory-configurable-product-indexer/Indexer/SelectBuilder.php". `$select = $connection->select() ->from( ['stock' => $indexTableName], [ IndexStructure::SKU => 'parent_product_entity.sku', IndexStructure::QUANTITY => 'SUM(stock.quantity)', IndexStructure::IS_SALABLE => 'IF(inventory_stock_item.is_in_stock = 0, 0, MAX(stock.is_salable))', ] )->joinInner( ['product_entity' => $this->resourceConnection->getTableName('catalog_product_entity')], 'product_entity.sku = stock.sku', [] )->joinInner( ['parent_link' => $this->resourceConnection->getTableName('catalog_product_super_link')], 'parent_link.product_id = product_entity.entity_id', [] )->joinInner( ['parent_product_entity' => $this->resourceConnection->getTableName('catalog_product_entity')], 'parent_product_entity.' . $linkField . ' = parent_link.parent_id', [] )->joinLeft( ['inventory_stock_item' => $this->resourceConnection->getTableName('cataloginventory_stock_item')], 'inventory_stock_item.product_id = parent_product_entity.entity_id' . ' AND inventory_stock_item.stock_id = ' . $this->defaultStockProvider->getId(), [] ) ->group(['parent_product_entity.sku']);
return $select;`
The IndexStructure::IS_SALABLE => 'IF(inventory_stock_item.is_in_stock = 0, 0, MAX(stock.is_salable))' condition seem wrong if the stock leagagy for configurable =0 therefore the is_salable for "inventory_stock_x" table wrong too. Can we change to "IndexStructure::IS_SALABLE => 'IF(MAX(stock.is_salable),MAX(stock.is_salable),inventory_stock_item.is_in_stock)'," instead ?
Any update here? We are experiencing in 2.4.5p-1 still
Hello,
I got the same issue on my side. I temporary created this patch : AC_FIX_INVENTORY_CONFIGURABLE_STOCK_2.4.5.patch.txt
Hello,
I got the same issue on my side. I temporary created this patch : AC_FIX_INVENTORY_CONFIGURABLE_STOCK_2.4.5.patch.txt
That patch seems to be working perfectly on 2.4.4 as well. Thanks!
This issue also exists for bundled products
And grouped products..
@RonanCapitaine are you able to raise a PR with your changes so that Magento / Adobe can review this and merge it in for the next release? That would help us all! Really appreciate your efforts.
I got the same issue on my side. I temporary created this patch : AC_FIX_INVENTORY_CONFIGURABLE_STOCK_2.4.5.patch.txt
It works fine with Magento 2.4.5-p2! Thank you very much! I note that ACSD-45488 unfortunately did not fix it.
Hello,
I got the same issue on my side. I temporary created this patch : AC_FIX_INVENTORY_CONFIGURABLE_STOCK_2.4.5.patch.txt
Hi Ronan,
I have the same issue on the Magento 2.4.6-p5.
But this patch can't apply on the M2.4.6-p5 because this file doesn't exist on this Magento version.
Please let me know if you have any solution for the last Magento version.
Thanks