Magento – Passing sku code value to TrustPilot product review

magento-1.9sku

hope someone can help.

I'm trying to set up a 3rd party review platform (TrustPilot) for our Magento 1.9 CE store, using Ultimo theme. There is a product review box which will display individual product reviews on product pages. The code to display this box looks pretty simple, but it requires us to add the variable for the product sku and product name.

Here's the code (I've added in capitals where the two bits of data need to go);

<!-- TrustBox widget --> <div class="trustpilot-widget" data-locale="en-GB" data-template-id="5717796816f630043868e2e8" data-businessunit-id="51cd30a800006400054f735a" data-style-height="700px" data-style-width="100%" data-theme="light" data-sku="MY SKU CODE GOES HERE" data-name="MY PRODUCT NAME GOES HERE"> <a href="https://uk.trustpilot.com/review/valueincontinence.co.uk" target="_blank">Trustpilot</a> </div> <!-- End TrustBox widget -->    

This code works fine if I hard code in the actual SKU (i.e. H12345). I was expecting to be able to replace the 'MY SKU CODE GOES HERE' with something like;

<?php echo $_product->getData('sku') ?>

…but that doesn't work.

I first tried this from the admin backend CMS in a custom block/tab – if I hard code sku, it works fine, if I try anything else, the code still works, but doesn't show any of the product related reviews/details which is should (i.e. it just looks like the product has no reviews).

I thought this might be something to do with custom blocks needing something else, so I tried it just on the main product description page (i.e. not in a custom block/tab) but still no joy.

I also tried creating a phtml file seperately, but couldn't get that to work either. Have looked through lots of posts about calling variables in other scenarios, here and elsewhere, but still no joy.

I'd really appreciate any suggestions.
Many thanks,
Bill

Best Answer

I had trouble with this also for the product pages so made the following code to get the sku and name to fill in the gaps for data-sku and data-name in the Trustbox dynamically for each product page. It works on products pages not sure if will work for catalog and search results.

<?php
$current_product = Mage::registry('current_product');
if($current_product) {
    $_sku = $current_product->getSku();
    $_name = $current_product->getName();
   }
?>
<!-- TrustBox widget - Product Reviews MultiSource SEO -->
<div class="trustpilot-widget" data-locale="en-GB" data-template-id="XXXXXXXXXXXX" data-businessunit-id="XXXXXXXXXXXX" data-sku="<?php echo $_sku?>" data-name="<?php echo $_name ?>">
<a href="https://trustpilot.com/review/YOURDOMAIN" target="_blank" rel="noopener">Trustpilot</a>
</div>
<!-- End TrustBox widget -->
Related Topic