开发者

How to toggle Shipping Methods Based on Products?

I want to be able to toggle what shipping method is used based upon the items that are in the cart. Where is the best place to 开发者_开发技巧"check" this and grab the right shipping method?

The way it will work is that there will be a standard shipping method that is used, and then, if there are certain items in the cart another method will override that other method.

I think I could do this by hacking around in the individual shipping modules, but I'd like to do this the "right" way.


shipping methods have built in method in Mage_Shipping_Model_Carrier_Abstract that they all extend:

 public function isActive();

extend your shipping methods and add your logic to that method and don't forget to call parent::isActive(); first


Try and Try as I did to implement a custom override, I was only able to find success when I copied the entire Tablerates.php file to local/Mage/Shipping/Model/Carrier/Tablerates.php

isActive() was still not "the way" at that point. I had to introduce some code in the collectRates() function like so:

       // check the store 
        if (Mage::app()->getStore()->getId() == 2){

            // check for free shipping
            $packageValue = $request->getPackageValueWithDiscount();
            $freeShipping = ($request->getFreeShipping()) || ($packageValue >=  Mage::getStoreConfig("carriers/freeshipping/free_shipping_subtotal", $this->getStore()));
            if($freeShipping)
                return false;

            $foundFlag = false;
            foreach ($request->getAllItems() as $item) {
                $org_product = Mage::getModel('catalog/product')->load($item->getProductId());
                if($org_product->getDeliveryFlag() == "workstationmats")
                {
                    $foundFlag = true;
                }   
            }

            if ($foundFlag == false)
                return false;
        }
        // end shpping mod

This was placed right at the beginning of the collectRates function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