I’m trying to get the product-sku (and name) of a product, whenever a customer adds or removes it from his cart or changes the quantity of that product.
I was able to come up with the following for adding products to cart:
define([
'jquery'
], function ($) {
'use strict';
return function (widget) {
$.widget('mage.catalogAddToCart', widget, {
_create: function () {
console.log("CREATE WIDGET")
$(document).on('ajax:addToCart', function (event, data) {
console.log("ADD TO CART")
console.log(data['sku']);
console.log(event);
});
$(document).on('ajax:removeFromCart', function (event, data) {
console.log("REMOVE FROM CART")
console.log(data['sku']);
console.log(event);
});
}
});
return $.mage.catalogAddToCart;
}
});
This at least gives me a products Sku. I suppose I can fetch the product-name with that.
However it does not work for the remove event. And I have no idea how to go about the event for changing the quantity.