The current patch contains the following:

  • Order total weight comparison rule condition
  • Maximum product dimension comparison rule condition
  • The order contains shippable products rule condition

Original Issue Post:

I've written some rules conditions to do with physical properties of commerce entities that I thought people might find useful. I've been using them with flat rate shipping to decide when to offer them. So far, there's:

  • Is the total weight of every product in an order under a certain limit?
  • Is the maximum dimension of any product in an order is under a certain size?

Would you consider adding these to this module? :) I'll attach a patch in a mo.

Comments

rupertj’s picture

Status: Active » Needs work
StatusFileSize
new5.6 KB

I've just noticed that some functions in the version of commerce_physical I just pulled down duplicate some code I added, but here's the patch anyway :)

I'll give it a bit of a rework so there's no duplicated functionality, but I'd still be interested in what people think otherwise.

rupertj’s picture

Status: Needs work » Needs review
StatusFileSize
new12.86 KB

New patch. This one's better, in that it uses the existing functions in commerce_physical, like commerce_physical_order_weight(), and adds some corresponding functions for getting dimension info.

Functionality-wise, the rules conditions are the same as before.

ñull’s picture

Unfortunately I don't see the new conditions appear. What could be the cause? Can you give me more information about the environment so that I might reproduce

kiwimind’s picture

#2 worked great for me. Might be an idea to include this in the module.
I'm working on a sliding scale of shipping by weight.
My 0-500g rule has a single condition set - weight < 0.5 kg.
My 500-1000g rule has 2 conditions: weight < 1kg and NOT weight < 0.5kg.
Works a treat.
My only suggestion would be to allow users to select which unit they wanted the value to be in. It seems set at kg, unless that's picking up on units I've got set in my store.
Thanks Ru!

webroru’s picture

Might be an idea to include this in the module.

+1
and #3 +1
can anybody give more info about calculating total weight?

kiwimind’s picture

The total weight is calculated when you use the condition of Commerce Physical > Order's total weight is under a chosen limit.

webroru’s picture

StatusFileSize
new13.34 KB

But I have no condition of Commerce Physical in the Rules. Maybe I'm wrong to apply a patch? I attached the patched file. Please check whether all okay with it.

When I apply patch #2 it display this notice:

can't find file to patch at input line 5
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/commerce_physical.module b/commerce_physical.module
|index dde39e2..8ab2207 100644
|--- a/commerce_physical.module
|+++ b/commerce_physical.module
--------------------------
File to patch:

Perhaps the problem is that I do not have this file - commerce_physical.rules.inc?

webroru’s picture

Ok. I understand. I should manualy create this file.

webroru’s picture

Does anyone know how to get a variable with a value weight of the order?

Jason Dean’s picture

rupertj you are a star - this works great :)

thanks!

rogermcallen’s picture

Solved! I have to set up the rules in the "configure component" of each shipping services! Now seems to work!
The rules will be:
Rule 1: order total weight < 1kg
Rule 2: order total weight < 10kg, AND, NOT order total weight < 1.1kg

Thanks a lot again for the patch!

Thanks rupertj for the patch! I'm just new to rules.. I'm trying to set it up.

I want to do like this:
0 to 5 kg -> 8,50€
5 kg to 10 kg -> 10 euro

So I made 2 shipping services:
1) Shipping for orders under 5kg, price 8.50€
2) Shipping for orders under 10kg, price 10€

The I made two shipping rules:
1) Rule one:
Conditions:
Order's total weight is under a chosen limit
Parameter: Order: [commerce-line-item:order], Weight limit (kg): 5

Actions:
Add a rate for a shipping service to an order
Parameter: Shipping service: Bartolini fino a 5kg, Order: [commerce-line-item:order]

2) Rule 2:
Conditions:
Order's total weight is under a chosen limit
Parameter: Order: [commerce-line-item:order], Weight limit (kg): 10
NOT AND
Order's total weight is under a chosen limit
Parameter: Order: [commerce-line-item:order], Weight limit (kg): 5

