Extra Fee Shopping Cart Price Rules Magento
Magento has a the feature to create rules in the Shopping Cart.
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:
if ((int)$this->getDiscountAmount() < 0) {
Mage::throwException(Mage::helper(‘rule’)->__(‘Invalid discount amount.’));
}
Just add some bars // to comment the code:
//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:
‘name’ => ‘discount_amount’,
‘required’ => true,
‘class’ => ‘validate-not-negative-number’,
‘label’ => Mage::helper(’salesrule’)->__(‘Discount amount’),
And again comment like this:
‘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:
You can change the value in order to show your own text. For example:
Done! 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.
Read this the comment below to learn how to fix it.
Extra
Magik, the Magento extensions company, has a nifty new extension for creating and managing Magento extra fees for a wide range of needs like rush orders, insurance, product-based service fees or even category-based additional charges. Check it out here.
Related PostsIf you liked Extra Fee Shopping Cart Price Rules Magento; the posts below might interest you too:
|




March 25, 2010
10:38
Interesting, I’ve been using magento quite a while now and I’ve been unable to make some kind of discounts. Problem with this solution is upgrades, as always.
March 25, 2010
10:40
Hey JMLeon,
Thanks for commenting.
Are you using the 1.4 version?
The discounts works great in the last version.
Regards.
March 27, 2010
20:14
Thank you for that. I used your example to create a custom setup fee for items that are imprinted with customer logos.
This becomes upgrade proof if you place these changed files under the app/local/folder so as not to overwrite the core code.
March 27, 2010
21:41
Well thanks to you. I’ll try that about the upgrade
Regards.
June 6, 2010
17:46
CJ, if you are doing imprints, can we talk? I am doing silk screen T-shirts & embroidered polos and having a tough time allowing people to meet a minimum order using different sizes, then applying a discount for total quantity.
In other words, if they order 12 small and 12 medium, how do I give them 24 quantity discount? I have shopping cart rule set up but it is not working correctly for 12 + 12, but works fine for 24. But rule says if quantity total is equal to or greater than 24…
Why wouldn’t it add 12 + 12?
Thanks,
Brad
June 6, 2010
22:32
It’s really weird Brad.
I was going to answer you “create a cart rule” but you already did
June 7, 2010
17:24
I figured it out. If I make the rule under “conditions” and the again under “actions” it works. Maybe I don’t need the rule in “conditions”? I’m a bit confused as to what the difference is.
April 7, 2010
18:49
Exactly what I have been searching for – thank you!
My customer needed a fee for cooled products. It’s ridiculous that Magento only supports the discounts. In my opinion a so called “price rule” should be possible in both ways.
Unfortunately my translation doesn’t work. I updated the app/locale… directories as in your example and the locale files of my template.
Any idea?
Thanks again.
April 7, 2010
21:11
You’re welcome
Did you cleanned (refresh?) the caché?
Regards.
April 8, 2010
00:16
Yes, I did. Several times.
There are no additional characters (I know this can cause problems – evil german language), nothing special at all. The correct german word for discount is being used, but that’s it. I checked all the csv-files in both directories, but nothing changes.
I need a beer. ^^
April 8, 2010
00:25
Maybe you’re changing something wrong. Maybe I was wrong (at least it worked for me in a Magento 1.3 version).
Are you using the 1.4 version? Could be diferent
April 8, 2010
14:07
Yes, it’s 1.4. I read some rumours, that some of the translation files could be somewhere in the database.
Anyway, I’ll run some tests now. Thanks again.
April 22, 2010
21:31
Thx. It really works to allow input the negative discount amount in actions of Shopping Cart Price Rule.
But after saved the rule, the negative discount amount works for “Fixed amount discount” but fail for the “Fixed amount discount for whole cart”.
I’ve tested both work for positive discount amount.
April 22, 2010
22:50
Hey oginome,
I think I did not test the “Fixed amount discount for whole cart” maybe this cheat will not work for that
I’ll try to look at it if I have time.
If you find any solution, please feel free to post it
Regards.
April 28, 2010
18:49
Hi quicoto!
Thanks for this guide.
I’ve the same problem of oginome.
Any ideas?
Regards.
April 28, 2010
19:17
Hi Simone,
I could not research about it but since Magento doesn’t do this by default I know don’t know if there is any solution
April 26, 2010
10:48
Hi,
currently I try to modify the way of catalog rules. I made the changes to the corresponding files for catalog rules and i was able to use negative amounts….but….e.g.
I have a product ‘A’ with a price (normal) of 30.00. When a special customergroup is logged in the price should be 35.00. So I made a rule which have -5 as discount amount. But it looks like when the price is higher than the normal then always the normal price is shown.
Is there a way to allow higher prices?
Thanks,
Neils
April 26, 2010
10:53
Hi Neils,
I’m not sure.
Maybe you should set the normal prize to 35 and add the -5 discount for all non X-Customer-Group.
Hope it helps.
Regards.
April 26, 2010
10:57
Hi Quicoto,
yes, this is the last option
But it would be much nicer when i can use the rules, cause when the “extra fee” change, i have to change all related product prices….
Regards.
April 26, 2010
10:55
Hey,
I had the same problem, I needed a fixed fee for the whole cart. I’m afraid you have to do some core-hacking here (again), because there is a nice little if, that prevents a negative discount.
app>code>core>mage>salesrule>model>validator.php
Gets interesting at the “cart_fixed” case. “if $cartRules[$rule->getId()] > 0)” etc. If you simply change it to “<" your negative discount will work (and nothing else). That's the quick'n'dirty way.
Now my new problem is, that there's no tax in this fee. And unfortunately most of my products are food with a lower tax, so I can't just put the fee in one amount with the products. If anyone has experience with the tax stuff…
Regards
April 26, 2010
11:04
Everything in tax and fees is dirty in Magento.
There is a paid solution (extension) see it here
I don’t how good it that but maybe it saves time and headaches
Regards
April 26, 2010
11:26
Thx, I found this extension too. But as far as i know, the field is voluntary?! This won’t work in my case, you shouldn’t have the choice if your salami is being sent chilled or not.
April 26, 2010
11:29
LOL
February 1, 2012
14:02
Hello Lu,
Thanx so much, your dirty solution works great, with a little change it works with positive and negative discounts. Instead of changing ‘>’ by ‘<', I asked it to check whether the value is different than some impossible value in this case, so it will always bypass the check, I know that this is even dirtier jejeje:
PD:It works for me on 1.6.1.0, hope Magento improves all these in future releases, other apps in the market all ready have this kind of features.
May 4, 2010
17:58
Hi, i’m working on an extrafee like this, because i have a category “frost food” that need an extra fee for special container that cost 15€.
What i did:
1) in Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Actions.php
i added a new option “Extra fee”:
$fieldset->addField('simple_action', 'select', array( 'label' => Mage::helper('salesrule')->__('Apply'), 'name' => 'simple_action', 'options' => array( 'by_percent' => Mage::helper('salesrule')->__('Percent of product price discount'), 'by_fixed' => Mage::helper('salesrule')->__('Fixed amount discount'), 'cart_fixed' => Mage::helper('salesrule')->__('Fixed amount discount for whole cart'), 'buy_x_get_y' => Mage::helper('salesrule')->__('Buy X get Y free (discount amount is Y)'), 'extra_fee' => Mage::helper('salesrule')->__('Extra fee'), ), ));2) in Mage/SalesRule/model/Validator.php
i dadded a new “case ‘extra_fee’”:
case 'extra_fee': $cartRules = $address->getCartFixedRules(); if (!isset($cartRules[$rule->getId()])) { $cartRules[$rule->getId()] = $rule->getDiscountAmount(); } if ($cartRules[$rule->getId()] > 0) { $quoteAmount = $quote->getStore()->convertPrice($cartRules[$rule->getId()]); $discountAmount = -$quoteAmount; $baseDiscountAmount = -$quoteAmount; //$cartRules[$rule->getId()] -= $baseDiscountAmount; $cartRules[$rule->getId()] =0; } $address->setCartFixedRules($cartRules); break;3) in Mage/Sales/Model/Quote/Address/Total/Discount.php
if($amount>0) { $title = Mage::helper('sales')->__('Discount'); } else { $title = Mage::helper('sales')->__('Extra fee'); }Please note: do not override the files, but copy them under local with the same structure!!!
This is working well, but what i want to do now is: add an extrafee every (example) 5 item in the basket. Let’s say, if you have only 5 frost food, you need only a container, if you have 10 items, 2 containers, and so on.
Another problem i have (but this is minor) is that is i have extrafee i can’t have discount or viceversa, because it do the sum and this is not clear to customers.
Any idea on how to solve?
Thank you and sorry for my english!
Nicola
May 4, 2010
18:15
Hi Nicola and thank you for you comment.
I do not understand everything in your code. About the items problem…
Maybe there is a function that give you the cart items. But seems doesn’t seem to be easy
In the other hand there is a condition “Total Item Quantuty is….” maybe you can use that condition in addition to the other one.
I’m sorry I’m not helping so much.
Regards
May 4, 2010
21:40
Yes, it is what i’m trying to do
I have a post on the magento community too, hoping someone can help.
http://www.magentocommerce.com/boards/viewthread/177428/
Thank you again.
June 7, 2010
17:37
Quicoto,
Is there a way to add a single flat fee to the whole order in the shopping cart? I’m afraid if I change the code as you suggest my hundreds of other price rules won’t work?
I have a $50 set up fee that I originally added to the configured product but I only need to charge it one time. If they order two or more products, they keep getting hit with another $50.
June 7, 2010
22:19
The code I posted should not conflict the normal rules. It just remove the imitation for negative discounts.
If you want to try it out, please make a database and files backup before proceed
June 15, 2010
08:33
Hi Quicoto,
thanks for posting this, just what ive been looking for.. thx!!.
Howabout the transactual sales email. i cant remove the – (minus) i the discount/fee line. what have you done, i´ve checked .phtml files, the emails i set up i backend etc, and ive gone blind
Also im looking for a solutions for an “extra” discount line in the cart and on sales emails, so both fee and discounts are specified in the cart, as postet by Nicola, if i find the way, ill post it, as this can be quite a problem….
thanx again!
June 15, 2010
08:37
Oh right, I did not digg into it (yet) but doesn’t look easy
And… You’re welcome!
June 15, 2010
17:07
Found it. i changed the file /app/design/frontend/blank/default/template/email/order/items.phtml.
Look for the line, formatPrice(0.00 – $_order->getDiscountAmount()), i changede it to formatPrice(0.00 + $_order->getDiscountAmount()), (Change – to + ). Works for me and my site…
BTW, this is also the file where you can changes the layout for the last “handle” in the order trans. mails.
Man, i think im close to finish:-)
Thx for leading the way….
June 15, 2010
20:00
Thank to you for the tip!
Feel free to post any questions or tips in our Forums or sending one
Regards.
June 16, 2010
08:22
NOTE… this ajustment will mess up the “total sales” on the dashboard in Mag. backend….
Still works for us as we dont use this….
just so you know…
August 31, 2010
20:53
Hi,
This is a great post thank you. I made it work in no time on the shopping cart price rule but how do I make it work on the catalogue price rule. I need a set up fee adding up to every item and not only to the final price of the shopping cart.
Thanks
August 31, 2010
21:14
Hey Welanie,
I was surfing the magento admin and I don’t see any option to set the rules for items. It is a whole “Shopping Cart” rule
September 1, 2010
01:40
Here is what I found but its not adding to the total…
http://www.magentocommerce.com/wiki/modules_reference/danish/mage_adminhtml/extensions_custom/how_to_add_setup_pricing_to_a_product
September 1, 2010
20:47
Hi Welanie
I see your problem, however i dont have a solution for this.
I hope you find your way.
September 5, 2010
16:39
So I’ve made the modifications noted in this post, but magento still tells me I cant have negative numbers in the percentage field, any idea why that may be?
TIA
September 5, 2010
21:59
Weird… If you remove the validation it should not validate
September 6, 2010
00:25
I’ve actually come across the problem of making changes and not having them be reflected in the system.
Do you know why this could be?
September 6, 2010
12:39
Do you have the Cache ON ?
September 6, 2010
13:28
No, Cache is off right now because I had not finished modifying my store.
September 6, 2010
17:31
Ok just followed steps to ensure that cache is flushed, that indexes are up to date and make sure compilation is disabled, I still get the error message.
Any ideas.
September 6, 2010
17:35
No idea, sorry :
September 7, 2010
01:14
Hello
i use Magento ver. 1.3.2.3 and i have a problem with a shopping cart price rule.
1.i make a rule name for single client with discount 10% off with some coupon code.
2.in a first step in checkout page everything is look good (the prices and the discount)
3. In the last step of checkout page (payment page) the discount is not there
4. When i’m going to admin area i see this rule name is inactive…..
Any idea?
September 7, 2010
08:18
hard to say, sorry
September 20, 2010
13:37
It does’t work for my shop (Manento 1.4.1.1).
The rule applies fine when a user is logged in (it seems that the last payment option is remembered).
For a new customer (or a customer who hasn’t logged in, there’s a error message saying the product can’t be put in the shopping cart.
Looks like the shopping cart promotion does’t work if the payment method is unknown.
September 23, 2010
08:17
Maybe the code just doesn’t work for the newest version
October 6, 2011
01:11
Hi,
This actually works fine with me using Magento version 1.6. However when I use Paypal to checkout then redirected to Paypal account page, it still shows “Discount” and it minus the subtotal (instead of adding).
Any idea how to manipulate the Paypal stuff?
Thanks.
October 6, 2011
08:23
No idea chanjay
Have you looked for an extension ?
Regards
October 19, 2011
04:20
That’s very helpful, however for my case, i need to add a shipping choice for the buyer.
There maybe a checkbox on the checkout page to allow buyer to pay for insurance or not, is that difficult?
October 19, 2011
04:33
Find a bug, when checkout and go to paypal page, the fee become discount again, e.g. -10% become the real discount of 10% , i think it needs some additional changes on the paypal module code
October 19, 2011
08:35
I think there’s an extension somewhere to add a field to the check out process.
If you find anything please post it
October 19, 2011
09:26
I found an extension from AITOC named “Extra fee” (However it needs to paid)
http://www.aitoc.com/en/magentomods_extra_fee.html
That allows to customize the fee title/description/percentage/amount and a checkbox in checkout process.
October 19, 2011
10:30
Sometimes the time you spend isn’t worth it. The extension may solve your problem fast and easy
November 14, 2011
09:25
Thanks for your method
How to set that the fee only occur one time
Result in me is every item added, the cost occur
For example, we want to charge only $1 for each purchase (for insurance purpose), but currently if customer add 2 different product, the cost become $2 (We need to keep $1 regardless how many item purchased)
Strangely the cost only occur once if the quantity for an item is more than 1, for example, if we add 2 pcs item A and 1 pcs item B, the charge becomes USD 2
Any help is very appreciated
Thank you
November 14, 2011
09:42
The result above is when setting:
Apply = Fixed amount discount
Maximum Qty Discount is Applied To = 1
Discount Qty Step (Buy X) = 0
Apply to Shipping Amount = No
Free Shipping = No
Stop Further Rules Processing = Yes
I tried to change:
apply -> Fixed amount discount to whole cart
Result = the fee is totally gone
November 14, 2011
09:49
The code I posted it doesn’t always work as expected.
Have you considered using an extension ?
November 28, 2011
10:56
Hi! The code works for me in magento 1.5.1
I use this for the extra fee in paypal payment method.
All is OK but when the store redirects to paypal, this doesn’t add the % and it discounts.
Any tip ??
Thanks in advance!
November 28, 2011
12:54
found the way to make paypal add the discount.
in app/code/core/Mage/Paypal/Model/Cart.php
search for all “TOTAL_DISCOUNT” and where there is a “-” change for a “+”.
It works for me because i don’t have any more discounts actually.
Hope it helps!
November 28, 2011
15:41
Thanks for the Top Lnk!
Perhaps you could put that in app/code/local
It will allow you to upgrade the Magento Core without losing your changes.
Regards.
November 29, 2011
03:31
The term for paypal is also discount, and after payment in your orders it’s wrong again and confused about the discount or extra fee.
So maybe pay for the extension is the best solution..
December 31, 2011
04:48
This does not work on 1.6.1, the value sent to paypal is positive so you will discount 3.4%, and you will get a notification of possible fraud on that order at magento.
April 12, 2012
12:33
Did anyone find a solution to make this work on Magento 1.6.1?
January 5, 2012
16:59
I solve this problem going to PayPal (my profile).
There’s an option “Calculation delivery”
If you set there Percent % and set for example 3%.
All your clients paid with paypal, when arrive at pay page Paypal have the EXTRA FEE of 3%.
You have to put a notice in your website to explain this charge as well.