Flat Rate Shipping Based on Order Amount

放肆的年华 提交于 2019-12-13 18:41:22

问题


I would like to configure our store's shipping option so that we charge a flat rate based on the order total. Example : $0 - $24 -> $10 shipping, $25 - $49 -> $5 shipping,


回答1:


if want to flat rate then used proccess

Step1:copy app\code\copy\Mage\Shipping\Model\Carrier\Flatrate.php to

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

Step2: modify collectRates function

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;
}


来源:https://stackoverflow.com/questions/22456401/flat-rate-shipping-based-on-order-amount

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