0

I have the following script which i need to add the product brand/manufacturer and SKU

<script>
    window.addEventListener('liveload', function() {
        IcecatLive.getDatasheet(
            {           
                'reasonstobuy':'#Container5',
            }, 
            {
            Brand: **$manufacturer**,
            PartCode: **$sku**,
            UserName: 'myusername'
        }, 'en')               
    });
</script>

I have added custom.phtml in web/magento/app/design/frontend/MyTemplate/default/Magento_Catalog/templates/product/view

which contains

<?php $_product = $this->getProduct(); 
/* YOU CAN GET ANY PRODUCT ATTRIBUTE HERE. */
echo $_product->getAttributeText('manufacturer') 
echo $_product->getSku(); 
?>

I can display the manufacturer and sku in a block on the front end but cant pass the attributes into the above script, how can i pass the php output manufacturer/sku to the javascript?

1 Answer 1

0

Managed to figure this out 30 mins after posting!

<?php $_product = $this->getProduct(); 
    /* YOU CAN GET ANY PRODUCT ATTRIBUTE HERE. */
    $mpn = $_product->getAttributeText('manufacturer');
    $partcode = $_product->getSku(); 
?>

<script>
    window.addEventListener('liveload', function() {
        IcecatLive.getDatasheet(
            {           
                'reasonstobuy':'#Container5',
            }, 
            {
            Brand:  <?php echo $mpn; ?>;
            PartCode: <?php echo $partcode; ?>;
            UserName: 'myusername'
        }, 'en')               
    });
</script>

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.