Reputation: 29
I'm trying to complete the Google Trusted Store integration in my Magento 1.9 CE website. I've currently got the badge properly implemented and passing all tests. What I'm having trouble with is the confirmation script dollar amounts. I'm getting errors that the format is wrong and from error to error the format is inconsistent. I've tried a couple of different php snippets to pull dollar amounts from different places (overly complicated theme) but nothing seems to work. Has anyone encountered this before?
Critical Error 1: Incorrect number format: “gts-o-tax-total” How to Fix: Follow the required format when providing the total taxes associated with the order in the “gts-o-shipping-total” field of the Google Trusted Stores Order Confirmation JavaScript code. Required format: “123.45” Your value: “1.6500”.
Critical Error 2: Incorrect value format: “gts-i-price” How to Fix: Follow the required format when providing the item price associated with the order in the “gts-i-price” field of the Google Trusted Stores Order Confirmation JavaScript code. Required format: “123.45” Your value: “19.9900,0.0000”.
Most errors show as the first with only 2 extra places behind the decimal. "gts-i-price" is something I can't understand.
Here's the code I have in my success.phtml page. I found this on SE after trying a few other scripts:
<?php
$orderId = $this->getOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
$address = $order->getShippingAddress();
$backorder = false; // some backorder logic
$download = false; // some download logic
$shipDate = new Zend_Date(); // some logic to determine ship date
?>
<div id="gts-order" style="display:none;" translate="no">
<!-- start order and merchant information -->
<span id="gts-o-id"><?php echo $orderId; ?></span>
<span id="gts-o-domain">www.mywebsite.com</span>
<span id="gts-o-email"><?php echo $email = $customer->getData('email'); $email_address2 = $address->getEmail(); if($email=="") $email = $email_address2; ?></span>
<span id="gts-o-country">US</span>
<span id="gts-o-currency">USD</span>
<span id="gts-o-total"><?php echo $order->getGrandTotal(); ?></span>
<span id="gts-o-discounts">-<?php echo $order->getDiscountAmount(); ?></span>
<span id="gts-o-shipping-total"><?php echo $order->getShippingAmount(); ?></span>
<span id="gts-o-tax-total"><?php echo $order->getTaxAmount(); ?></span>
<span id="gts-o-est-ship-date"><?php echo $shipDate->toString('yyyy-MM-dd'); ?></span>
<span id="gts-o-est-delivery-date">ORDER_EST_DELIVERY_DATE</span>
<span id="gts-o-has-preorder">N</span>
<span id="gts-o-has-digital">N</span>
<!-- end order and merchant information -->
<!-- start repeated item specific information -->
<!-- item example: this area repeated for each item in the order -->
<?php foreach ($order->getAllItems() as $item): ?>
<span class="gts-item">
<span class="gts-i-name"><?php echo htmlentities($item->getName()); ?></span>
<span class="gts-i-price"><?php echo $item->getBasePrice(); ?></span>
<span class="gts-i-quantity"><?php echo (int)$item->getQtyOrdered(); ?></span>
<span class="gts-i-prodsearch-id">SKU</span>
<span class="gts-i-prodsearch-store-id">000000</span>
<span class="gts-i-prodsearch-country">US</span>
<span class="gts-i-prodsearch-language">en</span>
</span>
<?php endforeach; ?>
</div>
Upvotes: 0
Views: 488
Reputation: 31
Not sure if I could help but I'm also trying to get this work. I have contacted Google and they send me this snippet specifically for Magento:
<?php
// Obtain order variables with Magento functions
$orderId = $this->getOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
$address = $order->getShippingAddress();
?>
<!-- START Google Trusted Stores Order -->
<div id="Google Trusted Stores-order" style="display:none;" translate=”no”>
<!-- start order and merchant information -->
<span id="Google Trusted Stores-o-id"> <?php echo $orderId; ?> </span>
<span id="Google Trusted Stores-o-domain"> MERCHANT_ORDER_DOMAIN </span>
<span id="Google Trusted Stores-o-email"> <?php echo
htmlentities($customer->getEmail()); ?> </span>
<span id="Google Trusted Stores-o-country"> <?php echo
htmlentities($address->getCountryId()); ?> </span>
<span id="Google Trusted Stores-o-currency"> CURRENCY </span>
<span id="Google Trusted Stores-o-total"> <?php echo $order->getGrandTotal(); ?> </span>
<span id="Google Trusted Stores-o-discounts"> -<?php echo $order->getDiscountAmount();
?> </span>
<span id="Google Trusted Stores-o-shipping-total"> <?php echo
$order->getShippingAmount(); ?> </span>
<span id="Google Trusted Stores-o-tax-total"> <?php echo $order->getTaxAmount();
?> </span>
<span id="Google Trusted Stores-o-est-ship-date"> ORDER_EST_SHIP_DATE </span>
<span id="Google Trusted Stores-o-est-delivery-date"> ORDER_EST_DELIVERY_DATE </span>
<span id="Google Trusted Stores-o-has-preorder"> HAS_BACKORDER_PREORDER </span>
<span id="Google Trusted Stores-o-has-digital"> HAS_DIGITAL_GOODS </span>
<!-- end order and merchant information -->
<!-- start repeated item specific information -->
<?php foreach ($order->getAllItems() as $item): ?>
<span class="Google Trusted Stores-item">
<span class="Google Trusted Stores-i-name"> <?php echo htmlentities($item->getName());
?> </span>
<span class="Google Trusted Stores-i-price"> <?php echo $item->getBasePrice(); ?> </span>
<span class="Google Trusted Stores-i-quantity"> <?php echo (int)$item->getQtyOrdered();
?> </span>
</span>
<?php endforeach; ?>
<!-- end repeated item specific information -->
</div>
<!-- END Trusted Stores -->
Also he said:
All of the below variables are required in order for the OCM code to trigger. Please refer to the Order level variables here.
<span id="Google Trusted Stores-o-est-ship-date">ORDER_EST_SHIP_DATE</span>
<span id="Google Trusted Stores-o-est-delivery-date">ORDER_EST_DELIVERY_DATE</span>
<span id="Google Trusted Stores-o-has-preorder"> HAS_BACKORDER_PREORDER </span>
<span id="Google Trusted Stores-o-has-digital"> HAS_DIGITAL_GOODS </span>
I changed the variables as required but for me, I don't even get the error messages just like you got for OCM, so I wouldn't know if these are the right code but may be for someone else.
I'm sure you've already come across all these informations but I also need an answer, too.
Upvotes: 0