0

I am trying to get jquery to work in the list.phtml file . I have jquery working on the product detail page within a this same jquery require tag. However when I put it on the list.phtml file it makes the entire page load all misaligned and full of other issues in the console I am presented with a require not defined error?

Here is the code I am trying to use.

<script>
   require(['jquery'], function ($) 
   {
       $(".tocart").click(function()
       {
          dataLayer.push({
                          'event': 'addToCart',
                          'ecommerce': {
                          'currencyCode': 'USD',
                          'add': {
                                   'products': [{
                                   'name': "<?php echo "$google_item_name $google_item_name_2 $google_item_name_3";?>",     // Name or ID is required
                                   'id': '<?php echo "$google_sku";?>',                      // Name or ID is required
                                   'price': '<?php echo "$google_price";?>',                // Insert product price
                                   'brand': '<?php echo "google_site_owned_by_name";?>',                // Insert product brand
                                   'category': '<?php echo "$category_name";?>',          // Insert product category
                                   'quantity': '1',           // Insert product quantity
                                   'site': '<?php echo "$google_sitebeing_viewed";?>'   // Insert site that product belongs to (e.g. site1, site2, site3)
                                    }]
                                  }
                            }
                         });
           });

       });
 </script>
  • 1
    Can you paste your code? – BartZalas May 17 at 22:58
  • Paste your entire list.phtml code such that it will be easy find the issue – aravind May 20 at 12:32
  • I am limited to 30000 characters and the magento2 list.phtml file is longer then that. However i have the file saved as a text file so it can be viewed here bit.ly/2VQSGN2 – Jayreis May 20 at 12:48

Your Answer

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

Browse other questions tagged or ask your own question.