2

I have two types of product in my store - one is wines and another is food/ grocery.

The shipping cost for wine is based table rates, while food/ grocery is based on a flat rate.

So when you order a food from my store, I don't want to show you the table rates.

And when you order a wine, I don't want to show you the flat rate as it is always at a lower rate.

But when you order a wine and a food, then you get the table rates.

So, how can I customize the Magento system to do this? Can this be configured in Magento?

When I create a new product, I choose Simple Product as Product Type for Wines. What about food then?

1 Answer 1

1

From what I understand your problem reduces to "If there is a wine type product in the cart, don't show the flat rate and when you order only food type products don't show table rate."
Each shipping method model has a method called proccessAdditionalValidation. You need to rewrite the models Mage_Shipping_Model_Carrier_Flatrate and Mage_Shipping_Model_Carrier_Tablerate and implement this method. The method receives as parameter an object of type Mage_Shipping_Model_Rate_Request from which you can access all products.

so your method can look something like this:

public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request)
{
    //get all cart items
    $items = $request->getAllItems();
    //loop through the items and check their type
    foreach ($items as $item) {
        $product = $item->getProduct();
        //on the table rate model use this
        if ($product is of type wine) { //replace this with your code that checks if product is of type wine
            //so if there is at least one wine product then show the method
            return $this;
        }
        //on the flat rate model use this
        if ($product is of type wine) { //replace this with your code that checks if product is of type wine
            //so if there is at least one wine product then don't show the method
            return false;
        }

    }

}

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.