Skip to main content
Formatting
Source Link
Inizio
  • 3.5k
  • 13
  • 19

How to alter the message shown ("xyz"- "xyz" added to your cart), when we add an item to cart in Drupal 8 commerceCommerce 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.

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\EventSubscriber where the function displayAddToCartMessage(CartEntityAddEvent $event) is written which is responsible for showing the message, is there any method to override it.

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\EventSubscriber where the function displayAddToCartMessage(CartEntityAddEvent $event) is written which is responsible for showing the message, is there any method to override it.

Rollback to Revision 1
Source Link
Clive
  • 167.9k
  • 19
  • 303
  • 337

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!

I Found a solution but i think there has to be a better method than this. I wrote a custom submit handler on Add to Cart Submit => $form['actions']['submit']['#submit'][] = 'example';

and then in

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']); 

    // 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.
  
}

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\EventSubscriber where the function displayAddToCartMessage(CartEntityAddEvent $event) is written which is responsible for showing the message, is there any method to override it?

FINALLY!

I Found a solution but i think there has to be a better method than this. I wrote a custom submit handler on Add to Cart Submit => $form['actions']['submit']['#submit'][] = 'example';

and then in

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']); 

    // 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.
  
}

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\EventSubscriber where the function displayAddToCartMessage(CartEntityAddEvent $event) is written which is responsible for showing the message, is there any method to override it.

added 50 characters in body
Source Link
leymannx
  • 18.8k
  • 6
  • 72
  • 126

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.

}

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\EventSubscriber where the function displayAddToCartMessage(CartEntityAddEvent $event) is written which is responsible for showing the message, is there any method to override it.

                 FINALLY!

I Found a solution but i think there has to be a better method than this.I wrote a custom submit handler on Add to Cart Submit => $form['actions']['submit']['#submit'][] = 'example';

and then in

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']);

// Path To Cart.    

$link = \Drupal\Core\Url::fromRoute('commerce_cart.page')->toString();

// Your custom message. 

drupal_set_message(t($get_cart_title.' added to your cart', array('@link' => $link)));

// $get_cart_title is some variable as per requirement.

}

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\EventSubscriber where the function displayAddToCartMessage(CartEntityAddEvent $event) is written which is responsible for showing the message, is there any method to override it?

FINALLY!

I Found a solution but i think there has to be a better method than this. I wrote a custom submit handler on Add to Cart Submit => $form['actions']['submit']['#submit'][] = 'example';

and then in

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']); 

    // 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.
  
}
added 53 characters in body
Source Link
Loading
added 694 characters in body
Source Link
Loading
Source Link
Loading