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.