Question

I am learning Magento and trying to create a shipping method that appears only when the subtotal of the cart is over than $100.

I tried to getSubTotal() in function collectRates(), then return false if the return value smaller than 100. However, it always returns 0. I guess it had not been calculated at that step, is that true?

And is there any other way I can do what I wanted?

Please help... Thank you a lot!

Was it helpful?

Solution

your collectRates method should look like this

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

    if ($request->getPackageValue() < 100) {
        return false;
    }
    /** @var Mage_Shipping_Model_Rate_Result $result */
    $result = Mage::getModel('shipping/rate_result');
    $method = Mage::getModel('shipping/rate_result_method');
    $method->setCarrier($this->_code); //add here the payment method code
    $method->setCarrierTitle($this->getConfigData('title')); //or you can add any title if it's not configurable
    $method->setPrice(your shiping cost here);
    $result->append($method);
    return $result;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top