0

I currently use the below code in the footer of my Magento store to display the Google Certified Shops badge...

<script type="text/javascript">
    var gts = gts || [];

    gts.push(["id", "12345"]);
    gts.push(["badge_position", "BOTTOM_RIGHT"]);
    gts.push(["locale", "en_GB"]);
    gts.push(["google_base_offer_id", "<?php if (Mage::registry('product')) { echo Mage::registry('current_product')->getId(); } ?>"]);
    gts.push(["google_base_subaccount_id", "123456"]);
    gts.push(["google_base_country", "GB"]);
    gts.push(["google_base_language", "en"]);

    (function() {
        var gts = document.createElement("script");
        gts.type = "text/javascript";
        gts.async = true;
        gts.src = "https://www.googlecommerce.com/trustedstores/api/js";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(gts, s);
    })();
</script>
<!-- END: Google Certified Shops -->

My probelem is with the code

gts.push(["google_base_offer_id", "<?php if (Mage::registry('product')) { echo Mage::registry('current_product')->getId(); } ?>"]);

This piece of code is meant to get the product ID IF the user is on a product page, and it does but only if I clear my sites cache and then load a product page. If I then navigate to another product page the value stays the same and doesn't update. I have tried wrapping the code into an on load function to force it to run again but I still doesn't update each time a new page is loaded.

Any ideas?

2 Answers 2

1

This is the same thing but a bit cleaner

<?php if (Mage::registry('current_product')) : ?>
    gts.push(["google_base_offer_id", "<?php echo Mage::registry('current_product')->getId() ?>"]);
<?php endif; ?>
0

I guess you should use 'current_product' in both the place

gts.push(["google_base_offer_id", "<?php if (Mage::registry('current_product')) { echo Mage::registry('current_product')->getId(); } ?>"]);
1
  • Yep, probably. This still doesn't get updated each time the page is loaded! :(
    – Harry
    Oct 10, 2014 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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