inventory icon indicating copy to clipboard operation
inventory copied to clipboard

Configurable products marked out of stock incorrectly

Open aligent-lturner opened this issue 2 years ago • 21 comments

Preconditions (*)

  1. Non-default inventory source and stock has been set up
  2. Configurable product set up with one or more simple products
  3. Simple products are all out of stock at default source
  4. At least one simple product in stock (with plenty of stock) at other sources

Steps to reproduce (*)

  1. Create and ship an order with a configurable product using a source other than the default source.
  2. Wait for stock reindexing and check the salable status of the configurable product

Expected result (*)

  1. Configurable product remains salable, as simple products are still salable at non-default sources

Actual result (*)

  1. 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.

aligent-lturner avatar May 18 '22 07:05 aligent-lturner

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


m2-assistant[bot] avatar May 18 '22 07:05 m2-assistant[bot]

I have the same problem. Any temporal solution available? Thanks

IvanVizcaino avatar May 18 '22 13:05 IvanVizcaino

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.

maheshm-kensium avatar Jun 01 '22 11:06 maheshm-kensium

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);
        }
    }


IvanVizcaino avatar Jun 01 '22 11:06 IvanVizcaino

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.

alvinnguyen avatar Jun 16 '22 10:06 alvinnguyen

Hi, has anyone looking in to this issue?

maheshm-kensium avatar Sep 06 '22 07:09 maheshm-kensium

solved in quality patch: MDVA-41061-V4 and ACSD-45488

https://devdocs.magento.com/quality-patches/tool.html#patch-grid

danielrussob avatar Sep 14 '22 10:09 danielrussob

ACSD-45488

Seems like it wasn't solved. Still experiencing an issue with it. Configurable goes OOS

Playhf avatar Oct 05 '22 09:10 Playhf

Experienced the same. Below patches didn't solve the issue. Any recent update? MDVA-41061-V4 and ACSD-45488

indunie avatar Oct 18 '22 17:10 indunie

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.

sohelrana09 avatar Oct 20 '22 09:10 sohelrana09

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 ?

cuongho803 avatar Nov 08 '22 02:11 cuongho803

Any update here? We are experiencing in 2.4.5p-1 still

kwilliams-concentrix avatar Nov 28 '22 22:11 kwilliams-concentrix

Hello,

I got the same issue on my side. I temporary created this patch : AC_FIX_INVENTORY_CONFIGURABLE_STOCK_2.4.5.patch.txt

RonanCapitaine avatar Dec 06 '22 14:12 RonanCapitaine

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!

kamilszewczyk avatar Dec 08 '22 15:12 kamilszewczyk

This issue also exists for bundled products

Stuart-1 avatar Jan 10 '23 12:01 Stuart-1

And grouped products..

barryvdh avatar Jan 23 '23 14:01 barryvdh

@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.

dverkade avatar Mar 13 '23 10:03 dverkade

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.

indrisepos avatar Mar 30 '23 19:03 indrisepos

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

vbuiendertech avatar Apr 25 '24 08:04 vbuiendertech