rubendivall

Survey opt-in for Google Merchant Center Prestashop 1.7

May 2nd, 2019
1,442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Smarty 2.12 KB | None | 0 0
  1. {* Integrate the survey opt-in module Google Merchant Center for Prestashop 1.7
  2. *
  3. * STEP 1
  4. * Add this code in your tpl file in themes/YOUR_THEME/templates/checkout/order-confirmation.tpl inside the block page_content_container -> {block name='page_content_container'}
  5. *
  6. * STEP 2
  7. * Define your google Merchant ID in  {assign var="merchant_id" value="YOUR_ID"}
  8. * Define how many days your order will be deliveried {assign var="estimated_delivery_days" value="NUMBER_OF_DAYS"}
  9. *
  10. *
  11. * by Ruben Divall @rubendivall http://www.rubendivall.com
  12. * https://support.google.com/merchants/answer/7106244?hl=en&ref_topic=7105160
  13. *}
  14. {block name='conversion_pixel'}
  15.   {assign var="estimated_delivery_days" value="NUMBER_OF_DAYS"}
  16.   {assign var="merchant_id" value="YOUR_ID"}
  17.   <!-- BEGIN GCR Opt-in Module Code -->
  18.   {if !empty($merchant_id) && !empty($order.details.id) && !empty(Country::getIsoById($order.addresses.delivery.id_country))}
  19.     <script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer></script>
  20.     <script>
  21.       window.renderOptIn = function() {
  22.         window.gapi.load('surveyoptin', function() {
  23.           window.gapi.surveyoptin.render(
  24.             {
  25.               // REQUIRED
  26.               "merchant_id": {$merchant_id},
  27.               "order_id": "{$order.details.id}",
  28.               "email": "{$customer.email}",
  29.               "delivery_country": "{Country::getIsoById($order.addresses.delivery.id_country)|upper}",
  30.               "estimated_delivery_date": "{"+$estimated_delivery_days days"|date_format:"%Y-%m-%d"}",
  31.               "opt_in_style": "CENTER_DIALOG",
  32.               // OPTIONAL FIELDS
  33.               "products": [
  34.                 {foreach $order.products as $item_product}
  35.                   {
  36.                     "gtin": "{if !empty({$item_product.product_ean13})}{$item_product.product_ean13}{/if}"
  37.                   } {if !$item_product@last},{/if}
  38.                 {/foreach}
  39.               ]
  40.  
  41.             });
  42.          });
  43.       }
  44.     </script>
  45.     <script>
  46.       window.___gcfg = {
  47.         lang: "{$language.iso_code|lower}"
  48.       };
  49.     </script>
  50.   {/if}
  51. {/block}
Add Comment
Please, Sign In to add comment