I am trying to get some more product data in the add-to-cart event (using ajax). So far, I can see the form works like this:

$(document).on('ajax:addToCart', function (event, data) {

I can see that there is some information in the "data" object already:

Object { sku: 8215, productIds: (1) […], form: {…}, response: [] }
form: Object { 0: form, context: form
, length: 1, … }
productIds: Array [ "15" ]
response: Array []
sku: 8215

The sku f.e. is now accessible in a script like this:

var sku = data.sku;

But I also need to know the price, the name and if possible the URL of the product I just added to the cart. How can I add this information to the add-to-cart functionality so it contains this kind of information?

Something like

<?php $product->getName() ?> 

but how does it work via php object?

1 Answer 1


It's just basic javascript you can extend any object; so

let price = "XXX";
data.price = price;

If your question is more about how to get the value of price name and url of the product, then you just have to get them from the php object.

Doing something like

let name = "<?php echo $product->getName(); ?>";
  • The question is indeed how to get the values (via php object) since I have no clue where to check for $product. On a product page, I know where to get it. But the add-to-cart function can be on a number of pages with different products. So somehow, the whole add-to-cart ajax setup has to be enhanced.
    – TheFrakes
    Commented Jan 30, 2023 at 8:28

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.