1

I have a requirement where I have to calculate shipping rates based on many conditions, below will impact the rates:

  • Summer or Winter
  • Different Containers (4 containers)
  • Different types of products (6 types)
  • Combinations of products in cart (qty based)

So let's see an example, If below products have been added to cart,

(2 qty) Product Type 1 - Container 1 - Type 1 - Summer
(1 qty) Product Type 2 - Container 2 - Type 1 - Summer

then rates will come based on that combination.

It's hard to explain, but I want to know how to startoff with such type of product-based shipping calculations.

Thanks

3

First you need to create a new shipping method. This should help you do that..
Then all you need to do is to calculate the cost in the method collectRates of your new module. You have access to the products in the cart in that method using $request->getAllItems().

$price = 0;
foreach ($request->getAllItems() as $item){
    $product = $item->getProduct();
    //do something with $item or $product
    //$price += 30;//add an amount to the total price
}

After calculating the total price just replace the line in the example:

$method->setPrice($rMethod['amount']+$handling);

with

$method->setPrice($price);

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.