I have limited the number of items allowed in shopping cart to 4. That I've done successfully. however I didn't like the displayed message:

The most you may purchase is 4

I want to change it, where/how can I do this?


you need to override app/code/Magento/CatalogInventory/Model/StockStateProvider.php

change the below line

->setMessage(__('The most you may purchase is %1.', $stockItem->getMaxSaleQty() * 1))


->setMessage(__('whatever message you need %1.', $stockItem->getMaxSaleQty() * 1))

for alternate solution you can create own module that contains a translation file i18n/en_US.csv. here you can translate your phrase

The most you may purchase is to whatever message you need

  • if i want to add any html for example link so how can i add that
    – ND17
    Sep 5 '16 at 5:23
  • without knowing context it is difficult to answer. can you please raise that separate question. @ND17 Sep 5 '16 at 5:36
  • check my question magento.stackexchange.com/questions/134702/…
    – ND17
    Sep 5 '16 at 5:55
  • good question! +1. Refer this link stackoverflow.com/a/13840522/5528059 and change your template here "module-theme/view/frontend/templates/messages.phtml". it is common template for notification so it is not a good practice but I hope it gives some idea about sort out. Sep 5 '16 at 7:23
  • @BilalUsean, can you explain how to override that model file to new custom module pls? Sep 24 '19 at 6:42


Another solution can be to create a theme specific translation by following the official documentation here: http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/translations/translate_practice.html

Then you only need to add the following in your magento2/app/design/frontend/Vendor/Theme/i18n/en_US.csv:

'The most you may purchase is %1.','Your custom message %1'
  • found this to be a much cleaner way Oct 6 '16 at 21:14

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.