Is there a way to calculate weight based shipping using commerce? How can we calculate shipping cost using product weights? If there is no way to calculate shipping using weight quotas this module is usless... or am I missing something.
I was looking for documentation from 3 days now, I even tried to make my own module but nothing.
Please give me a point to start from.

Comments

rszrama’s picture

Status: Active » Fixed

This strikes me as a bit melodramatic. No?

"If there is no way to calculate shipping using weight quotas this module is usless... [sic]"

I tend to think Commerce is still quite useful even if it never supports weight based shipping. Plenty of e-commerce sites don't require shipping.

However, you're in luck, despite your personal-use-case-centered pessimism! You can start by looking into the Commerce Shipping module, which is where it all happens. There is an example shipping method in there, but I'd strongly recommend you pursue Commerce Shipping 2.x. Shipping rates can be calculated using Rules, which in turn can access field data on your product types to calculate rates based on weight value.

So, Shipping 2.x, the Physical Fields module, Commerce Physical, and a custom shipping method module will serve you for now. Soon you'll be able to just based it on a single flat rate module and not have to write any code at all.

You might also check out the About page of my Pineapple Store: http://live.druplus.gotpantheon.com/about

SilviuChingaru’s picture

I was misunderstood... I like a lot approach of commerce module compared to ubercart module. I'm running an Ubercart stored for a year now and I'm very pleased with it but is so little support for drupal powered features.

I'm trying to migrate my ubercart store to commerce but lack of documentation made it harder for me to accomplish this task.

So, Shipping 2.x, the Physical Fields module, Commerce Physical, and a custom shipping method module will serve you for now. Soon you'll be able to just based it on a single flat rate module and not have to write any code at all.

can u explain a little pls?

I made a custom field on my products content type with physical dim but they are not accessible by rules so I can't calculate my shipping price based on total weight of order. Maybe I misunderstood something... If you'll be kind to get me closer on how to do this I'll be very grateful.

If I'll accomplish this I'll write an howto for other users to accomplish weight quotas on drupal documentation.

rszrama’s picture

You used a custom field or the dimensions field supplied by the Physical Fields module? And did you put the field on a content type or a product type? I'd put it on the product type.

To access field data via Rules, you also have to make sure the field exists on the entity you're evaluating. See http://www.drupalcommerce.org/faq/rules-field-data-selection for more info on that.

And just so I'm clear - would you classify yourself as a developer or more as a site builder?

SilviuChingaru’s picture

This is what I accomplish by now:
I created a physical dimensions field for product type field_weight, i added this field also to line items, so now when i place an order line item has also the weight value of product for one piece.

In rules i can access this field_weight from commerce-order:commerce-line-items:0:field-weight:weight if i add a data comparison:

commerce-order:commerce-line-items:0:type equals product

What I don't know is how to make this field available for every line item, because if I write a condition for every line item how I know the number of all line-items from an order? I don't want to limit orders to a number of line items.

Anyway if i put manualy conditions for 10 line-items how i get total weight of order.

I tried to make a loop for every line-item, then calculte a value qty or field weight for each line but how i sum the results? How can i store them to a global var not just a var inside the loop because the shipping will be calculated for total weight of the order.

I am a developer but this is my first D7 project. My previous work was on D6. Also I m trying to upgrade my old D6 Drupal site to commerce.

Thank you very much for your answer, time and for giving me a start point. ;-)

SilviuChingaru’s picture

Status: Fixed » Active
rszrama’s picture

Status: Active » Fixed

The Commerce Physical module has API functions to calculate the total weight of an order without relying on duplicating weight data from the product to the line item. Can you not use these instead? It strikes me that perhaps what you need would be equivalent Rules conditions based on those API functions (and maybe order tokens as well so the values like total weight can be selected with data selectors). If this would help you, please open an issue in the Commerce Physical queue.

SilviuChingaru’s picture

Status: Fixed » Active

The Commerce Physical module has API functions to calculate the total weight of an order without relying on duplicating weight data from the product to the line item.

Thank you very much for the tip, indeed it solved my problem and I was able to finish my task and have a weight based shipping module. I'll share it to the community after I'll test it and polish it for a while.

Please help me with one more thing, if you like, don't you know what function API preferred to call to check for order total price and for fine items total? I think they should be in this module "commerce" but I didn't find them or...

THIS MODULE (COMMERCE) ROCKS. IS THE BEST COMMERCE SOLUTION FOR DRUPAL and if I'll be able to implement it to my site I'll be the happiest devel ;-)

rszrama’s picture

Status: Active » Fixed

heh, glad to see you've come around. ; )

As for checking the total price of an order, you can just inspect the order total field on the order entity. For example:

// Load and wrap an order.
$order = commerce_order_load($order_id);
$wrapper = entity_metadata_wrapper('commerce_order', $order);

// Retrieve its total amount and currency code.
$total_amount = $wrapper->commerce_order_total->amount->value();
$total_currency = $wrapper->commerce_order_total->currency_code->value();

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dcharles’s picture

4 days trying to figure this one out and I give up and would really appreciate your help if you've got the time?

I have everything set up so that I can set weights and dimensions to products...but I haven't managed to find a way to use these values to set a shipping base rate in the checkout phase.

I've tried doing it through Rules. I can get each product's weight and dimension field value, but I don't know how to get this as a value based on the total order. Your previous comment suggests that I should be able to get the total order weight value from the physical module API? Is this something that is available to Rules or is that something that requires a loop through the order items?

