How to prevent a customer from navigation to checkout from cart when they enter invalid state and zip code in shipping cost estimate section

We can restrict customers from navigating to checkout while entering invalid country and zipcode in cart’s estimate shipping section using this solution.

JavaScript:

In here, respBody will contain the result of whether the zip code and country are valid or invalid

//CartSummaryView model is extending for preventing from navigaing to checkout in case of bad response in shipping cost.
      _.extend(CartSummaryView.prototype, {
        getContext: _.wrap(CartSummaryView.prototype.getContext, function (fn) {
          let original = fn.apply(this, _.toArray(arguments).slice(1));
					let response = this.model.get("respBody");
					original.showActions = response && response.success && original.showActions ? true : false;
          return original;
        }),
      });
      //CartDetailedView model is extending for preventing from navigaing to checkout in case of bad response in shipping cost for mobail devices.
      _.extend(CartDetailedView.prototype, {
        template: jj_cart_detailed_tpl,
        getContext: _.wrap(CartDetailedView.prototype.getContext, function (fn) {
          let original = fn.apply(this, _.toArray(arguments).slice(1));
          let response = this.model.get("respBody");
          original.showActions = response && response.success ? true : false;
          return original;
        })
      });

Leave a comment

Your email address will not be published. Required fields are marked *