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

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

Open
gaiterjones opened this issue Feb 10, 2021 · 21 comments

Comments

@gaiterjones
Copy link

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.

@m2-assistant
Copy link

m2-assistant bot commented Feb 10, 2021

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


@daniel-pietka
Copy link

daniel-pietka commented Feb 21, 2021

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

@gaiterjones
Copy link
Author

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

@daniel-pietka
Copy link

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
Copy link

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

@gaiterjones
Copy link
Author

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

@daniel-pietka
Copy link

@gaiterjones this #3276 (comment) it helped me a lot, thank you for your help.

@Morgy93
Copy link
Member

Morgy93 commented Mar 3, 2021

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.

@danhort
Copy link

danhort commented Mar 18, 2021

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

@enyceedanny
Copy link

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

@angelo983
Copy link
Member

angelo983 commented Mar 31, 2021

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!

@Cisca22
Copy link

Cisca22 commented Apr 21, 2021

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

@christianlknudsen
Copy link

Issue reproduced in 2.4.2-p1

@m2-assistant
Copy link

m2-assistant bot commented Jun 17, 2021

Hi @kamanivardhman! 👋
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.

@kamanivardhman
Copy link

kamanivardhman commented Jun 22, 2021

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

@aliantech
Copy link

@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

@bluedarter2
Copy link

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

@MarekCernak
Copy link

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) {

@JonathanHelvey
Copy link

JonathanHelvey commented Oct 6, 2021

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

@inspiration88
Copy link

inspiration88 commented Jun 25, 2023

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?

@0xMatt
Copy link

0xMatt commented Aug 25, 2023

Bump. Issue still persists. 2.4.6-p2

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