inventory icon indicating copy to clipboard operation
inventory copied to clipboard

Magento 2.4.2 inventory-configurable-product-frontend-ui shows "Only 0 left" when variation product is in stock

Open gaiterjones opened this issue 4 years ago • 21 comments

Preconditions (*)

  1. Magento 2.4.2
  2. Configurable product with variation products in stock and variation qty above configured only X left threshold of 0

Steps to reproduce (*)

  1. Load configurable product page
  2. Select a variation product

Expected result (*)

  1. configurable-variation-qty element created by module-inventory-configurable-product-frontend-ui frontend stockQty template should be hidden by script in configurable-variation-qty.js because product is in stock and qty is above the only X left threshold of 0.

Actual result (*)

module-inventory-catalog-frontend-ui shows "Only 0 left"

  1. configurable-variation-qty element is shown because logic in Magento\InventoryCatalogFrontendUi\Model\IsSalableQtyAvailableForDisplaying::execute() returns false and Magento\InventoryCatalogFrontendUi\Model\GetProductQtyLeft::execute() returns 0.0 Untitled

The js in configurable-variation-qty.js only hides the element when a null value is returned, if the logic in IsSalableQtyAvailableForDisplaying returns false GetProductQtyLeft can only return a float (0.0) the js then displays this as the available qty.

GetProductQtyLeft should probably return null if the "Only X left" should not be displayed.

gaiterjones avatar Feb 10 '21 18:02 gaiterjones

Hi @gaiterjones. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.

Please, add a comment to assign the issue: @magento I am working on this


m2-assistant[bot] avatar Feb 10 '21 18:02 m2-assistant[bot]

I have the same problem, clean installation of magento 2.4.2 on localhost

The type configurable product with variation has been added, SKU, prices and stock level have been set for each product.

On the front, the product is available, when I click on the variant, the message: "Only 0 left"

I tried to change the configuration to no avail.

The main product is set to On, Available.

Each product belonging to the configuration has an inventory 10, it is turned on.

My problems are identical to those described above

daniel-pietka avatar Feb 21 '21 18:02 daniel-pietka

There doesn't seem to be much interest in this issue at the moment it's pretty easy to fix in the js but the easiest way to work around it is to disable the module.

bin/magento module:disable Magento_InventoryConfigurableProductFrontendUi

gaiterjones avatar Feb 21 '21 18:02 gaiterjones

Can you give me your solution how I solved this problem edit the code? I can code in php and a bit in JS, but I can't handle it.

daniel-pietka avatar Feb 21 '21 19:02 daniel-pietka

When I disable the Magento_InventoryConfigurableProductFrontendUi module I get an error for a configurable product.

On the front, the options for available variants have disappeared, after adding the product to the cart without selecting a variant, an error appears with the message: You must select options with the product.

There were JS errors in the Chrome console: require.js: 141 Uncaught Error: Script error for: configurableVariationQty

daniel-pietka avatar Feb 21 '21 19:02 daniel-pietka

@adigame you can try extending/updating vendor/magento/module-inventory-configurable-product-frontend-ui/view/frontend/web/js/configurable-variation-qty.js

at line 32 change

