inventory
                                
                                
                                
                                    inventory copied to clipboard
                            
                            
                            
                        Magento 2.4.2 inventory-configurable-product-frontend-ui shows "Only 0 left" when variation product is in stock
Preconditions (*)
- Magento 2.4.2
 - Configurable product with variation products in stock and variation qty above configured only X left threshold of 0
 
Steps to reproduce (*)
- Load configurable product page
 - Select a variation product
 
Expected result (*)
- 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"
- 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

 
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.
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
- Join Magento Community Engineering Slack and ask your questions in #github channel.
 
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
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
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.
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
@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 this https://github.com/magento/inventory/issues/3276#issuecomment-783368250 it helped me a lot, thank you for your help.
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.
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;
    }
                                    
                                    
                                    
                                
Instead of hiding it, is there a potential fix that will properly show the quantity when the option is selected?
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!
@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.
Issue reproduced in 2.4.2-p1
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.
@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
@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
With this mod applied, there is still an issue with mobile view:

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) {
Issue reproduced in 2.4.2-p1 after upgrading from Magento 2.3.5. Tried @MarekCernak solution worked for me.
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?
Bump. Issue still persists. 2.4.6-p2