Calculating shipping rate on country not working – finding workaround-Collection of common programming errors
I installed commerce-kickstart 2.0-rc2 and need to set three shipping rates for different countries. I tried it the “obvious way” using flat rates module and rules “Order address component comparison”, but it doesn’t work. I followed the instructions from http://www.drupalcommerce.org/node/2511 but the comparison mostly fails, sometimes not, no idea why. Don’t know if it’s an address module issue or rules. It worked for me on an earlier beta release of commerce-kickstart.
So, what I did:
- Created three different flat rate shipping services.
- Created a calculation rule.
- First condition: data comparison (Data to compare: [commerce-line-item:type], Data value: Shipping)
- Second condition: entity has field (Entity: [commerce-line-item:order], Field: commerce_customer_shipping)
Now I should be able to use “Order address component comparison”, but it doesn’t work. I can dpm in actions for the shipping-line-item and can see the country-code, but I don’t find a way to get it compared.
I tried it with “data comparison” rule, but it seems, I can’t get deep enough in the array to get the correct field. I can dpm this: commerce-line-item:order:commerce-customer-shipping
, and I see the country code here: ->commerce_customer_address['en'][0]['country']
, but I don’t find a way to use it for comparison.
Maybe there is an easy solution with executing custom php code in rules to compare the countries?
Maybe the problem has to do with field translation. The customer profile types billing and shipping information have field translation on. I tried to disable translation, but after next test order it was enabled again.
Then I checked the database fields for address management and found something strange. In field_data_commerce_customer_address table the language is ‘en’, but in field_data_commerce_customer_billing and -shipping it is ‘und’.
If I switch page language to english, the checkout finishes without error. If site language is german, the addresses are not shown on checkouts review page, and on complete page I get errors from presave function.
Undefined index: und in commerce_order_commerce_customer_profile_presave() (Zeile 522 von /drupal-commerce/profiles/commerce_kickstart/modules/contrib/commerce/modules/order/commerce_order.module)
Undefined index: und in commerce_order_commerce_customer_profile_presave() (Zeile 523 von /drupal-commerce/profiles/commerce_kickstart/modules/contrib/commerce/modules/order/commerce_order.module)
Invalid argument supplied for foreach() in commerce_order_commerce_customer_profile_presave() (Zeile 532 von /drupal-commerce/profiles/commerce_kickstart/modules/contrib/commerce/modules/order/commerce_order.module)
Undefined index: und in commerce_order_commerce_customer_profile_presave() (Zeile 522 von /drupal-commerce/profiles/commerce_kickstart/modules/contrib/commerce/modules/order/commerce_order.module)
Undefined index: und in commerce_order_commerce_customer_profile_presave() (Zeile 523 von /drupal-commerce/profiles/commerce_kickstart/modules/contrib/commerce/modules/order/commerce_order.module)
Invalid argument supplied for foreach() in commerce_order_commerce_customer_profile_presave() (Zeile 532 von /drupal-commerce/profiles/commerce_kickstart/modules/contrib/commerce/modules/order/commerce_order.module)
Can someone help me with that? Did I do some configuration wrong? Is it a module problem?