{"id":2916,"date":"2014-03-10T12:35:01","date_gmt":"2014-03-10T12:35:01","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/10\/calculating-shipping-rate-on-country-not-working-finding-workaround-collection-of-common-programming-errors\/"},"modified":"2014-03-10T12:35:01","modified_gmt":"2014-03-10T12:35:01","slug":"calculating-shipping-rate-on-country-not-working-finding-workaround-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/10\/calculating-shipping-rate-on-country-not-working-finding-workaround-collection-of-common-programming-errors\/","title":{"rendered":"Calculating shipping rate on country not working &#8211; finding workaround-Collection of common programming errors"},"content":{"rendered":"<p>I installed commerce-kickstart 2.0-rc2 and need to set three shipping rates for different countries. I tried it the &#8220;obvious way&#8221; using flat rates module and rules &#8220;Order address component comparison&#8221;, but it doesn&#8217;t work. I followed the instructions from http:\/\/www.drupalcommerce.org\/node\/2511 but the comparison mostly fails, sometimes not, no idea why. Don&#8217;t know if it&#8217;s an address module issue or rules. It worked for me on an earlier beta release of commerce-kickstart.<\/p>\n<p>So, what I did:<\/p>\n<ol>\n<li>Created three different flat rate shipping services.<\/li>\n<li>Created a calculation rule.<\/li>\n<li>First condition: data comparison (Data to compare: [commerce-line-item:type], Data value: Shipping)<\/li>\n<li>Second condition: entity has field (Entity: [commerce-line-item:order], Field: commerce_customer_shipping)<\/li>\n<\/ol>\n<p>Now I should be able to use &#8220;Order address component comparison&#8221;, but it doesn&#8217;t work. I can dpm in actions for the shipping-line-item and can see the country-code, but I don&#8217;t find a way to get it compared.<\/p>\n<p>I tried it with &#8220;data comparison&#8221; rule, but it seems, I can&#8217;t get deep enough in the array to get the correct field. I can dpm this: <code>commerce-line-item:order:commerce-customer-shipping<\/code>, and I see the country code here: <code>-&gt;commerce_customer_address['en'][0]['country']<\/code>, but I don&#8217;t find a way to use it for comparison.<\/p>\n<p>Maybe there is an easy solution with executing custom php code in rules to compare the countries?<\/p>\n<p>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.<\/p>\n<p>Then I checked the database fields for address management and found something strange. In field_data_commerce_customer_address table the language is &#8216;en&#8217;, but in field_data_commerce_customer_billing and -shipping it is &#8216;und&#8217;.<\/p>\n<p>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.<\/p>\n<pre><code>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)\nUndefined 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)\nInvalid 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)\nUndefined 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)\nUndefined 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)\nInvalid 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)\n<\/code><\/pre>\n<p>Can someone help me with that? Did I do some configuration wrong? Is it a module problem?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I installed commerce-kickstart 2.0-rc2 and need to set three shipping rates for different countries. I tried it the &#8220;obvious way&#8221; using flat rates module and rules &#8220;Order address component comparison&#8221;, but it doesn&#8217;t work. I followed the instructions from http:\/\/www.drupalcommerce.org\/node\/2511 but the comparison mostly fails, sometimes not, no idea why. Don&#8217;t know if it&#8217;s an [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2916","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2916","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2916"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2916\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}