我使用的是magento 1.8.1,我有一个严重的问题:手续费是按总运费的百分比计算的。相反,我需要将此费用计算为购物车小计的百分比(不包括运费)。现在,对于一辆100美元的购物车,运费为10美元,手续费为10%,费用计算为1美元(运费的10%),总计111美元。相反,我们需要手续费是购物车的10%,总共120美元。
我们怎么能做到这一点我发现算法的文件在app/code/core/mage/shipping/model/carrier/abstract.php中
线路是460-468
/**
* Calculate price considering free shipping and handling fee
*
* @param string $cost
* @param string $method
* @return float|string
*/
public function getMethodPrice($cost, $method = '')
{
return $method == $this->getConfigData($this->_freeMethod)
&& $this->getConfigFlag('free_shipping_enable')
&& $this->getConfigData('free_shipping_subtotal') <= $this->_rawRequest->getBaseSubtotalInclTax()
? '0.00'
: $this->getFinalPriceWithHandlingFee($cost);
}
/**
* Get the handling fee for the shipping + cost
*
* @param float $cost
* @return float final price for shipping method
*/
public function getFinalPriceWithHandlingFee($cost)
{
$handlingFee = $this->getConfigData('handling_fee');
$handlingType = $this->getConfigData('handling_type');
if (!$handlingType) {
$handlingType = self::HANDLING_TYPE_FIXED;
}
$handlingAction = $this->getConfigData('handling_action');
if (!$handlingAction) {
$handlingAction = self::HANDLING_ACTION_PERORDER;
}
return $handlingAction == self::HANDLING_ACTION_PERPACKAGE
? $this->_getPerpackagePrice($cost, $handlingType, $handlingFee)
: $this->_getPerorderPrice($cost, $handlingType, $handlingFee);
}
/**
* Get final price for shipping method with handling fee per package
*
* @param float $cost
* @param string $handlingType
* @param float $handlingFee
* @return float
*/
protected function _getPerpackagePrice($cost, $handlingType, $handlingFee)
{
if ($handlingType == self::HANDLING_TYPE_PERCENT) {
return ($cost + ($cost * $handlingFee/100)) * $this->_numBoxes;
}
return ($cost + $handlingFee) * $this->_numBoxes;
}
/**
* Get final price for shipping method with handling fee per order
*
* @param float $cost
* @param string $handlingType
* @param float $handlingFee
* @return float
*/
protected function _getPerorderPrice($cost, $handlingType, $handlingFee)
{
if ($handlingType == self::HANDLING_TYPE_PERCENT) {
return ($cost * $this->_numBoxes) + ($cost * $this->_numBoxes * $handlingFee / 100);
}
return ($cost * $this->_numBoxes) + $handlingFee;
}
最佳答案
将文件app/code/core/Mage/Shipping/Model/Carrier/Abstract.php
复制到app/code/local/Mage/Shipping/Model/Carrier/Abstract.php
(注意代码池-本地)
protected function _getPerorderPrice($cost, $handlingType, $handlingFee)
{
if ($handlingType == self::HANDLING_TYPE_PERCENT) {
if($cost) { //if shipping is not free
$cartTotal = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
return ($cost * $this->_numBoxes) + ($cartTotal["subtotal"]->getValue() * $handlingFee / 100);
} else { //if shipping is free
return ($cost * $this->_numBoxes) + ($cost * $this->_numBoxes * $handlingFee / 100);
}
return ($cost * $this->_numBoxes) + $handlingFee;
}