I would like to override the cart controller in Magento 1.9.2 in order to change the wording of the coupon session messages. There are lots of tutorials and answers which I have gone through, but my override does not seem to be working, I’m not sure if the location of my files are correct.
New Module: app/etc/modules/My_Module.xml
<?xml version="1.0"?>
<config>
<modules>
<My_Module>
<active>true</active>
<codePool>local</codePool>
</My_Module>
</modules>
</config>
Config file: app/code/local/My/Module/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<My_Module>
<version>0.1.0</version>
</My_Module>
</modules>
<frontend>
<routers>
<checkout>
<args>
<modules>
<My_Module before="Mage_Checkout”>My_Module</My_Module>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>
New controller app/code/local/My/Module/controllers/CartController.php
<?php
require_once 'Mage/Checkout/controllers/CartController.php';
class My_Module_CartController extends Mage_Checkout_CartController
{
/**
* Initialize coupon
*/
public function couponPostAction()
{
/**
* No reason continue with empty shopping cart
*/
if (!$this->_getCart()->getQuote()->getItemsCount()) {
$this->_goBack();
return;
}
$couponCode = (string) $this->getRequest()->getParam('coupon_code');
if ($this->getRequest()->getParam('remove') == 1) {
$couponCode = '';
}
$oldCouponCode = $this->_getQuote()->getCouponCode();
if (!strlen($couponCode) && !strlen($oldCouponCode)) {
$this->_goBack();
return;
}
try {
$codeLength = strlen($couponCode);
$isCodeLengthValid = $codeLength && $codeLength <= Mage_Checkout_Helper_Cart::COUPON_CODE_MAX_LENGTH;
$this->_getQuote()->getShippingAddress()->setCollectShippingRates(true);
$this->_getQuote()->setCouponCode($isCodeLengthValid ? $couponCode : '')
->collectTotals()
->save();
if ($codeLength) {
if ($isCodeLengthValid && $couponCode == $this->_getQuote()->getCouponCode()) {
$this->_getSession()->addSuccess(
$this->__('Promo code "%s" was applied.', Mage::helper('core')->escapeHtml($couponCode))
);
} else {
$this->_getSession()->addError(
$this->__('Promo code "%s" is not valid.', Mage::helper('core')->escapeHtml($couponCode))
);
}
} else {
$this->_getSession()->addSuccess($this->__('Promo code was cancelled.'));
}
} catch (Mage_Core_Exception $e) {
$this->_getSession()->addError($e->getMessage());
} catch (Exception $e) {
$this->_getSession()->addError($this->__('Cannot apply the promo code.'));
Mage::logException($e);
}
$this->_goBack();
}
}
The only thing I have changed in the controller is the word ‘coupon’ to ‘promo’ I do not have any error messages.
Thanks