Posted on

Magento 2 js library(Magento_Customer/js/customer-data) how to get custom product attributes in js

I’ve a little problem with an override of google tag manager in Magento 2 enterprise.

google-analytics-universals.js have some function that trigger the events: addToCart, removeFromCart.

To get the products details in addtocart function google tag manager(google-analytics-universals.js) use:

‘Magento_Customer/js/customer-data’

with the method:

items = customerData.get(‘cart’)().items;

Unfortunately this method don’t retrieve product custom-attribute.

The question is: which is the best way to retrieve the custom attributes?

The js of google tag manager and the customer-data.js seems to haven’t a phtml associated that I can use and however I have to get custom attributes only of the product triggered by addtocart event in js.

Any idea?

Leave a Reply

Your email address will not be published.