Is there a way to show the total order weight at checkout, and/or the calculated weight of each line of the order? I have a client who offers free freight for orders over 1000lbs and they would like to let the customer see total weight so they now how much more they'd need to order to qualify for free shipping. Thank you.

Comments

gundara’s picture

+1

ioanmar’s picture

+1

kevster’s picture

This would be a great feature as although we have weight on each product line item we cant see a way to add the total weight order, +1...

blueblade’s picture

+1

ecvandenberg’s picture

Issue summary: View changes

I think this request is still valid. How can I help to get this going?

mrawat’s picture

+1

zenimagine’s picture

+1

roman_l’s picture

StatusFileSize
new4.8 KB

I'm disappointed to see no answer to this. Near 5000 installs and no tip from the users nor the devs ?

Anyway, first thanks for this great module which, i think, should be a part of DC core (weight and dimensions are needed for shipping rules and price calculations!).

Let's explain how to render the total order weight in a view, and then, show this view in a panel.

You'll need two modules : views_php (see doc for enabling php text format) and commerce_views_pane.

Enable them, create a new view with format "Commerce Checkout Pane".
Add a contextual filter : Commerce order id, with default value "current user order id".

Add a new hidden field "order id".
Add a new field "global : php".

In this field enter the code below :

 <?php
// we get the order_id from the view filter
$order_id = ($row->order_id);
// we load the order entity
$order = commerce_order_load($order_id);
// if we do not define the unit here, the weight will show in lb by default
$unit = 'kg';
// we get the total weight value in the unit we chose
$order_weight = commerce_physical_order_weight($order, $unit);
// we format with the physical_weight_format function
$order_total_weight = physical_weight_format($order_weight);
// we print the total order weight
print 'Your order has total weight : '.$order_total_weight;
 ?>

And voilà ! enable the pane in your order workflow and see the total order weight rendered.

You can use this code in any view where you can get the order_id (cart summary, cart, ...), in rules, custom module...

@kevster (3 years late sorry) : if you want to show, for example, each product unit weight in the cart or line items view, you must alter the views and add a "commerce product referenced by line item" relationship, then the field "commerce product : weight" will be available to add in the table.

Hope it helps, and sorry for my bad english !

With this post you'll find the view export so you can import it (beware : default language of the store i work for is French). If i have time to, i'll try to commit a patch to include the view in the module.

zenimagine’s picture

Great. Thank you very much.

mrawat’s picture

Thanks for this @piactif

Is it possible to show order weight in the cart?

roman_l’s picture

@mrawat yes as the shopping cart has an order id

sano’s picture

For cases when one needs to use the weight in a rule:

  1. create a variable action of type text
  2. put this code into the Value field for the default value of the variable wrapped into <?php ?> tags:
    $order_id = $commerce_line_item->order_id;
    $order = commerce_order_load($order_id);
    $weight = commerce_physical_order_weight($order, 'g');
    echo $weight['weight'] . ' ' . $weight['unit'];
    
  3. If all you want is a number without the unit, delete the
    $weight['unit']
    

    from the code.

  4. name the variable and save the action
  5. if you need to do additional computations with the weight, you might need to convert the new variable to decimal using the standard rules-provided action