Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable products marked out of stock incorrectly #3350

Open
aligent-lturner opened this issue May 18, 2022 · 19 comments
Open

Configurable products marked out of stock incorrectly #3350

aligent-lturner opened this issue May 18, 2022 · 19 comments

Comments

@aligent-lturner
Copy link

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.

@m2-assistant
Copy link

m2-assistant bot commented May 18, 2022

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


@IvanVizcaino
Copy link

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

@maheshm-kensium
Copy link

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.
magento/magento2#35494 (comment)
magento/magento2#35494 (comment)

Expecting, someone going to address this ASAP as it is Major bug for all vendors. Please let me know if anyone needs additional information.

@IvanVizcaino
Copy link

IvanVizcaino commented Jun 1, 2022

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


@alvinnguyen
Copy link

alvinnguyen commented Jun 16, 2022

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.

@maheshm-kensium
Copy link

Hi, has anyone looking in to this issue?

@danielrussob
Copy link

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

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

@Playhf
Copy link

Playhf commented Oct 5, 2022

ACSD-45488

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

@indunie
Copy link

indunie commented Oct 18, 2022

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

@sohelrana09
Copy link

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.

@cuongho803
Copy link

cuongho803 commented Nov 8, 2022

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 ?

@kwilliams-concentrix
Copy link

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

@RonanCapitaine
Copy link

Hello,

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

@kamilszewczyk
Copy link

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!

@Stuart-1
Copy link

This issue also exists for bundled products

@barryvdh
Copy link

And grouped products..

@dverkade
Copy link
Member

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

@indrisepos
Copy link

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.

@vbuiendertech
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Backlog
  
Ready for Grooming
Development

No branches or pull requests