I then tried creating a module and can get the order weight and product dimensions for use just fine BUT I don't know how then to set the shipping rate based on the chosen service! Is there a way I can just add a rate or a value to an existing service or shipping charge? The simpler the better for me right now. If I can just add a one liner to add a rate that would be fine.

And finally, I tried the newest Flat Rate module you posted but I still have the Rules problem.

Any help would be great and if you have an example that'd save me staring blindly at the screen for another four days! ;-)

rszrama’s picture

Yes, in your case you could just use http://drupal.org/project/commerce_flat_rate in conjunction with Shipping 2.x to add a new flat rate with your base shipping amount. Then you can add a rate calculation rule that adds to the base rate based on the total weight of the order. You don't even have to use Rules, as there's a hook that will let you perform this calculation: hook_commerce_shipping_calculate_rate()

dcharles’s picture

Thanks for getting back to me. I appreciate your help. I have Shipping 2.x installed along with your latest flat rate. I have a service set up with a base rate. It's all there but I cannot see a total order weight value in Rules that I can use to then set a rate for the shipping fee.

Should the total weight value be available in Rules or do I have to create that myself by looping through the products and adding the values? (I got the impressions from one of your previous notes that it should be available from the shipping API?).

Alternatively, if I use the hook method you suggest, what method can I use to then set the value of the shipping charge? Can you point me to an API that will show me what I need?

I'm not a PHP programmer and pretty new to Drupal so it's not particularly clear to me right now what I should be doing.

If you can point me to any resources for learning how to set the Rules for Shipping weights or how to do this programatically I would be grateful.

Thanks in advance.

rszrama’s picture

There is no total weight value available natively to Rules unfortunately; there is an API function for it in the Commerce Physical module, but you'd need to be a PHP programmer to write a custom action to take advantage of it. The closest you could come in Rules itself would be to add a loop on commerce-order:commerce-line-items and increment the cost of shipping based on each line item you came to. You might be able to use Rules to calculate the full total before altering the shipping rate, but at that point it'd probably be easier to learn PHP to make it happen.

dcharles’s picture

Thanks again. I guess I'll get learning PHP ;-)

ardnet’s picture

subscribe

ardnet’s picture

hi fiftyz, so do you mind to share to the community of what you have done with calculating shipping cost based on the weight of the product please :)

Thanks in advance.

marcmarc_’s picture

Hi, I had the same problem. So I posted my problem in the Drupal Commerce Forum, since there wasn't a real solution here. Randy Fay made a screencast to show how to do shipping by weight and it worked for me.

You can find the topic here: http://www.drupalcommerce.org/node/1721
and the screencast here: http://vimeo.com/33838479

Hope it helps.

LSU_JBob’s picture

omg, such useful info here, subscribed!

nandotinoco’s picture

Anyone looking to implement total weight conditions via Commerce Physical Product + Rules should look into this patch for Commerce Physical Product: http://drupal.org/node/1344962

#18 worked perfectly for me.

Hitby’s picture

Thanks for posting marcmarc_ - very helpful.

After running through the tutorial though I have two shipping line items on my order -
1. Weight Based Shipping which shows the standard charge and then a second
2. Shipping - which shows the extra charge calculated by the rule.

On the screencast this doesn't happen - Did you just end up with a single shipping item?

joncjordan’s picture

Same here... did you ever figure this out?

FiNeX’s picture

nobbyvo’s picture

Issue summary: View changes
nobbyvo’s picture

Hi guys,
I'm really confused because I don't know how to make a shipping rule and implement it:
I have 2 product types with a field called "weight" and it's type is "Physical weight"
It should do the following:
counting the weight of all products in the shopping-card and calculates the price like this:
0,1 kg - 24,9 kg = 4 €
25 kg - 49,9 kg = 8 €
and so on.

I read all above, but don't understand it full. The first worst thing is that I don't find the field "weight" in the data selector of rules. I made the field in the producttype visible as token, but it didn't help.
I 'm not a developer ... just a man who tries to build his own webshop with drupal commerce, building the side without kickstart. I got the products, the prices, the shopping card, the customer-catalog ... all it' fine exept the right shipping. So please please please ... may anybody can make a documentation or sceencast how to do it starting from the beginning in step by step? I searched the web, but found nothing really helpfully. I have taken a look of https://drupal.org/project/commerce_shipping_weight_tariff and it looks like what I want to use. I installed it and could make prices like I want. But there a 2 problems: 1) How to I say the modul to use my product field "weihgt" (which I cannot find in rules) and how can I activate this rules to my shopping card? No documentation found (just a short readme which doesn't help).

i have not preference (with or without the modul commerce_shipping_weight_tariff) but I have to get a solution. Otherwise all work on my side are for wast. So again: Please help.

Greetings
Nobbyvo

nobbyvo’s picture

Status: Closed (fixed) » Needs work
rszrama’s picture

Status: Needs work » Closed (fixed)

Commerce Physical Products has a condition for checking the total weight of the order. That's all you should need. Beyond that you'd need to be using the "Entity has field" condition as described in the FAQ linked above. For further support, please refer to https://drupal.stackexchange.com.

harshadananjaya’s picture

This drupal 7 ubercart module will help to you add shipping rate according to the ordered products weight.

https://github.com/harshadananjaya/drupal-ubercart-Weight-based-shipping

Summit’s picture

Him But Drupal Commerce is no Ubercart, will the same module apply then?
greetings, Martijn