How to create personalized messages in purple when a user adds an item to the cart?

First I wanted to create a new attribute. Let me call it the "Price Factor." Integer values ​​can be set on the product page in the admin control panel.

On the front side, when a user adds an item to the shopping cart, a message appears in the cart and says: “Your old price was X and your new price is Y” (where X was the original price and Y is the adjusted price.)

How do I create my own message when someone adds something to their cart?

+6
source share
1 answer

This is the first thing you need to do is listen to the event that was fired when the item was added to the cart. This is called checkout_cart_add_product_complete and comes from Mage/Checkout/controllers/CartController.php .

The subscription of the event that is dispatched is:

 Mage::dispatchEvent('checkout_cart_add_product_complete', array( 'product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse() ) ); 

We can access the product that has been added to the cart through the product variable. This means that we can evaluate whether we need to show our new message or not, based on your attribute.


The next step is to add the flash message to the page. This is controlled through sessions. There are three types of messages that you can use: success, error, and notification. Adding a message is simple:

 Mage::getSingleton('core/session')->addSuccess($message); Mage::getSingleton('core/session')->addError($message); Mage::getSingleton('core/session')->addNotice($message); 
+12
source

Source: https://habr.com/ru/post/894938/


All Articles