1

There will be a one time charge for each product called as handling charges. So, I did below,

Reference Tutorial is: http://excellencemagentoblog.com/blog/2012/01/27/magento-add-fee-discount-order-total/

       <sales>
            <quote>
                <totals>
                    <discount>
                        <class>Namo_Packing_Model_Courier</class>
                        <after>subtotal</after>
                    </discount>
                </totals>
            </quote>
        </sales>

Inside local/Namo/Giftcarfs/Model/Courier.php

<?php

class Namo_Packing_Model_Courier extends Mage_Sales_Model_Quote_Address_Total_Abstract {

    public function collect(Mage_Sales_Model_Quote_Address $address) {
            if ($address->getData('address_type') == 'shipping')
                return $this;

                $cart = Mage::getModel('checkout/cart')->getQuote();
                $courier_fee = 0;

                    $helper = Mage::helper('catalog/product_configuration');

                    $totalCourierFee = 0;
                    foreach ($cart->getAllItems() as $item) {
                        $courierFee = $item->getCourierFee();
                        $totalCourierFee = $totalCourierFee+$courierFee;
                    }
                $address->setCourierFee($totalCourierFee);
                $address->setBaseCourierFee($totalCourierFee);


                $address->setGrandTotal($grandTotal + $address->getCourierFee());
                $address->setBaseGrandTotal($baseGrandTotal + $address->getBaseCourierFee());

            return $this;
    }

    public function fetch(Mage_Sales_Model_Quote_Address $address) {

            if ($address->getData('address_type') == 'shipping')
                return $this;

            $amt = $address->getCourierFee();

            if ($amt != 0) {


                $address->addTotal(array(
                    'code' => 'Discount',
                    'title' => 'Courier Fee',
                    'value' => $amt
                ));
            }

        return $address;
    }

}

After adding this if I apply coupon code, I am getting error message as

Coupon code "3A46-ZF1G-WE0X" is not valid.

If I comment <sales>...</sales> coupon code working fine.

Can someone help me?

0

I found the issue,

XML handler discount is the default Magento XML handler for applying coupon code. I changed <discount> into <courier_fee> Now it is working fine,

I changed below into

        <sales>
            <quote>
                <totals>
                    <discount>
                        <class>Namo_Packing_Model_Courier</class>
                        <after>subtotal</after>
                    </discount>
                </totals>
            </quote>
        </sales>

like below

        <sales>
            <quote>
                <totals>
                    <courier_fee>
                        <class>Namo_Packing_Model_Courier</class>
                        <after>subtotal</after>
                        <before>grand_total</before>
                    </courier_fee>
                </totals>
            </quote>
        </sales>

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.