0

Having trouble inserting a pretty simple tracking code into each product page.
I am not having any luck pulling the SKU from the product page to populate the product_id (see below).
I am attempting to do so via a widget - which may be causing an issue, though I have inserted code this way before.

<script type="text/javascript">
        var sidecar = sidecar || {};
        sidecar.product_info = {
        product_id: '1234'
        };
    </script>

Any idea on what code to use so '1234' will dynamically populate with our SKU? Also, product id would be an acceptable substitute if, for whatever reason, it's easier to do so.

3
  • You want to get product SKU on product detail page or Magento or somewhere else ? Commented Feb 19, 2018 at 2:54
  • The Product detail page is preferred - thanks!
    – michaelp
    Commented Feb 19, 2018 at 13:41
  • I think the code below will work, now I just can't figure out where to insert it!
    – michaelp
    Commented Feb 22, 2018 at 17:14

1 Answer 1

0

you can use below code to get product Id in Product detail page:

<?php $_product = $this->getProduct(); ?>

<script type="text/javascript">
        var sidecar = sidecar || {};
        sidecar.product_info = {
        product_id: '<?php echo $_product->getId();?>'
        };
    </script>
4
  • Thanks man, still having issues - is there a location on the page it needs to be?
    – michaelp
    Commented Feb 19, 2018 at 19:07
  • It can be place anywhere in the page. Currently on product detail page how the product name is showing? Please share that code. Also is that the default Magento's product detail page or its your custom page? Commented Feb 20, 2018 at 1:20
  • I'm thinking it might be related to using a static block and widget to insert the code.
    – michaelp
    Commented Feb 21, 2018 at 21:58
  • Had to add to the bottom of view.phtml in catalog/product
    – michaelp
    Commented Feb 22, 2018 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.