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:

Just add some bars // to comment the code:

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

Look for:

And again comment like this:

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 comment below to learn how to fix it.

112 comments
  • 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.

  • Hey JMLeon,

    Thanks for commenting.

    Are you using the 1.4 version?

    The discounts works great in the last version.

    Regards.

  • 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.

    • Well thanks to you. I’ll try that about the upgrade 😉

      Regards.

    • 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

    • It’s really weird Brad.

      I was going to answer you “create a cart rule” but you already did 😕

      • 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.

  • 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.

    • You’re welcome 😉

      Did you cleanned (refresh?) the caché?

      Regards.

      • 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. ^^

      • 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 😕

      • 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.

  • 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.

    • 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.

  • 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

    • 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.

      • 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.

  • 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 😉

    • 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

    • 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:

      [code]if ($cartRules[$rule->getId()] != 'x')[/code]

      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.

  • 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”:
    [code]
    $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’),
    ),
    ));[/code]

    2) in Mage/SalesRule/model/Validator.php

    i dadded a new “case ‘extra_fee'”:

    [code]
    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;
    [/code]

    3) in Mage/Sales/Model/Quote/Address/Total/Discount.php

    [code]
    if($amount>0)
    {
    $title = Mage::helper(‘sales’)->__(‘Discount’);
    }
    else
    {
    $title = Mage::helper(‘sales’)->__(‘Extra fee’);
    }
    [/code]

    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

    • 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

  • 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.

  • 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.

    • 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 😉

  • 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!

    • Oh right, I did not digg into it (yet) but doesn’t look easy 😕

      And… You’re welcome!

      • 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….

      • Thank to you for the tip!

        Feel free to post any questions or tips in our Forums or sending one 😉

        Regards.

      • 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…

  • 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

  • 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

  • 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?

  • 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.

  • 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.

  • 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?

  • 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

    • 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 🙁

    • The code I posted it doesn’t always work as expected.

      Have you considered using an extension ?

  • 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!

    • 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!

    • 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.

    • 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..

  • 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.

  • 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.

  • Hello,
    Someone have a solution to have a shopping cart surcharge negative rule on magento 1.7.0.0 ?
    Thank you

  • Great Tip!

    Normally magento shopping cart price rules calculate on Subtotal.
    when using the “Percent of Product Price discount” method.
    i want to calculate it on (Subtotal+Shipping & Handling Charges)
    how can i solve my problem…

    Thank you!

  • This is awesome. Works with EE. Thanks.

  • In 1.7 no condition found in Rule.php, any idea for 1.7

  • 🙂 got it : magento 1.7 : go to /app/code/core/Mage/Rule/Model/Abstract.php and edit line No. 94 to 96….

  • But paypal shows as discount :(… useless trick..

  • and also paypal not plus the amount, show discount and negative value…

  • cant use this trick into paypal payment method

  • HI there,

    Mine is still showing “Discount (Surcharge) : ” How do i completely remove the discount at the front?

  • I did. I changed it on the 2nd column. The word discount is still appearing during checkout 🙁 I’m using 1.7.0.2

  • ok, this is weird…i solved it, but i had to change the ‘locale’ to english (united states). I’m using english (united kingdom) how do i fix this with united kingdom? i created en_UK and copied the mage_sales.csv files to that folder but still it’s not showing the ammended text. It’s showing discount. When i change it to united states it will show ‘surcharge’ which is the text i ammended.

    • That’s a though one Budi.

      I don’t know if it’s suposed to be a en_UK file in there.

      it’s been a while since I played with this things, I’d have to digg about it.

      If you happen to find an answer to your problem, please post the solution!

      Cheers.

  • if i’m using english (united kingdom) would u know where it will load the mage_sales.csv from?

  • I got this code to work in 1.7.0.2, but there is an issue when using it.

    The amount applied (in this case a negative number, which of course is really a increase in the costs) does not work because the taxes calculated in Magento ignore this increase in price.

    Real example from my store:

    item – $279.87
    Extra Fees $27.00 (from this code)
    Shipping – $26.95
    Total – $333.82

    Tax – (10% here) = $27.99 which is incorrect.
    Reason, we don’t have tax on shipping.
    The tax should be $279.87 + $27.00 + 10% = $30.69

    This code however only allows Magento to calculate tax on the item price $279.87 + 10% = $27.99

    Unfortunately this makes the code in Magento useless unless of course you do not charge tax.

    • After further research, I can say the code is working correctly even though I stated it did not.

      Explanation:

      The discount applied in magento is treated as a non-taxable item.

      279.87+27+26.95=333.82
      333.82-(ship$26.95)=306.87-(extra fees$27.00) = 279.87
      279.87+10%(tax)= $27.99
      27.99+279.87+27+26.95=361.81 which is correct

      Everything is working correctly

    • Thank you for posting it ! 😉

      Cheers.

  • Rick,

    When you put these files in app/local instead of the original magento directories, do you have the create the exact file directory structure in app/local?

    I tried it and it stopped working, I tried putting the changed files in app/local with the exact structure and that doesn’t work either?

  • Well ok nvm.. I was putting them in locale instead of local…lol

  • This doesn’t work when I put the modified files in app/local/. I’ve tried creating the exact directory structure also, and just putting the changed files there and neither seem to work

  • I’m using Special promotions pro extension from amasty to set up price rules of different types easily. It a great time saver. Highly recommend http://amasty.com/special-promotions-pro.html

  • Rick,

    I just noticed that while this code works great, it shows as example (-$3.25) on the invoice emails etc..

    It is confusing to customers seeing -$3.25 when in fact it is an addition instead.
    Any way to make it no show the “-“?

  • Rick,

    I read that yesterday but in version 1.7.0.2 I cannot find the file where it has that code?

    This version doesn’t have a /app/design/frontend/blank/default/template/email/order/items.phtml

    It has a /app/design/frontend/base/default/template/email/order/items.phtml and the code is not in their either

    • Hi,

      The path /app/design/frontend/whatever depends on the theme you’re using.

      If you’re using the default it can be something like: /app/design/frontend/base/default

      You should look for getDiscountAmount in your entire theme and then try to change the code make it look similar to:

  • I have looked in every file named items.phtml and that code is not in any of them.

    The original post was made using an old version of magento and a lot of the filenames and codes changed in later versions.

  • There is a lot more code that needs to be modified for this feature to work and display properly. I am not a coder by nature so I wouldn’t know where to start to fix all of these in 1.7.0.2. Here are the items that do not display properly.

    1. Sales Order in Admin – Items ordered will show the discount amount as -$.$$ (should not show as “-” when in fact it is an addition). It of course is reading directly from your shopping cart price rules where we put the “-” discount amount for calculations.

    a. Sales Order Totals show the discount as (whatever you changed the name to in original code), mine is set to Extra Fees. This totals block show correctly Extra Fees $.$$

    2. Sales Invoice in Admin – items invoiced show discount as -$.$$

    a. Sales Invoices – invoice totals show wrong again as Extra Fees -$.$$ (should not show a “-” here)

    It would also be safe to say that any of the transactional emails will also be wrong since they just read from Magento code.

    Customers paying attention to this would think you are trying to do something wrong since things say “discount” but are added to the costs and things show as “-discount” but really aren’t.

    Hopefully someone who codes will read this and help fix it..

  • Nice tips. I wonder can we create rules depends on group of customers? Custom price for selected groups like frequent buyers or contractors.

  • Another approach is to use event observer method which doesn’t not modify or extend any core code.
    The event you need to implement is: sales_quote_collect_totals_before
    And the observer model method looks like:

    REF: http://www.blog.magepsycho.com/change-shipping-price-handling-fee-fly-magento/

  • Am using magento 1.8.1 and am new to magento. While I am going to give condition for new rule for shopping cart price rule, if I click (+) icon that page automatically redirect into dashboard. Anyone knows how to fix this problem?

  • Hi guys.
    I need to use negative value for discount field. Hence I found this blog. I am using magento 1.8.1.0 version. My problem is that I couldn’t find

    in app/code/core/Mage/Rule/Model/Rule.php.

    What should I do?

    • It’s been a while since I did this.

      Have you tried looking into the hole /app/code/core/Mage/Rule folder?

      • If yo read the code at the begining of /app/code/core/Mage/Rule/Rule.php you can read:

        The line you are looking for is in:
        /app/code/core/Mage/Rule/Abstract.php

        But anyway, i can’t do it works in 1.9…..

    • Magento 1.8 in app/code/core/Mage/Rule/Model/Abstract.php. line 107

  • Do not work on 1.6.1, anyone has a solution?

  • Hello,
    I wnat to apply negative discount value for fixed discount amount for whole cart how can I dot it

  • Any ideas on how to do this in Magento 2?

  • I didn’t find the code in Magento 1.9.3.2
    app/code/core/Mage/Rule/Model/Rule.php

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*