I custom add to cart module on Magento 2 and keep message like Magento core.
if (!$this->_checkoutSession->getNoCartRedirect(true)) {
if (!$this->cart->getQuote()->getHasError()) {
$message = __('You added %1 to your shopping cart.', $product->getName());
$this->messageManager->addSuccessMessage($message);
}
return $this->goBack(null, $product);
}
After add to cart success, it return message "Product name add to cart success". But when I access to another page, that message still display.
Ex: I clicked add to cart, when it was loading, I quickly clicked to cart(checkout/cart). Success message was display at there. How can I remove that message, I just want it display one time at product(where click add to cart) page. I use Magento 2.0.7