Actions:
Add a rate for a shipping service to an order
Parameter: Shipping service: Bartolini da 5.1 a 10kg, Order: [commerce-line-item:order]

But when I go in the checkout I have all the two shipping services to chose... where I'm wrong?

Thanks to everyone that can help me!

ñull’s picture

Just reporting that patch works like promised. the rules.inc file should be in the same folder and because of faulty patching it ended up in a folder called b. The conditions became available and are sufficient for their purpose.

When can we consider this "reviewed and tested"?

Patricec’s picture

Patch #2 works great for me. Many thanks.

rupertj’s picture

Status: Needs review » Reviewed & tested by the community

Let's see if we can get Ryan's attention ;)

ñull’s picture

bump,

When is this going to be at least submitted to dev?

savingstrangers’s picture

Patch worked PERFECTLY for me, thanks!

Anyone have a decent method of converting the kg to ounces? Any makeshift way of doing this would be great, my products are in ounces in my store, so I created ranges of shipping flat rate prices, and it's not the most friendly thing to convert my ranges to kilograms rather than convert the patch to be using ounces. Thanks!

duaelfr’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new10.02 KB

Hi !

#2 seems to work perfectly but here is a new patch which :

  • adds a new condition "commerce_physical_rules_order_is_shippable"
  • changes parameter key "order" to "commerce_order" as everywhere in the commerce module (seems more conventional)
    [Take care ! The rules created with the previous patch won't continue to work with this one.]
  • makes a tiny change in the functions' return statements to make them less dummy (sorry) as follow :
    if ($something_true) {
      return FALSE;
    }
    return TRUE;
    

    becomes

    return !$something_true;
    
  • and finaly, adds a combo to choose the unit for each condition
duaelfr’s picture

Wow !
Someone told me that a big part of the patch was missing ! (enjoy git diff...)
Here is the complete one.

Enjoy

ponies’s picture

Commerce ups calls commerce_physical_order_volume. I added it back in using commerce_physical_order_dimensions to get the dimensions and sanitize the units then returned the $volume array.

bradhawkins’s picture

@ponies can you explain a bit more? I follow what you're saying except for the implementation. Did you alter commerce_ups or the above patch?

bradhawkins’s picture

Also, I'm just wondering why was the volume function removed in the first place? Since Commerce UPS needs it to work properly and I'm guessing there's a decent number of users for UPS.

Anonymous’s picture

I can confirm that #18 works - thanks very much!

My feedback would be that the naming is slightly misleading: calling the condition "Order's total weight is under a chosen limit" makes it seem like the comparison would be "less than" whereas actually it's "less than or equal to".

Also it is slightly awkward to implement weight bands e.g. 0-10kg, 10-20kg etc, as you have to do 2 conditions: one for "NOT total weight is less than 10kg" and "total weight is less than 20kg". Now I don't know much about Rules, but would it be possible to instead let the user do a normal "Data comparison" condition, and feed in the order total weight as the input variable? That would make it much simpler for the user.

muhammad.tanweer’s picture

Hello DuaelFr,

Thanks for the great patch. As mentioned, it works for several people, however, I applied the latest complete patch to commerce_physical module, but still I am unable to see the rules here : http://mywebsite.com/admin/config/workflow/rules
I even uninstalled and re-installed the module, cleared cache, did everything that I understood should work but still no clue. I am stuck, can you please give me a few lines of quick help? Would be appreciated.

Thanks

duaelfr’s picture

This patch provide Rules conditions which are in the Components tab.
They are usable in common rules but the patch does not provide any of them.

muhammad.tanweer’s picture

Thanks for responding back. However, I am still unclear on the use of it. Here is the scenario I want to accomplish. Can you please give me some instructions? Would be appreciated

I have a boolean field in the commerce product types named "non shippable" . I want that if the boolean field is checked (i.e. its value is 1) , it will mean that the item is non-shippable. Now, if an order contains all the products which are non-shippable, I need to skip the shipping step. Can you please instruct me specifically about this? Would be highly appreciated.

Muhammad.

duaelfr’s picture

Your use case is a bit complicated. By keeping your boolean field you will have to build a really complex rule to meet your needs.
However, Commerce Physical, with this patch, gives you a new condition which name is "Order is shippable". An order is shippable when the sum of its weights or dimensions is not null.

andyf’s picture

I needed to check if the weight was less than or equal to a value, which isn't possible with #18. The attached patch is #18 with an extra parameter for the total weight and maximum dimension conditions that lets you specify the operator to use (eg. <=). I'm afraid I only tested the weight condition (that's the one I need), but I also modified the dimension condition as I presume someone at some point might find that useful.

Thanks

ponies’s picture

@bradhawkins: Sorry it took me a while to get back to this. I lost my machine and the patch along with it. I'm rerolling now.

Here's the error I'm getting with #18

Call to undefined function commerce_physical_order_volume() in /var/www/drupal/sites/all/modules/commerce_ups/commerce_ups.xml.inc on line 31

ponies’s picture

Here's #18 with commerce_physical_order_volume() added back in.

ponies’s picture

Disregard #29. This one did the trick for me. There was a dimensional misalignment with the $dimension array.

andyf’s picture

Status: Needs review » Needs work

Imho #30 should be rerolled with the operator changes from #27. This is in line with other Commerce Rules, eg. Order contains a particular product, Total product quantity comparison, Order balance comparison.

nandotinoco’s picture

#18 worked a treat for me. Looking forward to see this patch rolled out. Thanks

la.carvalho’s picture

Could someone please give details on how to work with this? I'm quite new to Drupal and can't seem to understand how this works...

I have a shipping service setup and want to be able to set different prices depending on weight ranges. How can I do that?

Thanks a lot

muhammad.tanweer’s picture

Your scenario is pretty straight forward. You ll need to create a rule and add the case in it to check order's weight. You can set different shipping price depending on weight.

Muhammad.

scarr’s picture

muhammad.tanweer: did you get your situation in #25 figured out, or did you just use the "Order is shippable" suggested by #26? I have a similar situation using a boolean to indicate whether an item ships freight, and am wondering what your rules solution was if you did go that route?

Thank you!

Steve

tbenice’s picture

had some trouble applying #30, #29 applied and I changed the 1 line 29->30. FYI.

tbenice’s picture

Hey, can we make this feature compatible with commerce_product_bundle? It would just be a couple more lines to dig into bundle line items....

I'm going to make it so on my version and am happy to contrib back if you like the idea.

ioanmar’s picture

1. I had installed physical module. Then created a weight field for my product type and then I also installed commerce_physical. To begin with, should I recreate the weight product type field?

2. I have applied the #18 patch succesfully and I can see these three new rules in the conditions selection list, under commerce physical. I have created some test products with a value in their weight field. Here's is what I want to succeed:

I have a flat rate for shippable products and I want to charge extra shipping costs to customers according to order's total weight (note that some products won't have anything in the weight field and in this case I don't want to take them into consideration for the shipping cost calculation).

I want to charge €3 (flat rate's base charge) if the order is 0-2 kilos (that happens already with that flat rate above).
BUT: In case the total order's weight is more than 2 kilos, I want to add €1.2 to shipping cost for every additional kilo.
e.g. order has 3 products:
> Product 1 - 2 kilos
> Product 2 - 0 kilos (or no value in weight field)
> Product 3 - 2.5 kilos
>> Total order's weight: 2+0+2.5 = 4.5 kilos (ie 2.5 kilos to be charged extra)

So the shipping charge should be €3 (flat rate's base) + €1.2*2.5 = €6.

I would really appreciate any suggestions on this.

duaelfr’s picture

I think the simplest way to acheive this is to create one flat rate per weight slice and to select the good rate using the given conditions.

For this module to be complete we should add attributes to the order for the total weight and the maximum size which could be used as a token to make some calculation as you need. If someone have some time to spend on it, I think it would be really great.

[Note for the one who will do this : please take the time to merge the patches #30 and #27, thanks]

ioanmar’s picture

Thank you for your quich response.

Do you suggest to create a flat rate for order weight < 2 kilos and additional ones for total order weight
- <3 &not <2
- <4 &not <3
- <5 &not <4
etc etc ??
That would work well but I need too many flat rates for all these cases. To play it safe, I could create let's say 10 of these flat rates but customers could order even heavier stuff from my store from time to time...

Isn't there a way to have the 1st rule for order weight <2 kilos and as weight increases, multiply the order weight to €1.20 for every extra kilo?

duaelfr’s picture

I think you currently cannot find a better solution.

With a bit of code you could have a token for the order's total weight which could be used in a calculation rule but not with the actual patch.

ioanmar’s picture

I created these flat-rate & rules pairs but ALL flat rates are available to customer during checkout (also see #11 by rogermcallen).

I got it finally - the correct way to implement this is NOT to create new calculation rules for each flat rate but to edit each flat rate's component by adding the proper condition for order's weight.

muhammad.tanweer’s picture

Infact I used the way that if an order's weight is 0, its shipping is skipped. Otherwise, shipping is applied. My requirement was fulfilled with that.

tbenice’s picture

need to change line 320 from:

if (!empty($weight)) {

to:

if (!empty($weight) && ($weight['weight'] > 0)) {
divan’s picture

Error: Unknown condition commerce_physical_rules_order_is_under_weight_limit

Everything worked perfectly ... but today this error here :(
I tried to reinstall the module and put the patch but nothing works anymore.
This happened after update Flat Rate module ... any ideas?

Can anyone give me scheme commerce_flat_rate_service table from the database?

divan’s picture

Category: feature » support
Priority: Normal » Critical

Error: Unknown condition commerce_physical_rules_order_is_under_weight_limit

star-szr’s picture

Category: support » feature
Priority: Critical » Normal

@divan - Please don't change the category or priority, the issue was correctly filed before.

rupertj’s picture

It'd be nice to get this issue back on track actually - it's looking slightly at risk of descending into nothing but support requests.

Which patch are people having success with? If we could get it committed, then people could file their own issues for support. If someone who's set this up recently could submit a re-rolled patch with any of the mentioned tweaks, that'd be even better.

divan’s picture

divan’s picture

Can someone explain everything in one post step by step? Please. This will help all people who have a problem with this module.

... or if someone can put a module whith patch on zip file?

ponies’s picture

#30 works for me.

divan’s picture

ponies How? I already try the third day ... in components of the Rule does not appear Order's total weight is under a chosen limit ... Please put your folder commerce_physical in a zip to check where my error

joecanti’s picture

Hi all,

#27 works great for me - I suggest it gets committed as I think it covers most possible options.

Thanks everyone! Joe

joecanti’s picture

StatusFileSize
new4.07 KB
new13.34 KB

Ok step by step:

- Download the module. Download the patch file #27.
- Use a program to patch the files. the .module file gets changed, and commerce_physical.rules.inc gets created.
- Upload. overwrite. Clear all caches.
- Now add a flat rate shipping service. Give a name and save.
- Edit the component, and add a condition. You can now choose a weight condition (under a new section called 'commerce physical'.
- To show this shipping option for weights under 5kg, just choose >, and then add 5 as a weight.
- To show this shipping option for weights between 5 and 10, first add a condition for '>5', then add an 'AND' condition, then add a final condition for '<10' - this gives you a weight band between 5 and 10.

- Now add a new weight field to your products - edit some products and add the weight values in - and now test by adding to your basket, and proceeding to the checkout.

Hope this helps!
(ps patching is sometimes annoying - attached is the .module file and the new commerce_physical.rules.inc - put them both in the module folder after renaming to look like: (This is for #27)

commerce_physical.module
commerce_physical.rules.inc

Joe

shaneonabike’s picture

I can confirm that #27 works for me :)

shaneonabike’s picture

I started experiencing some issues where the shipping page was not being skipped and throwing errors. I realized that was a result of the physical weight now being zero and not being passed properly into the physical weight conversion. Patched that here: #1887116: Physical Weight conversion

torgospizza’s picture

Status: Needs work » Needs review

I'd also like to see #30 and #27 combined and re-rolled; they overlap in too many places to make a clean patch possible, but at this point it looks like #27 is the preferred patch.

Can someone from the Commerce team look at this and share their thoughts? This is our #1 requirement for our store (99.9% of our products are downloads) and so this is fundamental for us.

Setting to "Needs review" for now, so someone (maybe @rszrama or @googletorp?) can take a look, but NB that this should probably be "Needs work".

Thanks!

nodecode’s picture

Just checking if anyone has managed to combine #27 and #30 as seems to be the consensus? I agree it looks pretty messy of a job and fear this is where the issue may stall. IMHO the rules features introduced here will go a long way toward resolving a number of deficiencies with commerce shipping.

svouthi’s picture

Thank you, joecanti, for posting the files. I haven't any experience with patches yet (though I'm sure I will get some), so I appreciated having quick access to this feature. However, after loading the files, I found that commerce_physical.module did not play nicely with my UPS shipping setup, which threw errors (I'm running Commerce Physical v.7.x-1.x-dev and Commerce UPS v.7.x-2.0.) So, I switched back to my original commerce_physical.module file (as if I just added commerce_physical.rules_.inc to my setup) and all seems fine. Will see how this goes. Thanks again!

DrMicky’s picture

#27 Works great for me too thanks.

When I applied I got the following result (not sure if it's important but thought I should report it)

$ git apply commerce_physical_rules_conditions-1344962-27.patch
commerce_physical_rules_conditions-1344962-27.patch:411: trailing whitespace.
  
commerce_physical_rules_conditions-1344962-27.patch:424: trailing whitespace.
  
warning: 2 lines add whitespace errors.
chrisNtampa’s picture

#30 worked for my project and was critical in making the client happy. Thanks to everyone that contributed.

summit’s picture

Hi, will #27 in combination with #30 be committed please?
I do not know what to do to get this working?
Greetings, Martijn

ponies’s picture

I'll see if I can combine the two this week.

zmove’s picture

Subscribing and I hope it will be commited soon as it's a so basic function to test order total weight to calculate shipping and this is so complicated ATM with rules, loops and components.

It should be as easy as ubercart that provided a weight condition to test without the necessity to create loop, components etc...

summit’s picture

It would be great if also Dimensions would be implemented in the rules. Lots of shipping prices consists of weight and dimensions volume...

greetings, Martijn

deggertsen’s picture

I have attempted to combine the patch in #27 and #30 in this patch. I have not yet tested so someone might want to double check to see if I missed anything.

The main difference I was able to find in #27 to what is in #30 is in commerce_physical.rules.inc.

#30 also brought back the commerce_physical_order_volume() function.

I discarded the rules in #30 commerce_physical_rules_order_is_under_weight_limit and commerce_physical_rules_order_maximum_dimension_is_under_size in favor of what appear to be better rules in #27 commerce_physical_rules_order_weight_comparison and commerce_physical_rules_order_max_dimension_comparison.

Most everything else appeared to be the same.

calmforce’s picture

There is a bug in the patch #66: the function commerce_physical_rules_order_max_dimension_comparison() uses unidentified variable $limit. It should use $value provided as a function argument.

deggertsen’s picture

Good catch. Should be fixed now in this patch version.

deggertsen’s picture

Status: Needs review » Reviewed & tested by the community

I've been testing this on a few sites including a production site for the last month (almost) and I have had no problems. Moving to RTBC.

Tor Arne Thune’s picture

I've had this running on a production environment for about 3 weeks now so, +1 to the RTBC of #68.

torgospizza’s picture

Would love to see the patch committed as well.

Failing that, perhaps the Rules could be added to Commerce Rules Extra?

Anonymous’s picture

+1 for me too, can someone submit this patch please? Thank you so much!

blueblade’s picture

For those who are trying to get total weight, please see this post http://www.drupalcommerce.org/discussions/817/shipping-prices-depending-.... Much appreciated if you can tell me what Fonant means in his post "This can be output using the Debug value action, if the Devel module is enabled." Everything looks fine in the rule he sets up but I just cant get the variable to show up at all....help, please.

deggertsen’s picture

@torgosPizza, adding these Rules to Commerce Rules Extra may be good seeing as this module has not had a commit since October of 2011 and rszrama is next to impossible to reach.

deggertsen’s picture

Issue summary: View changes
Related issues: +#2139413: commerce_physical Rules conditions

Removed some old patches from the issue display to make it more clear to those first visiting this issue.

Also, lets move any discussion about having these rules as part of Commerce Rules Extra to this issue: #2139413: commerce_physical Rules conditions

deggertsen’s picture

blueblade’s picture

When I load "Maximum Product Dimension Comparison", I dont see any options that let me choose any of the dimensions, all I see is the Data Selector which I have tried many ways to access the width/length/height with no success, the comparison operator, value and dimension unit dropdown. Can someone please tell me how to specify the width/length/height to compare, please?

deggertsen’s picture

@blueblade. Based on the function commerce_physical_rules_order_max_dimension_comparison() it appears that it is setup to check each dimension and use the largest dimension as the Maximum. So it will check the width, length, and height and compare it against what you put in as the value. If any of those do not match your value and operator it will return False. For example if you entered 5 for your value and < for your operator and the dimensions being compared are height:4, width:3, and length:5, it will return false because the length is not less than 5. Hopefully that makes sense.

So this works as designed. I think your concept probably makes more sense for this rule, but it would take some modification. Seeing as none of my clients need this rule I will probably not be the one to make those modifications.

blueblade’s picture

@deggertsen Many thanks to your quick reply. I was just wondering how to get this figured out but now I think I can go to bed and have a good night sleep. Thanks so much!! Have a wonderful day yourself.

macman911’s picture

I've applied patch 66 but I can't see "commerce physical" rules listed in the conditions lists. I've spent two days on it with no luck. I could really do with this feature working, so would greatly appreciate some suggestions.

deggertsen’s picture

Hopefully you mean the patch in #68 as there was a problem with the one in #66. Be sure that you have cleared all your caches as the new rules conditions will not appear until you do.

macman911’s picture

Thank you for your fast reply @deggertsen - it finally worked, weight is working beautifully :) However, if I use the Maximum product dimension comparison I get this error: "Fatal error: Cannot use assign-op operators with overloaded objects nor string offsets in /home/public_html/profiles/commerce_kickstart/modules/contrib/physical/physical.module on line 855" and "Notice: Undefined variable: multiplier in physical_dimensions_convert() (line 855 of /home/public_html/profiles/commerce_kickstart/modules/contrib/physical/physical.module).".

deggertsen’s picture

@macman911, could you post your rule here so that I can see what operator you are using and the context of the rule? I'm not sure I'll be able to help you with this one, but I'm willing to look at it.

deggertsen’s picture

Issue summary: View changes
macman911’s picture

Thank you @deggertsen for the kind offer. Here is an export of the rule (I hope this is what you meant).

{ "commerce_shipping_service_royal_mail_signed_for_1st_class_" : {
"LABEL" : "Rate Royal Mail Signed For 1st Class - Small Parcel",
"PLUGIN" : "rule",
"REQUIRES" : [ "commerce_order", "commerce_physical", "commerce_shipping" ],
"USES VARIABLES" : { "commerce_order" : { "label" : "Order", "type" : "commerce_order" } },
"IF" : [
{ "commerce_order_compare_address" : {
"commerce_order" : [ "commerce_order" ],
"address_field" : "commerce_customer_shipping|commerce_customer_address",
"address_component" : "country",
"value" : "GB"
}
},
{ "commerce_physical_rules_order_weight_comparison" : {
"commerce_order" : [ "commerce_order" ],
"operator" : "\u003C",
"value" : "2",
"unit" : "kg"
}
},
{ "commerce_physical_rules_order_max_dimension_comparison" : {
"commerce_order" : [ "commerce_order" ],
"operator" : "\u003C",
"value" : "20",
"unit" : "cm"
}
}
],
"DO" : [
{ "commerce_shipping_service_rate_order" : {
"shipping_service_name" : "royal_mail_signed_for_1st_class_",
"commerce_order" : [ "commerce-order" ]
}
}
]
}
}

deggertsen’s picture

@macman911, Sorry it took me so long to get back. Unfortunately, I can't see any problems with your rule and have no idea why you would be getting that error. Did you ever figure it out?

Open Pixel’s picture

Hi all,

I wanted to thanks all contributors for this patch. I made some tests and it works perfectly ...

It's a pity that this kind of features aren't included in DC package.

Thanks for all

jpmelguizo’s picture

Thanks for the patch. It was really usefull for an specific weight shipping tariff system that I needed for a shop.

The system itself had 5 different weight intervals with fixed shipping rates and then a price-per-kilo addition for everything above that. e.g.:

  • <= 1kg = 4€
  • <= 3kg = 4.5€
  • <= 5kg = 5€
  • <= 10kg = 5.9€
  • <= 15kg = 7.5€
  • > 15kg = +0.5€ per kg

I added an action in order to get the total order weight so I could use it later in a calculation rule:

function commerce_physical_rules_action_info() {

  $actions = array();

  $actions['commerce_physical_rules_get_order_weight'] = array(
    'label' => t("Get order total weight"),
    'parameter' => array(
      'commerce_order' => array(
        'type' => 'commerce_order',
        'label' => t('Order'),
      ),
      'unit' => array(
        'type' => 'text',
        'label' => t('Weight unit'),
        'options list' => 'physical_weight_unit_options',
        'restriction' => 'input',
        'default value' => 'kg',
      ),
    ),
    'provides' => array(
      'total_weight' => array (
        'type' => 'decimal',
        'label' => t('Total weight of an order'),
        ),
    ),
    'group' => t('Commerce Physical'),
  );

  return $actions;
}

function commerce_physical_rules_get_order_weight($order, $unit) {

  $order_weight = commerce_physical_order_weight($order, $unit);

  return array(
    'total_weight' => $order_weight['weight'],
  );
}

I'm sure there would be many different ways to implement what I needed, but this was the easiest for me. Also, having the total order weight as a variable might be useful for other cases too.

Exigo’s picture

#68 worked for me. After several days of struggle and seaching of a solution I found it. If it had been commited to the module I would have solved my problems with shipping weight calculations so much easier. Many thanks to everyone who have contributed to this patch. If the original authors of the physical module do not have the time for review, should someone else take it over?

zmove’s picture

Any news about an officiel commit ? It's marked as reviewed and tested, and it's quite annoying now to take care of the module updates because you have to apply patch each time you update.

deggertsen’s picture

rszrama is probably the one who would need to commit this and he is one busy dude. Maybe someone would want to PM him and offer to co-maintain this module?

drupal4u.org’s picture

@deggertsen: I can follow up to #68. Weights work perfectly. This saved my day :-)

Then I start with the dimensions. Before applying #68 I get the following error for dimensions which I think is „normal“, because #68 is not yet applied:

„Notice: Undefined variable: limit in commerce_physical_rules_order_max_dimension_comparison() (Zeile 113 von /home/httpd/vhosts/immodeal.ch/wood3/sites/all/modules/commerce_physical/commerce_physical.rules.inc).

After applying #68 I get the same fatal error as macman911 in #82:

Fatal error: Cannot use assign-op operators with overloaded objects nor string offsets in /home/httpd/vhosts/immodeal.ch/wood3/sites/all/modules/physical/physical.module on line 855

perignon’s picture

Would there be any interest in adding this to Commerce Rules Extra? Someone brought it up in the issue queue almost a year ago #2139413: commerce_physical Rules conditions

rcodina’s picture

The patch on #68 doesn't work for me because new options doesn't appear for me. However if I take all the code inside commerce_physical.api.php and I put it adapted into a new module (inside .module file) it works like a charm. Maybe a new patch has to be done with a hook in .module file informing in this module there are plugins for rules module.

deggertsen’s picture

@rcodina, perhaps you could help write a patch for #2139413: commerce_physical Rules conditions. I'm having a hard time finding time to do it.

rcodina’s picture

@deggertsen I don't have much time right now. However I have uploaded what I've done here. Maybe helps someone to do the patch. I'm testing the code and probably commit fixes soon.

This may be interesting too for somebody.

das-peter’s picture

Assigned: Unassigned » das-peter

Hi there,
these changes look really promising. As I've lately got maintainer permissions for this module I'll have look into this soon.

deggertsen’s picture

@das-peter, that would be awesome. Let me know if you have any questions. I would way rather see these committed to Commerce Physical Product than to Commerce Rules Extra. I don't really like those "extra" modules when I can avoid them. I think the patch in #68 is ready to go. I've been using it for awhile now.

  • das-peter committed 2ae3778 on 7.x-1.x authored by deggertsen
    Issue #1344962 by deggertsen, ponies, DuaelFr, rupertj, joecanti, AndyF...
das-peter’s picture

Status: Reviewed & tested by the community » Fixed

Here we go.
Thanks to all that worked on this!

I just had some minor cleanups to do -> coding standards (I recommend using the CodeSniffer in the coder module).
The one change I didn't commit is this:

-function commerce_physical_order_volume($order, $unit = 'in') {
+function commerce_physical_order_volume($order, $unit = 'cm') {

As much as I'm in favour of using the metric system by default, this would be an API change since it could break modules that use the function and simply expect "in" as unit.

deggertsen’s picture

Thank you! So glad to have this committed!

Also thanks for the Code Sniffer recommendation. Some of us just don't know about these sorts of things yet so it's nice to be educated =).

Status: Fixed » Closed (fixed)

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

lalbright’s picture

So based on das-peter's comment #100, regarding the metric system, does that mean that this code now works for US Standard? Not metric? Or both?

perignon’s picture

Remember that the world over, Metric is the standard of measure. Even in the US the meter is the standard length of measure and has been since 1893. People in the US don't realize this fact that an inch is standardized against the meter.

Jeremy Scott’s picture

When I click on the commerce_physical_rules_conditions-1344962-68.patch in #68 it opens the file in another tab. What do I have to do to get this to work on my website. Any help will be greatly appreciated. Thanks.

torgospizza’s picture

@Jeremy Scott, since this is listed as "committed" the easiest way would be to download the -dev version of the module.

Jeremy Scott’s picture

@torgosPizza, Thanks for your response. That is the version I have installed. Could you tell me how to enable the shipping rate selection by weight?

torgospizza’s picture

It should be part of Rules, available as a new Rules condition. I haven't used that one in particular yet, though, so I don't think I can be of much help there.

Jeremy Scott’s picture

Ok, thank you very much. Maybe someone who has used it will be able to offer me some guidance.

Jeremy Scott’s picture

I found the answer in #54. Apparently I overlooked it the first time I read through the comments.