1

I have a big issue with Magento 2.3.2. When products reach a salable quantity of 0 they still appear in stock. These products still have a physical quantity of more than zero as they haven't shipped yet, but they can still be selected on the frontend, although they won't add to basket, leading customers to think that the website is not functioning correctly. (Which I suppose it isn't). Why would my products still be selectable on the frontend even though salable stock is zero? Can anyone please shed some light?

I do have the 'inventory_stock_1' database view, but products with zero salable quantity are still listed as 'is_salable=1' in this view.

Product doesn't actually go 'Out of Stock' until 'Quantity' reaches zero (all are shipped). Something is not right.

Thank you.

  • Reindex your magento setup – Hamendra Sunthwal Apr 13 at 8:31
  • as in 'bin//magneto indexer:reindex'? Thanks Hamendra, but I've done that so many times, the 'x' has rubbed off my keypad! :) – user355218 Apr 13 at 9:01
1

I was facing the same issue in one of my projects recently. In my case the client wanted to display stock availability label (i.e. Instock/Outofstock) on category pages as well. That is not available in default magento.

When saleable qty becomes 0 and quantity is 1 in that case PDP page was showing outofstock where the category page was still showing in stock having the same code written over both places. However, the fact was that the customer could not able to add that product into cart at the end. Hence, it was creating chaos on customer's mind.

What I did was to modify magento default code a little bit as below:

Old Code :

<?php if ($block->displayProductStockStatus()) :?>
    <?php if ($_product->isAvailable()) :?>
        <div class="stock available" title="<?= $block->escapeHtmlAttr(__('Availability')) ?>">
            <span><?= $block->escapeHtml(__('In stock')) ?></span>
        </div>
    <?php else :?>
        <div class="stock unavailable" title="<?= $block->escapeHtmlAttr(__('Availability')) ?>">
            <span><?= $block->escapeHtml(__('Out of stock')) ?></span>
        </div>
    <?php endif; ?>
<?php endif; ?>

New Code :

<?php 
    $stockState = $objectManager->get('\Magento\InventorySalesApi\Api\GetProductSalableQtyInterface');
    $saleQty = $stockState->execute($_product->getSku(), 1);
?>

<?php if ($block->displayProductStockStatus()) :?>
    <?php if ($_product->isAvailable() && $saleQty > 0) :?>
        <div class="stock available" title="<?= $block->escapeHtmlAttr(__('Availability')) ?>">
            <span><?= $block->escapeHtml(__('In stock')) ?></span>
        </div>
    <?php else :?>
        <div class="stock unavailable" title="<?= $block->escapeHtmlAttr(__('Availability')) ?>">
            <span><?= $block->escapeHtml(__('Out of stock')) ?></span>
        </div>
    <?php endif; ?>
<?php endif; ?>

Hope this help you.

Thanks,

| improve this answer | |
  • Thank you for taking the time to answer Patrick. Which file did you have to amend? – user355218 Apr 13 at 19:00
  • Hello @user355218, I have installed the third party theme in my project so I have changed it in respective theme file. In default magento you can look for this file "vendor/magento/module-catalog/view/frontend/templates/product/view/type/default.phtml" and can put above code in this file by overriding it in your specific theme. For safer way, I would suggest you to check first about which file is responsible to display stock status on product page by enabling template path hints and then do the rest. If you find my answer useful then please upvote it. – Pratik Navapara Apr 14 at 8:15
0

Have you checked the value in Inventory if it is Out of Stock in Backend?

| improve this answer | |
  • They are not out of stock in the backend, as the stock is still on the system as it hasn't been shipped. I could manually change everything with zero 'salable quantity' to 'Out of Stock' but I shouldn't have to, should I. Shouldn't Magento be doing that automatically? – user355218 Apr 13 at 9:47
  • No, It doesn't do automatically when you have zero quantity in stores. Mark as out of stock in Inventory and Tell me the new result – Ahmed Chouihi Apr 13 at 9:56
  • Thank you for your answer, Ahmed. So when I have zero salable quantity, as in nothing left to sell, I have to adjust 'in stock/out of stock' manually?? Really? I may as well stick to using paper and a pencil. :) – user355218 Apr 13 at 10:09
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review – Jai Apr 13 at 10:10
  • It is @Jai. I mean he should check in Inventory not Quantity – Ahmed Chouihi Apr 13 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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