If we edit the quantity of item, it exceeds the available quantity then a message need to display like your quantity exceeds the available quantity. Make customer not able to add more quantity and cannot proceed to checkout, if they add more.
Solution:
I extend the cart item summary view, there i added the functionality. try to get the number of available quantity on that view and try to get the current value on the quantity box . compare it and deactivate the proceed to checkbox button based on that condition. That view i getting the console value of available quantity and current value on the quantity box. I checked everything in local as per requirement displayed a message if the qunatity updated in cart exceeds the available quantity and proceed to checkout option also disabled. . All functionality working fine .
Code For Cart Page Update:
_.extend(CartItemSummaryView.prototype, {
getContext: _.wrap(CartItemSummaryView.prototype.getContext, function (fn) {
try {
var original_Ret = fn.apply(this, _.toArray(arguments).slice(1));
console.log("original_Ret", original_Ret)
var QUANTITY = this.model.attributes.quantity;
var maximumQuantity = this.model.attributes.item.attributes.quantityavailable;
console.log(maximumQuantity, 'this', original_Ret)
if (maximumQuantity === 0 || QUANTITY > maximumQuantity)
original_Ret.maximumQuantity = maximumQuantity
} catch (e) {
console.log('error', e)
}
return original_Ret;
})
});
_.extend(CartSummaryView.prototype, {
events: _.extend({}, CartSummaryView.prototype.events, {
'click [data-action="click-checkout"]': "clickCheckout",
}),
clickCheckout: function (e) {
let checkoutURL = this.model.get('touchpoints').checkout;
console.log(checkoutURL);
window.location.href = checkoutURL;
},
getContext: _.wrap(CartSummaryView.prototype.getContext, function (fn) {
try {
var originalRet = fn.apply(this, _.toArray(arguments).slice(1));
console.log("originalRet", originalRet)
var itemQuantity = this.model.attributes.summary.itemcount;
console.log("itemQuantity", itemQuantity);
var quantityavailable = this.model.attributes.lines.models[0].attributes.item.attributes.quantityavailable;
console.log('quantityavailable', quantityavailable)
if (quantityavailable === 0 || itemQuantity > quantityavailable) {
originalRet.disabled = true;
} else {
originalRet.disabled = false;
}
}
catch (e) {
console.log("issue in cart container", e);
}
return originalRet;
})
});