Фиксирана ставка за доставка въз основа на сумата на поръчката

Бих искал да конфигурирам опцията за доставка на нашия магазин, така че да таксуваме фиксирана ставка въз основа на общата сума на поръчката. Пример : $0 - $24 -> $10 доставка, $25 - $49 -> $5 доставка,


person Sunil George    schedule 17.03.2014    source източник
comment
Защо не използвате таблични ставки вместо плоски ставки?   -  person Gerard de Visser    schedule 17.03.2014


Отговори (1)


ако искате фиксирана ставка, тогава използваният процес

Стъпка 1: копирайте app\code\copy\Mage\Shipping\Model\Carrier\Flatrate.php в

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

Стъпка 2: променете функцията 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;
}
person Amit Bera    schedule 17.03.2014