我使用的是 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
(注意代码池 - local)
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;
}
关于php - Magento 更改处理费算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31852170/