2

I am writing a custom module to add surcharge values to a commerce order at the time of UPS shipping calculations. I am trying to find a way to access the total weight of the order.

I thought I would be able to access the weight from the array returned by:

entity_metadata_wrapper('commerce_order', $order);

Unfortunately it's not present in the data that I can see.

Does anyone know how I can access the total weight of an order or are these generated dynamically when the UPS shipping process is called?

2 Answers 2

1

I believe it is generated when it's needed, and not stored. But, after looking at the Commerce Order Weight Token module, you can get the weight using the following:

$weight = commerce_physical_order_weight($order);
2
  • I have not checked the mentioned module commerce order weight token but does this $weight = commerce_physical_order_weight($order); require the module or we can use it without the module?
    – harshal
    Feb 2, 2016 at 20:55
  • 1
    commerce_physical_order_weight is a function provided by the Commerce Phsycial Products module. As long as you have that module installed and are using it to configure weights for your products, the function will be available. The Commerce Order Weight Token module is not needed for this function.
    – thirdender
    Oct 9, 2016 at 20:02
1

Drupal Commerce itself doesn't require products to have weights, so there is no way for it to know what an order's total weight might be. However, the Commerce Physical Product module does at this support. I'm actually using that module for a project now and will be ensuring it has complete Rules support for the various API functions that determine whether or not an order / a particular line item is shippable and how much an order / a particular line item weighs.

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.