Pages

Thursday, July 4, 2013

Extra Fee Shopping Cart Price Rules Magento

Under the Promotions tab in your admin panel:
It’s cool but it’s not cool enough. What I wanted to do is to set a surcharge for one payment method. I needed to add a charge in PayaPal method.
So I found the way you can set negative discounts (what means a surcharge) in the cart total price.

Note: we are going to change Magento Core files. Please make a backup of your files before continuing.

1. Go to app/code/core/Mage/Rule/Model/Rule.php

Find the line:

//check if discount amount > 0
if ((int)$this->getDiscountAmount() < 0) {
Mage::throwException(Mage::helper(‘rule’)->__(‘Invalid discount amount.));
}

Just add some bars // to comment the code:

//check if discount amount > 0
//if ((int)$this->getDiscountAmount() < 0) {
//Mage::throwException(Mage::helper(‘rule’)->__(‘Invalid discount amount.’));
//}

2. Now go to: app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Actions.php

Look for:

$fieldset->addField(‘discount_amount’, ‘text’, array(
‘name’ => ‘discount_amount’,
‘required’ => true,
class=> ‘validate-not-negative-number’,
‘label’ => Mage::helper(’salesrule’)->__(‘Discount amount’),
And again comment like this:
$fieldset->addField(‘discount_amount’, ‘text’, array(
‘name’ => ‘discount_amount’,
‘required’ => true,
// ‘class’ => ‘validate-not-negative-number’,
‘label’ => Mage::helper(’salesrule’)->__(‘Discount amount’),

3. Translate the discount word.

Go to app/locale/es_ES (I’m using the Spainish translation so maybe yours would be en_US)
Find a file called Mage_Sales.csv. Inside look for the word discount you will find something like:
"Discount (%s)","Discount (%s)"
You can change the value in order to show your own text. For example:
"Discount (%s)","Extra Fee (%s)"

Now you’re free to set negative values in the input field:



Fixed amount discount for whole cart

If you select this option the code above will not work entirely.

No comments:

Post a Comment