2

Is it possible to filter the shipping method(s) available based on the item (or the attribute of an item) in the shopping cart. To date we have had one type of product that always requires LTL shipping. Of course this has been simple to accommodate, we just offer the LTL method.

Now we are adding product that can be shipped via a ground carrier (e.g, FedEx or UPS) and would like to offer that method but only when the LTL items are not in the cart.

Is it possible to implement this without custom code?

Running Community 1.6.1.0

  • LTL is "less than truckload", correct? – philwinkle Jul 31 '13 at 21:06
  • Yes, LTL = "Less than Truckload" – badgerdigital Aug 1 '13 at 20:10
4

Unfortunately Magento does not dispatch an event when the shipping rates are collected (I think it really should) so you will have to override something.
All the carriers are collected and validated in this method: Mage_Shipping_Model_Shipping::collectCarrierRates() where you have access to the items in the cart by calling $request->getAllItems(). You can either override this method and if you find a product that requires LTL just ignore other carriers.
Also, each carrier has a method called proccessAdditionalValidation called in the same methods as described above. You can override this method for all the carriers and again check if there is a product in the cart that requires LTL.
Honestly I would take the first approach. It seams less code.
Your code can be something like this:

foreach ($request->getAllItems as $item){
    if ($item->getProduct()->getRequireLtl()){ //chagen getRequireLtl with your attribute code
        if ($carrierCode != 'ltl'){//change ltl with the correct code
            return false;
        }
    }
}

This is written of the top of my head so it might not function as required, but you get the idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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