if (response.qty !== null) {

to

if (response.qty > 0) {

This is a workaround that will stop the incorrect returned value of 0 from showing the stock message.

gaiterjones avatar Feb 22 '21 13:02 gaiterjones

@gaiterjones this https://github.com/magento/inventory/issues/3276#issuecomment-783368250 it helped me a lot, thank you for your help.

daniel-pietka avatar Feb 22 '21 16:02 daniel-pietka

You could also just replace that module completely for now by adding to your composer.json:

"replace": {
    "magento/module-inventory-configurable-product-frontend-ui": "*"
}

After composer update and magento setup:upgrade it is gone.

Morgy93 avatar Mar 03 '21 15:03 Morgy93

I think the issue is coming from GetProductQtyLeft class. vendor/magento/module-inventory-catalog-frontend-ui/Model/GetProductQtyLeft.php The execute method is returning 0.0 even when it is not supposed to return any quantity. It should be returning null instead.

It can be replaced with the following:

     /**
     * Get salable qty if it is possible.
     *
     * @param string $productSku
     * @param int $stockId
     * @return mixed
     */
    public function execute(string $productSku, int $stockId)
    {
        $productSalableQty = $this->getProductSalableQty->execute($productSku, $stockId);
        if ($this->qtyLeftChecker->execute((float)$productSalableQty)) {
            return $productSalableQty;
        }

        return null;
    }

danhort avatar Mar 18 '21 18:03 danhort

Instead of hiding it, is there a potential fix that will properly show the quantity when the option is selected?

enyceedanny avatar Mar 23 '21 22:03 enyceedanny

The less invasive way to hide the message is editing the file vendor/magento/module-inventory-configurable-product-frontend-ui/view/frontend/templates/product/view/stockQty.phtml at line 8 from <?= /* @noEscape */ __('Only %1 left', "<strong>%1</strong>") ?> to <!-- <?= /* @noEscape */ __('Only %1 left', "<strong>%1</strong>") ?> -->

THIS IS NOT A SOLUTION!

angelo983 avatar Mar 31 '21 16:03 angelo983

@adigame you can try extending/updating vendor/magento/module-inventory-configurable-product-frontend-ui/view/frontend/web/js/configurable-variation-qty.js

at line 32 change

if (response.qty !== null) {

to

if (response.qty > 0) {

This is a workaround that will stop the incorrect returned value of 0 from showing the stock message.

It works for me to get the 0 stock away, but I prefer the right number of stock for our B2B shop.

Cisca22 avatar Apr 21 '21 08:04 Cisca22

Issue reproduced in 2.4.2-p1

christianlknudsen avatar Jun 02 '21 09:06 christianlknudsen

Hi @kamanivardhman! :wave: Thank you for collaboration. Only members of Community Contributors Team are allowed to be assigned to the issue. Please use @magento add to contributors team command to join Contributors team.

m2-assistant[bot] avatar Jun 17 '21 08:06 m2-assistant[bot]

@magento I check the whole issue and The issue is fixed. Here is the pull request https://github.com/magento/inventory/commit/337f8b7d56d81c217d5bf2bac180b315fd6120d0#diff-3f538d466d079fb270c25ba797de6eae883621a534997a58de77551b095df1ab

kamanivardhman avatar Jun 22 '21 11:06 kamanivardhman

@magento I check the whole issue and The issue is fixed. Here is the pull request 337f8b7#diff-3f538d466d079fb270c25ba797de6eae883621a534997a58de77551b095df1ab

The desktop has disappeared, but the mobile has not disappeared

aliantech avatar Jul 22 '21 16:07 aliantech

With this mod applied, there is still an issue with mobile view: Screenshot from 2021-08-11 12-54-08

bluedarter2 avatar Aug 11 '21 19:08 bluedarter2

what about in vendor/magento/module-inventory-configurable-product-frontend-ui/view/frontend/web/js/configurable-variation-qty.js

from if (response.qty !== null && response.qty > 0) { to if (response.qty !== null && parseFloat(response.qty) > 0) {

MarekCernak avatar Sep 01 '21 15:09 MarekCernak

Issue reproduced in 2.4.2-p1 after upgrading from Magento 2.3.5. Tried @MarekCernak solution worked for me.

JonathanHelvey avatar Oct 06 '21 00:10 JonathanHelvey

I'm still dealing with same issue in 2.4.6

None of the "fixes" worked only to hide from stockQty. I'm still getting Only %1 Left, anyone fixed in another way?

inspiration88 avatar Jun 25 '23 06:06 inspiration88

Bump. Issue still persists. 2.4.6-p2

0xMatt avatar Aug 25 '23 10:08 0xMatt