I made an add to wishlist with ajax module and I want to indicate if the product is already in wishlist without breaking the full page cache. I know the wishlist object is in customer-data
but I can't get the Items from that object. Can you help me with some pointers?
js file code
define([
'jquery',
'Magento_Customer/js/customer-data',
'Magento_Customer/js/model/customer',
'jquery/ui'
], function ($, customerData, customer) {
'use strict';
$.widget('test.wishlistChecker', {
wishlistClass: 'in-wishlist',
/** @inheritdoc */
_create: function () {
console.log('test checker');
this.checkWishlistItems();
},
/**
* Check customer wishlist
*/
checkWishlistItems: function () {
var wishlistItems = customerData.get('wishlist')['items'];
console.log(wishlistItems);
}
});
$(document).wishlistChecker();
return $.test.wishlistChecker;
});