【问题标题】:Add Google trust badge to Magento将 Google 信任徽章添加到 Magento
【发布时间】:2012-06-07 20:45:01
【问题描述】:

我正在尝试将 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 -->

【问题讨论】:

  • 那么,您可以向 Google 提供有关您客户的更多信息吗? (我知道,有点跑题了,但要考虑一下……)
  • 嗨@Paul 我很抱歉,但我不应该把那个代码放上去?我只是想做更多的生意。不过,我担心我的客户隐私。我认为 Google 不会滥用它。
  • “我不认为谷歌会滥用它” - 滥用是一个如此主观的词! :)

标签: php magento google-trusted-stores


【解决方案1】:

Implementing Google Trusted Stores:#3 Add the JavaScript to Your Site:

Google 实际上希望您将第一部分放在您网站的每个页面上。无需在模板文件中执行此操作,您可以将其添加到 System > Configuration > General > Design 中的 Footer > Miscellaneous HTML。我删除了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 -->

其余代码只需在Checkout Success页面上(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 -->

【讨论】:

  • 实际上,Google 希望获得客户的收货地址,而不是帐单地址,因为他们有兴趣跟踪您是否正确发货。显然我无法编辑你的帖子,但你可能想要。
  • 两年多后仍在为 Magento 工作!谢谢@nachito。我发现的唯一问题是您的 sn-p 不允许访客电子邮件。 $email = $customer-&gt;getData('email'); $email_address2 = $address-&gt;getEmail(); if($email=="") $email = $email_address2;
【解决方案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-sn-p,而无需在模板中实现它。

【讨论】:

  • 这实际上应该在结帐成功页面上,它在结帐页面上没有用,$cart-&gt;getItemsCount()返回购物车中的商品数量,而不是数量订购的物品,正如gts-i-quantity 应该的那样。
  • 我对上面的谷歌代码一无所知。所以我不知道它放在哪里最好,$cart-&gt;getItemsCount() 也只是一个例子。
  • 嗨@feeela,我给谷歌写了一封电子邮件,他们告诉我第一个代码将进入页脚,另一个代码将进入成功页面。
【解决方案3】:

代码肯定需要在应用文件夹(app/design/frontend/yourtheme/template/checkout/success.phtml)中的结帐成功页面上。我在这里找到了magento badge implementation 的答案,但就像几个答案表明它是重要的逻辑一样,并且根据您正在运行的扩展和自定义开发,每个商店通常都不同。

    <!– 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 –>

【讨论】:

    【解决方案4】:

    此后谷歌自己发布了一个 Magento 扩展:http://www.magentocommerce.com/magento-connect/google-trusted-stores-3308.html

    【讨论】:

    • 请注意,此扩展程序不是您所希望的,并且尚未保持最新状态。谷歌最近修改了他们的集成方式(不再依赖于提要)——这个扩展仍然有效,但尚未更新,并使用可能会被逐步淘汰的旧 .js api。
    猜你喜欢
    • 2012-03-06
    • 1970-01-01
    • 2010-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 2019-08-31
    • 1970-01-01
    相关资源
    最近更新 更多