0

I can't figure where to find the code displaying "The requested qty is not available" and redirecting to the product URL when we add more product than the stock.

[I'm using Magento 2.3.3 and custom theme and module]

I want to do TWO things :

  • Remove the href redirecting from the catalog to the product page

  • Display "The requested qty is not available" in catalog view when we add more product than the stock

When i do this (i add 61 items and the stock left is 60) :

I am redirecting to product page (and i don't want to), and i would move the error message to catalog view :

Thanks in advance for your help !

Alex

0

I've finally found a solution which solve my problem, i override app/design/frontend/package/theme/Magento_Catalog/templates/product/list.phtml in my custom theme, and add a MAX parameter to the input box

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');
$stockQty =  $StockState->getStockQty($_product->getId(), $_product->getStore()->getWebsiteId());
?>

<input type="number" min="1" max="<?= $stockQty ?>" step="1" name="qty" ng-attr-id="{{ 'Quantity-' + myScopeObject.index }}"
style="width: 110px" maxlength="12"
value="<?php /* @escapeNotVerified */ echo '0' ?>"
title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty" />
</div>

which is solving my problem

enter image description here

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.