I am trying to alert the user that they have not added a postcode into their session when clicking "Add to cart"
I have created a mixin, "catalog-add-to-cart-mixin.js" within my custom module.
The issue that I am having is the variable "quote" is undefined
.
How can I pass through the Magento_Checkout/js/model/quote
shipping address to the submitForm
function to be able to see if there is a postcode or not?
Here is my code:
define([
'jquery',
'mage/translate',
'jquery/ui',
'Magento_Checkout/js/model/quote',
'Magento_Ui/js/modal/modal'
], function($, $t, ui, quote, modal) {
"use strict";
return function (widget) {
$.widget('mage.catalogAddToCart', widget, {
submitForm: function (quote, form) {
alert("there");
var postcode = quote.shippingAddress().postcode;
console.log(postcode);
debugger;
if(!quote.shippingAddress()) {
this.showModal(form);
} else {
this.ajaxSubmit(form);
}
},
showModal: function(form) {
console.log('show modal');
$('#shipping-popup-modal').modal('openModal');
}
});
return $.mage.catalogAddToCart;
}
});
I am open to options.