First I wanted to create a new attribute. Let's call it "Price Factor." Integer values can be set from the product page on the admin control panel.
On the front end, whenever a user adds an item to the shopping cart, a message pops up in the shopping bag 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 would I go about create a custom message when someone adds something to their shopping cart?
This first thing you need to do is listen to the event that's fired when an item is added to the cart. This is called checkout_cart_add_product_complete
and originates from Mage/Checkout/controllers/CartController.php
.
The signature of the event that is dispatches 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. That means we can assess whether we need to show our new message or not, based on your attribute.
The next step is to add a flash message to the page. This is controlled through sessions. There are three types of messages that can be used: success, error and notice. Adding a message is simple:
Mage::getSingleton('core/session')->addSuccess($message);
Mage::getSingleton('core/session')->addError($message);
Mage::getSingleton('core/session')->addNotice($message);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With