Prestashop Facebook 像素购买集成

Prestashop Facebook Pixel Purchase Integration

我试图更改我的订单-confirmation.tpl,在显示一些错误之后,我正在尝试添加 Facebook 像素代码来跟踪订单。

我的改动是

我加OrderConfirmationController.php

        $cart = new Cart((int)($this->id_cart));
    self::$smarty->assign(array(
        '_order' => $this->id_order,
        '_value' => $cart->getOrderTotal()
    ));

之后我添加我的订单-confirmation.tpl

 <!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','//connect.facebook.net/en_US/fbevents.js');

fbq('init', 'xxxxxxxxxxxxxx');
fbq('track', "PageView");
fbq('track', 'Purchase', {value: {$_value}, currency: 'USD'}); 
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=1445570592421898&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->

如您所见,我正在尝试使用 $_value

获取价值

错误是

   Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "/var/www/presta/themes/mytheme/order-confirmation.tpl" on line 43 
"!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?" - Unexpected ".", expected one of: "","" , ")" <-- thrown in 
/var/www/presta/tools/smarty/sysplugins/smarty_internal_templatecompilerbase.php on line 43

谢谢

我通过更改该部分解决了这个问题,也许有一天有人需要 facebook Pixel 的东西:)

关于订单-confirmation.tpl需要添加{文字}因为聪明

 !-- Facebook Pixel Code -->
<script>
{literal}
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','//connect.facebook.net/en_US/fbevents.js');

fbq('init', '1445570592421898');
fbq('track', "PageView");
fbq('track', 'Purchase', {value: {/literal}'{$_value}'{literal}, currency: 'USD'});  
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=1445570592421898&ev=PageView&noscript=1"
/></noscript>{/literal}
<!-- End Facebook Pixel Code -->

在 Smarty 模板中,{ 和 } 大括号只要被白色包围就会被忽略 space。

所以只需在每个大括号前后插入一个白色的space:

<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s) { if(f.fbq)return;n=f.fbq=function() { n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments) } ;if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s) } (window,
document,'script','//connect.facebook.net/en_US/fbevents.js');

fbq('init', '0123456789012345');
fbq('track', "PageView");</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=0123456789012345&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->