Show custom error messages on cart page
Hi in this article i will try to tell you all about how to show custom error messages or popups on cartpage
in the below folder
app/code/core/Mage/Checkout/controllers/CartController.php
near about line 537 you will find code something like this
else {
$this->_getSession()->addError(
$this->__('Coupon code "%s" is not valid.', Mage::helper('core')->htmlEscape($couponCode))
);
}
which contains a error message for wrong coupon code apply
which i have change to
else {
$this->_getSession()->addError(
$this->__('Coupon code "%s" is not valid.', Mage::helper('core')->htmlEscape($couponCode))
);
$myValue = 'Hello World';
Mage::getSingleton('customer/session')->setMyvalue($myValue);
}
in this i have make use of magento sessions , i have set a session as setMyvalue
for the wrong code apply and than check the value of this in cart file
cart file path under
yourtheme/template/checkout/cart.phtml
i have retrieve the session value something like
getMyvalue(); ?>
do something:: you can do anything here like show your html ,js popups.....
do somethindo something:: you can do anything here like show your html ,js popups.....
thats it ......
1) Manual solution:
Create a coupon with your desired rules
Set the number of uses to 1 per customer and unlimited for general usage.
Copy the coupon code in the newsletter email
Path: app/design/frontend/{your package}/{your theme}/locale/language_ISO/template/email/newsletter_subscr_confirm.html
for exemple.
2) The dynamic one:
Create an observer on the newsletter_subscriber_save_before
or newsletter_subscriber_save_after
that checks if the customer subscribes and if so, it creates a coupon with your desired settings. See this for creating coupons by code.
Then rewrite the method Mage_Newsletter_Model_Subscriber::sendConfirmationSuccessEmail
so you can pass that code as a parameter to the e-mail template.
Something like this:
$email->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE),
Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY),
$this->getEmail(),
$this->getName(),
array('subscriber'=>$this, 'coupon_code'=>THE COUPON GENERATED IN THE EVENT)
);
Then modify the newsletter subscription e-mail template to include this:
Your coupon code is: {{var coupon_code}}
Reference.
Best Answer
So after the some action the customer gets the email with the code.
I assume in the code it's a controller action.
What you need is to add a view for this action (block and template) and in the template show generated coupon code. And the coupon generation function you already have in the module.