How to alter the message shown ("xyz" added to your cart) when we add an item to cart in Drupal 8 commerce 2x.
I saw Drupal\commerce_cart\EventSubscriberDrupal\commerce_cart\EventSubscriber
where the function displayAddToCartMessage(CartEntityAddEvent $event)displayAddToCartMessage(CartEntityAddEvent $event)
is written which is responsible for showing the message, is there any method to override it.?
FINALLY!
FINALLY!
I Found a solution but i think there has to be a better method than this.I I wrote a custom submit handler on Add to Cart Submit => $form['actions']['submit']['#submit'][] = 'example';$form['actions']['submit']['#submit'][] = 'example';
and then in
function example(array $form, FormStateInterface $form_state) {
function example(array $form, FormStateInterface $form_state) {
// TO Unset The message which is shown add an item is added to cart.
unset($_SESSION['_symfony_flashes']['status']);
unset($_SESSION['_symfony_flashes']['status']);
// Path To Cart.
$link = \Drupal\Core\Url::fromRoute('commerce_cart.page')->toString();
// Your custom message.
drupal_set_message(t($get_cart_title.' <a href="@link">added to your cart</a>', array('@link' => $link)));
// $get_cart_title is some variable as per requirement.
}
drupal_set_message(t($get_cart_title.' added to your cart', array('@link' => $link)));
// $get_cart_title is some variable as per requirement.
}