我正在尝试将Google Trust Badge添加到我的magento商店。我试图在Magento网站上搜索扩展程序,但我找不到一个。我是否需要将以下代码粘贴到产品和结帐页面,或者我必须对其进行更改?如果有人能引导我走向正确的方向,我将非常感激。
<!-- BEGIN: Google Trusted Store -->
<script type="text/javascript">
var gts = gts || [];
gts.push(["id", "54785"]);
gts.push(["google_base_offer_id", "ITEM_PRODUCT_SEARCH_ID"]);
gts.push(["google_base_subaccount_id", "ITEM_PRODUCT_SEARCH_ACCOUNT_ID"]);
gts.push(["google_base_country", "ITEM_PRODUCT_SEARCH_COUNTRY"]);
gts.push(["google_base_language", "ITEM_PRODUCT_SEARCH_LANGUAGE"]);
(function() {
var scheme = (("https:" == document.location.protocol) ? "https://" : "http://");
var gts = document.createElement("script");
gts.type = "text/javascript";
gts.async = true;
gts.src = scheme + "www.googlecommerce.com/trustedstores/gtmp_compiled.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(gts, s);
})();
</script>
<!-- END: Google Trusted Store -->
<!-- START Trusted Stores Order -->
<div id="gts-order" style="display:none;">
<!-- start order and merchant information -->
<span id="gts-o-id">MERCHANT_ORDER_ID</span>
<span id="gts-o-domain">MERCHANT_ORDER_DOMAIN</span>
<span id="gts-o-email">CUSTOMER_EMAIL</span>
<span id="gts-o-country">CUSTOMER_COUNTRY</span>
<span id="gts-o-currency">CURRENCY</span>
<span id="gts-o-total">ORDER_TOTAL</span>
<span id="gts-o-discounts">ORDER_DISCOUNTS</span>
<span id="gts-o-shipping-total">ORDER_SHIPPING</span>
<span id="gts-o-tax-total">ORDER_TAX</span>
<span id="gts-o-est-ship-date">ORDER_EST_SHIP_DATE</span>
<span id="gts-o-has-preorder">HAS_BACKORDER_PREORDER</span>
<span id="gts-o-has-digital">HAS_DIGITAL_GOODS</span>
<!-- end order and merchant information -->
<!-- start repeated item specific information -->
<!-- item example: this area repeated for each item in the order -->
<span class="gts-item">
<span class="gts-i-name">ITEM_NAME</span>
<span class="gts-i-price">ITEM_PRICE</span>
<span class="gts-i-quantity">ITEM_QUANTITY</span>
<span class="gts-i-prodsearch-id">ITEM_PRODUCT_SEARCH_ID</span>
<span class="gts-i-prodsearch-store-id">ITEM_PRODUCT_SEARCH_ACCOUNT_ID</span>
<span class="gts-i-prodsearch-country">ITEM_PRODUCT_SEARCH_COUNTRY</span>
<span class="gts-i-prodsearch-language">ITEM_PRODUCT_SEARCH_LANGUAGE</span>
</span>
<!-- end item 1 example -->
<!-- end repeated item specific information -->
</div>
<!-- END Trusted Stores -->
答案 0 :(得分:6)
Implementing Google Trusted Stores:#3 Add the JavaScript to Your Site:
Google实际上希望您将第一部分放在您网站的每个页面上。而不是在模板文件中执行此操作,您可以将其添加到页脚&gt;系统中的杂项HTML&gt;配置&gt;一般&gt;设计。我已移除ITEM_PRODUCT_SEARCH_ID
和ITEM_PRODUCT_SEARCH_ACCOUNT_ID
,但您可以随意编辑产品页面以添加此数据。这是代码:
<!-- BEGIN: Google Trusted Store -->
<script type="text/javascript">
var gts = gts || [];
gts.push(["id", "54785"]);
gts.push(["google_base_country", "US"]);
gts.push(["google_base_language", "en"]);
(function() {
var scheme = (("https:" == document.location.protocol) ? "https://" : "http://");
var gts = document.createElement("script");
gts.type = "text/javascript";
gts.async = true;
gts.src = scheme + "www.googlecommerce.com/trustedstores/gtmp_compiled.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(gts, s);
})();
</script>
<!-- END: Google Trusted Store -->
其余代码只需要位于结帐成功页面(app / design / frontend / {your} / {theme} /template/checkout/success.phtml)。我们需要加载订单以获取客户的电子邮件,国家/地区和订单数据。您需要实施逻辑以确定是否有任何商品延期交货,是否有任何商品是下载商品,以及商品何时发货。在该文件中的任何位置添加:
<?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
?>
<!-- START Trusted Stores Order -->
<div id="gts-order" style="display:none;">
<!-- start order and merchant information -->
<span id="gts-o-id"><?php echo $orderId; ?></span>
<span id="gts-o-domain">{www.yourstore.com}</span>
<span id="gts-o-email"><?php echo htmlentities($customer->getEmail()); ?></span>
<span id="gts-o-country"><?php echo htmlentities($address->getCountryId()); ?></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-has-preorder"><?php echo $backorder ? 'Y' : 'N'; ?></span>
<span id="gts-o-has-digital"><?php echo $download ? 'Y' : 'N'; ?></span>
<!-- end order and merchant information -->
<!-- start repeated item specific information -->
<?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-country">US</span>
<span class="gts-i-prodsearch-language">en</span>
</span>
<?php endforeach; ?>
<!-- end repeated item specific information -->
</div>
<!-- END Trusted Stores -->
答案 1 :(得分:2)
您可以在app/design/frontend/default/USED_TEMPLATE/template/checkout/onepage.phtml
的底部插入该代码,以使其显示在最终的结帐页面上。
您需要使用Magento函数填充变量并输出它们。例如:
// Magento .phtml-style
<?php $cart = Mage::getSingleton( 'checkout/cart' ); ?>
<span class="gts-i-quantity"><?php echo $cart->getItemsCount(); ?></span>`
或者你可以走很长的路,在自己的扩展程序中使用Magento钩子在任何地方展示Google-snippet,而无需在模板中实现它。
答案 2 :(得分:2)
代码肯定需要在app文件夹中的checkout成功页面上(app / design / frontend / yourtheme /template/checkout/success.phtml)。我在magento badge implementation找到了我的答案,但就像几个答案所说的那样,LOGIC很重要,而且每个商店通常都有所不同,具体取决于你所运行的扩展和自定义开发。
<!– START Google Trusted Stores Order –>
<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”>[INSERT URL (www.example.com)]</span>
<span id=”gts-o-email”><?php echo htmlentities($customer->getEmail()); ?></span>
<span id=”gts-o-country”><?php echo htmlentities($address->getCountryId()); ?></span>
<span id=”gts-o-currency”>[USD]</span>
<span id=”gts-o-total”><?php echo round_and_kep($order->getGrandTotal()); ?></span>
<span id=”gts-o-discounts”>[CALL IT OUT WITH CODE – use 0 if no discounts]</span>
<span id=”gts-o-shipping-total”><?php echo round_and_kep($order->getShippingAmount()); ?></span>
<span id=”gts-o-tax-total”><?php echo round_and_kep($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”><?php echo $shipDate->toString(‘yyyy-MM-dd’); ?></span>
<span id=”gts-o-has-preorder”><?php echo $backorder ? ‘Y’ : ‘N'; ?></span>
<span id=”gts-o-has-digital”><?php echo $download ? ‘Y’ : ‘N'; ?></span>
<!– end order and merchant information –>
<!– start repeated item specific information –>
<!– item example: this area repeated for each item in the order –>
<span class=”gts-item”>
<span class=”gts-i-name”><?php echo htmlentities($item->getName()); ?></span>
<span class=”gts-i-price”><?php echo round_and_kep($item->getBasePrice()); ?></span>
<span class=”gts-i-quantity”><?php echo (int)$item->getQtyOrdered(); ?></span>
<span class=”gts-i-prodsearch-id”>[ITEM_GOOGLE_SHOPPING_ID]</span>
<span class=”gts-i-prodsearch-store-id”>[YOUR STORE ID GIVEN TO YOU BY GOOGLE]</span>
<span class=”gts-i-prodsearch-country”>US</span>
<span class=”gts-i-prodsearch-language”>en</span>
</span>
<!– end item 1 example –>
<!– end repeated item specific information –>
</div>
<!– END Google Trusted Stores Order –>
答案 3 :(得分:1)
此后,Google自己发布了Magento扩展程序:http://www.magentocommerce.com/magento-connect/google-trusted-stores-3308.html