Friday, October 29, 2010

How to : Magento - Payment Type Surcharge Without Paying for an Extension.

Just though I would share this little tid bit for the benefit of all who have asked for this type of functionality from magento and not been prepared to pay $64 USD for an extension to do so.

Just to clarify, this is a mod, not an extension.  Also, I'm not the worlds greatest Magento user and i'm sure there is a way of making an extension to do this.  But.. for the moment, the following instructional works very well and is very easy to do.

Usage:  Once mods have been made, admin users will be able to create a shopping cart rule "discount" which is not actually a discount based on a percentage of the value of their shopping cart.  I'm not going to educate you all how to make a shopping cart rule, but basically, until now there have been a few problems with using  shopping cart rules to apply a Surcharge.

The First. You can't.  You can only enter a positive number as a percentage

The Second.  Magento in all their wisdom have an option to calculate the "discount" on shipping as well as shopping cart value, however the stupid system does not allow you to move the location of the "discount" / surcharge to after the shipping line.  This can be very confusing for customers trying to figure out how their "discount"/surcharge is calculated.

Lastly, again in all their Wisdom, Magento went and hard coded the word "Discount" in front of the name of your discount / surcharge.  So for instance if I wanted to add a surcharge using the mod below, it would read something like this :

(Discount) Credit Card Surcharge 1.5%  = $15.60

Obviously that is not the smartest way to do things which is surprising for an E-Commerce system which is supposed to be flexible. Did they need to hard code the word "Discount" especially given the fact one could easily pre pend  the word "discount" in the name of the  shopping cart rule if they wanted it displayed.

One more gripe before I proceed to the How to is the fact the only reason I wrote this is because Magento are so pathetically poor at answer extreemly simple questions such as this.  I could find absolutely no definitive solution to this issue other than to A) Pay Magento for support – which is laughable given how easy this was to resolve or B)Pay $64 for an extension.

And for the disclaimer.  This will involve very small modifications to core Magento files.  Always make backups before changing any of the files mentioned herin.  Also apparently it is illegal to apply Credit Card (or any other payment type for that matter) surcharges in some countries.  Check with your Merchant provider in your country to see if this is a problem.

Let me know if you have any questions and please provide credit if you intend on posting this elsewhere.

MAGNETO CHANGES :
To create credit card surcharge :

Change the following file :
app/code/core/Mage/rule/model/rule.php

Find :

protected function _beforeSave()
{
check if discount amount > 0
if ((int)$this->getDiscountAmount() < 0) {
Mage::throwException(Mage::helper('rule')->__('Invalid discount amount.'));
}

Change to :

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

Change the following file :
app/code/core/Mage/Adminhtml/block/promo/quote/edit/tab/actions.php

Find :

$fieldset->addField('discount_amount', 'text', array(
'name' => 'discount_amount',
'required' => true,
'class' => 'validate-not-negative-number',
'label' => Mage::helper('salesrule')->__('Discount amount'),

Change to :

$fieldset->addField('discount_amount', 'text', array(
'name' => 'discount_amount',
'required' => true,
// 'class' => 'validate-not-negative-number',
'label' => Mage::helper('salesrule')->__('Discount amount'),

Find :

app/locale/en_us/mage_sales.csv <–you may be using a different language definition file folder ie /en_au – copy changed file to both folders.

This part is important : open the file in Excel the first column is the variable name, the second is the variable value.  ONLY CHANGE THE VARIABLE VALUE!! DO NOT CHANGE THE

VARIABLE NAME.

Find the row which says "Discount" in column 1 and "Discount" in column 2.
Erase the value of Discount in Column 2 ie Column 1 should read "Discount"  (without the inverted commas) and column 2 should be empty.

The next step is optional and will depend if you want your surcharge to show AFTER shipping or before shipping.  The Magento default is to display discounts (surcharge) BEFORE shipping- regardless of whether you've opted to have your surcharge/discount applied to shipping in the admin console.  If you wish to have discount/surcharge displayed AFTER shipping, then proceed with the next step. Otherwise you're all done.

Change the following file ***THIS STEP IS OPTIONAL AND IS SUITED TO VERSIONS LOWER THAN 1.4.01  For versions Later than 1.4.01 This change can be made via the admin console Admin ->Sales – >Checkout Total Sort Order.  Change "Shipping" to "20″ and change the blank line above it to 30.

For versions prior to 1.4.01

app/code/core/Mage/Sales/etc/config.xml

Change the following :

<totals_sort>
<discount>20</discount>
<grand_total>100</grand_total>
<shipping>30</shipping>
<subtotal>10</subtotal>
<tax>40</tax>
</totals_sort>

To:

<totals_sort>
<discount>30</discount>
<grand_total>100</grand_total>
<shipping>20</shipping>
<subtotal>10</subtotal>
<tax>40</tax>
</totals_sort>

All Done.  You should now be able to set negative values in the "Shopping Cart Price Rules" from your admin console.  Make sure all rule names are descriptive so your customers know what is going on.

 

1 comment:

Senthil kumar said...

Hello milind

after completing above steps i go to admin panel "shopping cart price rule" and Adding any shopping cart rule based on payment method condition the system return the following error,
"Notice: Undefined index: model in /hsphere/local/home/www/magento.wwwlabs.com/app/code/core/Mage/Payment/Model/Config.php on line 79"
can you help me to solve this problem