magento charge shipping as percentage of subtotal

僤鯓⒐⒋嵵緔 提交于 2019-12-05 09:38:53

问题



Wanted to calculate a shipping cost on basis of percentage which is also manageable from admin.
For E.g :- Shipping cost [ADMIN] : 10
If subtotal = 100.
Then Shipping cost = 10.
Thanks in advance.


回答1:


Alas got the answer.
File copy from app/code/core/Mage/Shipping/Model/Carrier/Flatrate.php to --> local/Mage/Shipping/Model/Carrier/Flatrate.php
About line 96 edit accordingly:

if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
                $shippingPrice = '0.00';
            }
                    //code starts here
            if ($this->getConfigData('shipper_type') == 'P')
            {
            $session        = Mage::getSingleton('checkout/session');
            $quote_id       = $session->getQuoteId();

            $item_quote     = Mage::getModel('sales/quote')->load($quote_id);

            $shippingPrice  = $item_quote->getSubtotal()*($this->getConfigData('price')/100);
            //code ends here
            }


            $method->setPrice($shippingPrice);
            $method->setCost($shippingPrice);


In app/code/core/Mage/Shipping/etc/system.xml. [About line : 181]

                <shipper_type translate="label">
                        <label>Calculate Shipping Fee</label>
                        <frontend_type>select</frontend_type>
                        <source_model>shipping/source_shipperType</source_model>
                        <sort_order>4</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>0</show_in_store>
                </shipper_type>

Create In app/code/core/mage/Shipping/Model/Source/ShipperType.php

class Mage_Shipping_Model_Source_ShipperType
{
    public function toOptionArray()
    {
        return array(
            array('value' => Mage_Shipping_Model_Carrier_Abstract::HANDLING_TYPE_FIXED, 'label' => Mage::helper('shipping')->__('Fixed')),
            array('value' => Mage_Shipping_Model_Carrier_Abstract::HANDLING_TYPE_PERCENT, 'label' => Mage::helper('shipping')->__('Percent')),
        );
    }
}

I hope this helps someone.



来源:https://stackoverflow.com/questions/14933462/magento-charge-shipping-as-percentage-of-subtotal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!