0

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.

1 Answer 1

0

For my case, it was this block

<referenceBlock name=""checkout.cart.shipping"" remove=""true""/>

I removed that line and I overwrote shipping.phtml on my theme to remove the shipping address and to keep the checkoutConfig and the JavaScript

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.