I want to modify/update the success message added by cart controller (Magento\Checkout\Controller\Cart\Add).

As described here and here, I can use preference to override controller to update success message but I think overriding core classes is bad idea.

So, is there any other better way to update success message instead of preference?

  • You could use translation files to change message. Place the changed message in language translation file under i18n directory. Jan 21, 2017 at 17:02
  • thanks for solution but it won't work in a case when I want to add some dynamic information with success message.. For example, URL of cart page..
    – Shyam
    Jan 21, 2017 at 18:19
  • In case you want to add dynamic information also you need to use plugin/preference only according to me. Jan 23, 2017 at 7:35

2 Answers 2


We can use plugin or event/observer to update the success message. In my case, I used postdispatch event.


<event name="controller_action_postdispatch_checkout_cart_add">
    <observer name="updatemessage" instance="{Vendor}\{Module}\Observer\UpdateMessage" />

In observer, Use \Magento\Framework\Message\ManagerInterface to get last added message and add new/updated success message.


namespace {Vendor}\{Module}\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;

class UpdateMessage implements ObserverInterface
    /** @var \Magento\Framework\Message\ManagerInterface */
    protected $messageManager;

    /** @var \Magento\Framework\UrlInterface */
    protected $url;

    public function __construct(
        \Magento\Framework\Message\ManagerInterface $managerInterface,
        \Magento\Framework\UrlInterface $url
    ) {
        $this->messageManager = $managerInterface;
        $this->url = $url;

    public function execute(\Magento\Framework\Event\Observer $observer) {
        $messageCollection = $this->messageManager->getMessages(true);
        $cartLink = '<a href="'. $this->url->getUrl('checkout/cart') .'">View Cart/Checkout</a>';
        $this->messageManager->addSuccess($messageCollection->getLastAddedMessage()->getText() . '  ' . $cartLink);
  • Thanks a lot.. I was searching for solution via plugin, but observer is also working fine.. Nov 16, 2017 at 5:28
  • @Shyam, is that possible to do this using plugins instead of observer ? Jun 6, 2018 at 6:10
  • @Camit1dk Yes, it is possible. You can use afterExecute() to do the same
    – Shyam
    Jun 6, 2018 at 6:59
  • Thanks Shyam , What can i used in return value while using plugin ? Jun 6, 2018 at 7:28
  • @Shyam, can you please answer magento.stackexchange.com/questions/246296/…, since you have mentioned that it is possible to do the same using plugin. Nov 6, 2018 at 5:34

You can change the Add to cart message from the following template file.


Note: Do not make any changes in core files. Override this template file in your theme and make changes there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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