4

I want to add 3.5% Surcharge Fee to the Total Shopping Cart Quote for using Credit Card option. Is this possible ?

Thanks.

1

Yes, that is quite possible. If you would like to show it as a separate total you could create a new total collector for surcharge fee : see here:

If you would just like to add the 3.5% surcharge without showing it as a separate component you could hook into the event: sales_quote_save_before and sales_quote_address_save_before and write code to add 4.5% surcharge to quote and address grand total

if $quoteObject->getPayment()->getMethod() == 'cc'

4

Here are the steps I would have followed to implement the above request -:

Step 1 -

Create two fields (surcharge and base surcharge) against quote address and order

<?php
$installer = $this;
$installer->startSetup();

$installer->run("ALTER TABLE  `".$this->getTable('sales/quote_address')."` ADD `surcharge` DECIMAL( 10, 2 ) NOT NULL");
$installer->run("ALTER TABLE  `".$this->getTable('sales/quote_address')."` ADD `base_surcharge` DECIMAL( 10, 2 ) NOT NULL");

$installer->run("ALTER TABLE  `".$this->getTable('sales/order')."` ADD `surcharge` DECIMAL( 10, 2 ) NOT NULL");
$installer->run("ALTER TABLE  `".$this->getTable('sales/order')."` ADD `base_surcharge` DECIMAL( 10, 2 ) NOT NULL");


$installer->endSetup();

Step 2 - Add the following to config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <CompanyName_Surcharge>
            <version>0.0.1</version>
        </CompanyName_Surcharge>
    </modules>
    <global>
       <blocks>
          <surcharge>
             <class>CompanyName_Surcharge_Block</class>
          </surcharge>
          <sales>
            <rewrite>
                <order_totals>CompanyName_Surcharge_Block_Sales_Order_Total</order_totals>
            </rewrite>
          </sales>
       </blocks>
       <helpers>
         <surcharge>
            <class>Company_Surcharge_Helper</class>
         </surcharge>
       </helpers> 
       <models>
          <surcharge>
             <class>CompanyName_Surcharge_Model</class>
         </surcharge>
       </models>
       <sales>
          <quote>
            <totals>
                <surcharge>
                    <class>CompanyName_Surcharge_Model_Total_Quote</class>
                    <after>subtotal</after>
                    <before>tax</before>
                </surcharge>
            </totals>
         </quote>
      </sales>
      <fieldsets>
        <sales_convert_quote_address>
            <surcharge>
                <to_order>*</to_order>
            </surcharge>
            <base_surcharge>
                <to_order>*</to_order>
            </base_surcharge>
        </sales_convert_quote_address>
      </fieldsets>
   </global>
</config>

Step 3 - Create Model app\code\community\CompanyName\Surcharge\Model\Total\Quote.php

<?php

class CompanyName_Surcharge_Model_Total_Quote extends Mage_Sales_Model_Quote_Address_Total_Abstract {

    protected $_code = 'surcharge';

    /**
     * Initialize surcharge totals collector
     */
    public function __construct()
    {
        $this->setCode($this->_code);
    }

    public function collect(Mage_Sales_Model_Quote_Address $address) 
    {
        parent::collect($address);

        $this->_setAmount(0);
        $this->_setBaseAmount(0);

        $items = $this->_getAddressItems($address);
        if (!count($items)) {
            return $this;
        }

        $grandTotal= Mage::getModel('sales/quote_address')->load($address->getId())->getData('grand_total');            
        $baseSurcharge = 0;
        $surcharge = 0;

        $baseSurcharge += (($grandTotal) * (3.5 / 100));
        $surcharge += Mage::app()->getStore()->convertPrice($baseSurcharge);

        $address->setSurcharge($surcharge);
        $address->setBaseSurcharge($baseSurcharge);

        $this->_addAmount($address->getSurcharge());
        $this->_addBaseAmount($address->getBaseSurcharge());

        return $this;
    }

    public function fetch(Mage_Sales_Model_Quote_Address $address) {
        $amount = $address->getSurcharge();
        if ($amount > 0) {
            $address->addTotal(array(
                'code' => $this->getCode(),
                'title' => 'Surcharge',
                'value' => $amount
            ));
        }

        return $this;
    }
}

Step 4 - Create Block app\code\community\CompanyName\Surcharge\Block\Sales\Order\Total.php

<?php

class CompanyName_Surcharge_Block_Sales_Order_Total extends Mage_Sales_Block_Order_Totals {

    protected function _initTotals() {
        parent::_initTotals();
        $surcharge = $this->getSource()->getSurcharge();
        $baseSurcharge = $this->getSource()->getBaseSurcharge();

        if ($surcharge != 0) {
            $this->addTotal(new Varien_Object(array(
                'code' => 'surcharge',
                'value' => $surcharge,
                'base_value' => $baseSurcharge,
                'label' => Mage::helper('surcharge')->getLabel(),
                    )), 'surcharge');
        }
        return $this;
    }
}

Hope the above helps but if you are not a developer then you can use the following module which can be used to address the above issue along with more flexibility -:

http://www.scommerce-mage.co.uk/magento-surcharge-or-additional-fee.html

Cheers S

  • using above method invoice is not created for surcharge, Invoice is being created only for other than sur charge amount – Butterfly Apr 3 '16 at 11:24
2

In addition to the accepted answer, this new order total should also show up in transactional emails and other places.

This post explains this in details: http://excellencemagentoblog.com/blog/2012/01/27/magento-add-fee-discount-order-total/

There's also a really simple extension which lets you do this: http://www.magentocommerce.com/magento-connect/catalog/product/view/id/26312/super-simple-surcharge/

You can add a single surcharge for any payment method, shipping method or customer group. You can either calculate your surcharge based on a percentage value or use a flat value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.