Scenario: For tracking events(Add to cart, Search terms, Product views, etc) from a test e-commerce website(Opencart), JavaScript function is written in the footer page and these functions are called at button triggers or page loads.
Problem:
While tracking product view event following code is added to Product page, function captureProductView()
is called from footer, and parameters clientid, fname, lname
are retrieved from getClientDetails();
<script>
window.onload=function(){
getClientDetails();
captureProductView('<?php echo $product['product_id']; ?>',
'<?php echo $product['name']; ?>', '<?php echo $product['price']; ?>',
clientid, fname, lname);
};
</script>
But the values from php variables $product['product_id']
, $product['name']
, $product['price']
cannot be parsed to the script tag, leaving Notice:
Notice : Undefined variable: product in /home/path.../product.tpl on line 29"
for all those three variables
I tried assigning these values to javaScript variables, which also did not work.
var p_id = "<?php echo $product['product_id']; ?>";
var p_name = "<?php echo $product['name']; ?>";
Is there a way where I can parse the php variables to the script tag, so that they can be passed as parameters to the function?