1

I tried the below scenario in Magento 2.4.0 version

Anyone please try the below scenario in your Magento 2.4 version ?

I created one configurable product and it's two simple children with 100 qty.

Before Order place: I went to Admin Product Grid there are two columns Quantity and Salable Quantity. One child product has 100 Quantity and Salable Quantity are 100

After Placed order: In Admin product grid, same child product has salable quantity is 0 and quantity column shows 100 quantity and when I went product edit page it still shows in stock status even no backorders and Manages stock set to yes and I did reindex.

Expected Result: when the product becomes zero salable quantity it should automatically change stock status out of stock

Actual Result: when the product becomes zero salable quantity it does not change stock status from in stock to `out of stock

Anyone faces above issue in your Magento 2.4 version ?

10
  • That is what currently works with MSI. You need modification for that.
    – Sohel Rana
    Commented Aug 1, 2021 at 9:48
  • @SohelRana it means is it bug right now ? Commented Aug 1, 2021 at 9:54
  • I also got a report from this issue from my manager last week; I might take a look at it in the week. I'll keep track of it. Default source indicate 0 quantity, but the product still shows as available in front side. Don't know if this is a m2 bug or not, but there has to be a workaround. I'll keep you updated of what I find.
    – Claims
    Commented Aug 1, 2021 at 9:56
  • @Claims ok thanks Commented Aug 1, 2021 at 10:18
  • yes. That is bug.
    – Sohel Rana
    Commented Aug 1, 2021 at 11:03

3 Answers 3

1
+50

In My Project, I am using external Stock so Order Invoices & shipments not happening at Magento's end, so I need to change the inventory based on order placement.

The following module works as you expect. If the customer places the order if qty 1 then this below module made that product stock status as "Out of Stock".

This module removes or disables the inventory reservation on order placement. You can find the order item qty decrement in order placement itself for qty & salable qty.

Magento 2 Module Source Link : https://github.com/AmpersandHQ/magento2-disable-stock-reservation

Please check the additional notes on the reference link.

4
  • 2
    we are using MSI so we do not want to disable MSI Commented Aug 6, 2021 at 13:23
  • As far as I was aware that module doesn't disable MSI completely, but basically changes the reduction of stock on order and not on shipment. So it basically stops the reservation system happening
    – elfling
    Commented Aug 6, 2021 at 15:34
  • @elfling because of this issue at frontend it does not show out of stock message at frontend side. I just checked the Magento2.4.3 release notes and they solved issue and show out of stock message when salable qty becomes zero.check this link devdocs-beta.magento.com/guides/v2.4/release-notes/…. Commented Aug 6, 2021 at 17:54
  • @jitendrapatel thank you Commented Aug 7, 2021 at 12:51
0

There are some steps missing from the steps described, but the essential one is shipping items, if the order was placed but is still waiting to be shipped the product won't become out of stock, because it is still in your stock.

Here's a reference about the MSI workflow: How does the Magento salable quantity calculation work for merchants?

But if you use external systems to sync stock (as just salable items) or process your orders returns or shipments through a different system, then you need to disable the stock reservation, this module will handle it: https://github.com/AmpersandHQ/magento2-disable-stock-reservation

3
  • Only the bug is if salable qty is zero and qty is 1 so at frontend it will show add to cart button rather than show out of stock text if back order is no for that item. adobe says it fixed in magento 2.4.3 release notes but not fixed yet Commented Dec 22, 2021 at 19:45
  • Hi @NirajPatel, could you send the reference link? thanks Commented Dec 23, 2021 at 20:10
0

This is my hotfix.

Create extension Lexim_InventoryConfigurableProduct

etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Inventory\Model\SourceItem\Command\DecrementSourceItemQty">
        <plugin name="update_parent_configurable_product_stock_status_in_legacy_stock" disabled="true"/>
        <plugin name="update_parent_configurable_product_stock_status_in_legacy_stock_fix" type="Lexim\InventoryConfigurableProduct\Plugin\InventoryApi\UpdateParentStockStatusInLegacyStockPlugin"/>
    </type>
</config>

Plugin\InventoryApi\UpdateParentStockStatusInLegacyStockPlugin.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Lexim\InventoryConfigurableProduct\Plugin\InventoryApi;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Inventory\Model\SourceItem\Command\DecrementSourceItemQty;
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface;
use Magento\InventoryCatalogApi\Model\GetProductIdsBySkusInterface;
use Magento\ConfigurableProduct\Model\Inventory\ChangeParentStockStatus;

/**
 * Apply a fix for update configurable product stock status in legacy stock
 * after decrement quantity of child stock item
 */
class UpdateParentStockStatusInLegacyStockPlugin
{
    /**
     * @var DefaultSourceProviderInterface
     */
    private $defaultSourceProvider;

    /**
     * @var ChangeParentStockStatus
     */
    private $changeParentStockStatus;

    /**
     * @var GetProductIdsBySkusInterface
     */
    private $getProductIdsBySkus;

    /**
     * @param DefaultSourceProviderInterface $defaultSourceProvider
     * @param GetProductIdsBySkusInterface $getProductIdsBySkus
     * @param ChangeParentStockStatus $changeParentStockStatus
     */
    public function __construct(
        DefaultSourceProviderInterface $defaultSourceProvider,
        GetProductIdsBySkusInterface $getProductIdsBySkus,
        ChangeParentStockStatus $changeParentStockStatus
    ) {
        $this->defaultSourceProvider = $defaultSourceProvider;
        $this->getProductIdsBySkus = $getProductIdsBySkus;
        $this->changeParentStockStatus = $changeParentStockStatus;
    }

    /**
     * Make configurable product out of stock if all its children out of stock
     *
     * @param DecrementSourceItemQty $subject
     * @param void $result
     * @param SourceItemInterface[] $sourceItemDecrementData
     * @return void
     * @throws NoSuchEntityException
     */
    public function afterExecute(DecrementSourceItemQty $subject, $result, array $sourceItemDecrementData): void
    {
        $productIds = [];
        $sourceItems = array_column($sourceItemDecrementData, 'source_item');

        /** @var SourceItemInterface $sourceItem */
        foreach ($sourceItems as $sourceItem) {
            $sku = $sourceItem->getSku();
            if ($sourceItem->getSourceCode() === $this->defaultSourceProvider->getCode()
                && $productId = ($this->getProductIdsBySkus->execute([$sku])[$sku] ?? null)
            ) {
                $productIds[] = (int) $productId;
            }
        }

        if ($productIds) {
            $this->changeParentStockStatus->execute($productIds);
        }
    }
}

registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Lexim_InventoryConfigurableProduct',
    __DIR__
);

module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Lexim_InventoryConfigurableProduct" setup_version="1.0.0" />
</config>

I hope you can fix the error!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.