基于订单金额的统一运费

时间:2014-03-17 14:03:30

标签: magento shipping

我想配置我们商店的送货选项,以便我们根据订单总额收取统一费率。 示例: $ 0 - $ 24 - > 10美元运费, 25美元 - 49美元 - > 5美元运费,

1 个答案:

答案 0 :(得分:0)

如果想要统一费率则使用过程

第1步:将app\code\copy\Mage\Shipping\Model\Carrier\Flatrate.php复制到

app\code\local\Mage\Shipping\Model\Carrier\Flatrate.php

Step2:修改collectRates函数

public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
    if (!$this->getConfigFlag('active')) {
        return false;
    }

    $freeBoxes = 0;
    if ($request->getAllItems()) {
        foreach ($request->getAllItems() as $item) {

            if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
                continue;
            }

            if ($item->getHasChildren() && $item->isShipSeparately()) {
                foreach ($item->getChildren() as $child) {
                    if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
                        $freeBoxes += $item->getQty() * $child->getQty();
                    }
                }
            } elseif ($item->getFreeShipping()) {
                $freeBoxes += $item->getQty();
            }
        }
    }
    $this->setFreeBoxes($freeBoxes);

    $result = Mage::getModel('shipping/rate_result');
    if ($this->getConfigData('type') == 'O') { // per order
        if(($request->getBaseSubtotalInclTax() > 24)  && ($request->getBaseSubtotalInclTax() <50) ){
            $shippingPrice=5;
        }
        elseif(($request->getBaseSubtotalInclTax() > 0)  && ($request->getBaseSubtotalInclTax() <25)){
            $shippingPrice=10;
        }else{
             $shippingPrice = $this->getConfigData('price');

        }

    } elseif ($this->getConfigData('type') == 'I') { // per item
    if(($request->getBaseSubtotalInclTax() > 24)  && ($request->getBaseSubtotalInclTax() <50) ){
            $shippingPricetmp=5;
        }
        elseif(($request->getBaseSubtotalInclTax() > 0)  && ($request->getBaseSubtotalInclTax() <25)){
            $shippingPricetmp=10;
        }else{
             $shippingPricetmp = $this->getConfigData('price');

        }


        $shippingPrice = ($request->getPackageQty() * $shippingPricetmp) - ($this->getFreeBoxes() * $shippingPricetmp);
    } else {
        $shippingPrice = false;
    }

    $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);

    if ($shippingPrice !== false) {
        $method = Mage::getModel('shipping/rate_result_method');

        $method->setCarrier('flatrate');
        $method->setCarrierTitle($this->getConfigData('title'));

        $method->setMethod('flatrate');
        $method->setMethodTitle($this->getConfigData('name'));

        if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
            $shippingPrice = '0.00';
        }


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

        $result->append($method);
    }

    return $result;
}