Tags/topics: 
1
Answers
Vote up!
0
Vote down!

Checking if Billing and Shipping address are the same

I need to check that an orders billing and shipping addresses are the same so that we can avoid accepting orders in certain circumstances if they differ.

This needs to be done prior to, or when checking valid shipping methods for the delivery address. Or course this may not be fool proof as even if the "same" address is entered twice it may not be identical! Probably only the country and post code values would be relativly fool proof and sufficient to check.

I've tried and failed using Rules as they seem to want to check an entity value against a constant rather then another entity value. Can this be done with Rules or will I have to write a module with a hook-?? method. If a module what hook method would be the best to use?

Asked by: donaldp
on November 1, 2012

1 Answer

Vote up!
1
Vote down!

You will need to use the condition "entity has field" multiple times, first to get the billing profile on the order and then the address on the billing profile. Also the same for the shipping address.

You can then use the standard rules data comparison on the address components.

Here is an example:

{ "entity_has_field" : { "entity" : [ "commerce-order" ], "field" : "commerce_customer_billing" } },
{ "entity_has_field" : { "entity" : [ "commerce-order" ], "field" : "commerce_customer_shipping"} },
{ "entity_has_field" : {
"entity" : [ "commerce-order:commerce-customer-billing" ],
"field" : "commerce_customer_address"
}
},
{ "entity_has_field" : {
"entity" : [ "commerce-order:commerce-customer-shipping" ],
"field" : "commerce_customer_address"
}
},
{ "NOT data_is" : {
"data" : [
"commerce-order:commerce-customer-billing:commerce-customer-address:country"
],
"value" : [
"commerce-order:commerce-customer-shipping:commerce-customer-address:country"
]
}
}

David Kitchen
Answer by: David Kitchen
Posted: Nov 5, 2012