0

I wish to modify the shipping cost Double if they add more than 5 items at the cart.

class ChangeShipping_MyCarrier_Model_Carrier extends
    Mage_Shipping_Model_Carrier_Abstract implements
    Mage_Shipping_Model_Carrier_Interface
{
    protected function _getStandardShippingRate()
    {
        $rate = Mage::getModel('shipping/rate_result_method');
        $rate->setCarrier($this->_code);
        $rate->setCarrierTitle($this->getConfigData('title'));
        $rate->setMethod('standand');
        $rate->setMethodTitle('Standard');

        $items_count = Mage::helper('checkout/cart')->getItemsCount();
        if ($items_count > 6) {
            $rate->setPrice(19.99);
        } else {
            $rate->setPrice(9.99);
        }
        $rate->setCost(0);
        return $rate;
    }
}

This function executes flawless without IF condition but shows error then.

2
  • What is the error that you're getting? Commented Jan 15, 2016 at 13:24
  • I suggest you add a Mage::log($items_count) you might find that the count isnt actually what you are thinking. Ie if you add a configurable product, is it giving you 1 or 2? (simple+configurable). Moreover, do you want qty to be factored in? See this question: magento.stackexchange.com/questions/23491/… Commented Jan 15, 2016 at 14:03

1 Answer 1

2

In the carrier model please use $request object, and not the $cart object, as we can create the order from admin, API and other sources. See example here:

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

You need is to modify the collectRates based on you logic:

...
if ($request->getPackageQty() > 6) { // modify price }
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.