Posted on

Magento 1.1.7 Google Checkout and Free Shipping

I have been working with the Magento E-commerce platform and have to say it’s generally pretty slick. I ran into a problem though when trying to get the Google Checkout integration working. The error message in the Google Checkout integration console was:

"We were looking for data in your merchant-calculation-results, but were not
able to find it: result: address-id: XXXXXX"

The problem was that the XML response Magento was sending back had the correct calculations for each shipping method that was available but it didn’t include the shipping methods that were not available for the address. These are required according to the Google Checkout XML API Docs.

For example: if there are two shipping methods: standard and free – where free is only available to UK customers. The customer has 2 potential delivery addresses (One in the UK and one in the US).

The Google request would look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<merchant-calculation-callback
xmlns="http://checkout.google.com/schema/2"
serial-number="9999888-a4d9-98b5-9146-a786865421">
  <shopping-cart>
    <items>
      <item>
        <item-weight value="0.6" unit="LB" />
        <tax-table-selector>none</tax-table-selector>
        <item-name>Special Blue Widget</item-name>
        <item-description></item-description>
        <quantity>1</quantity>
        <unit-price currency="GBP">20</unit-price>
        <merchant-item-id>SBW008</merchant-item-id>
        <merchant-private-item-data>
          <quote-item-id>450</quote-item-id>
        </merchant-private-item-data>
      </item>
    </items>
    <merchant-private-data>
      <quote-id><![CDATA[88]]></quote-id>
    </merchant-private-data>
  </shopping-cart>
  <buyer-id>71862764876424</buyer-id>
  <calculate>
    <addresses>
      <anonymous-address id="769875978986">
        <country-code>US</country-code>
        <postal-code>03801</postal-code>
        <city>Demo City</city>
        <region>NH</region>
      </anonymous-address>
      <anonymous-address id="78648564865986">
        <country-code>GB</country-code>
        <postal-code>SP6 7AJ</postal-code>
        <city>UK Demo Town</city>
        <region>UK</region>
      </anonymous-address>
    </addresses>
    <shipping>
      <method name="Shipping - Free" />
      <method name="Shipping - Standard" />
    </shipping>
    <tax>true</tax>
    <merchant-code-strings />
  </calculate>
  <buyer-language>English</buyer-language>
</merchant-calculation-callback>

Out of the box Magento would send back data for standard shipping for both addresses, free shipping is only included for the UK address.

<?xml version="1.0" encoding="utf-8"?>
<merchant-calculation-results xmlns="http://checkout.google.com/schema/2">
  <results>
    <result shipping-name="Shipping - Standard" address-id="769875978986">
      <shipping-rate currency="GBP">10</shipping-rate>
      <shippable>true</shippable>
      <total-tax currency="GBP">0</total-tax>
    </result>
    <result shipping-name="Shipping - Standard" address-id="78648564865986">
      <shipping-rate currency="GBP">5</shipping-rate>
      <shippable>true</shippable>
      <total-tax currency="GBP">0</total-tax>
    </result>
    <result shipping-name="Shipping - Free" address-id="78648564865986">
      <shipping-rate currency="GBP">0</shipping-rate>
      <shippable>true</shippable>
      <total-tax currency="GBP">0</total-tax>
    </result>
  </results>
</merchant-calculation-results>

The missing element is:

<result shipping-name="Shipping - Free" address-id="78648564865986">
   <shipping-rate currency="GBP">0</shipping-rate>
   <shippable>false</shippable>
 </result>

The fix is in Callback.php around line 216. You need to have an else condition like so:

if (isset($rates[$methodName])) {
    if ($this->getData('root/calculate/tax/VALUE')=='true') {
        $address->setShippingMethod($rateCodes[$methodName]);
 
        $address->setCollectShippingRates(true)->collectTotals();
        $billingAddress->setCollectShippingRates(true)->collectTotals();
        $taxAmount = $address->getTaxAmount();
        $taxAmount += $billingAddress->getTaxAmount();
 
        $result->setTaxDetails($taxAmount);
    }
 
    $result->SetShippingDetails($methodName, $rates[$methodName], "true");
    $merchantCalculations->AddResult($result);
} else {
        $result->SetShippingDetails($methodName, 0, "false");
        $merchantCalculations->AddResult($result);
}

And then you will have the Google Checkout Callbacks working! There is another problem I found with the actual determination of free shipping eligibility. I’ll document the fix for that in my next post.

Edit: This is still an issue in Magento 1.2.1.

2 thoughts on “Magento 1.1.7 Google Checkout and Free Shipping

  1. Hi, I am receiving the following error for my store…

    Merchant Calculations: We were looking for data in your merchant-calculation-results, but were not able to find it: result: address-id:XXXXXXX

    On the surface the problem I seem to have is that Google checkout doesn’t process “per item” shipping. I am using the flat rate method and also an extension via the “merchant calculated” method.

    Any help would be fantastic ! ( I am really struggling)

    Many thanks

    Shane

  2. Hi, Shane
    If you post your XML from the integration console, the parts that say ‘what we sent’ and ‘what you sent back’ (or words to that effect) – obviously you’d want to mask any sensitive info in the xml first! This might allow me to spot what is wrong. Cheers, Ashley

Comments are closed.