Reputation: 489
I was try to change my order-confirmation.tpl and after that showing few error i'm trying adding facebook pixel code to track orders.
My changes are
I add on OrderConfirmationController.php
$cart = new Cart((int)($this->id_cart));
self::$smarty->assign(array(
'_order' => $this->id_order,
'_value' => $cart->getOrderTotal()
));
After that i add my order-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 -->
As you see i'm trying to getting value with $_value
Error is
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
Thank You
Upvotes: 2
Views: 3322
Reputation: 41
In Smarty templates, the { and } braces will be ignored so long as they are surrounded by white space.
So just insert a white space before and after each brace:
<!-- 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 -->
Upvotes: 4
Reputation: 489
I Fix it that problem with changing that part maybe someone need one day that facebook Pixel things :)
About order-confirmation.tpl need adding {literal} because of smarty
!-- 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 -->
Upvotes: 10