Remove out of stock items from cart

The REquirement is to remove out of stock items from cart. We have an option in the frontend API. Adding the code below.

 var cart= container.getComponent("Cart");
                var removed = 0;
                console.log("Cart",cart)
                _.extend(OrderWizardModuleCartItemsShip.prototype, {
                    getContext: _.wrap(OrderWizardModuleCartItemsShip.prototype.getContext, function (fn) {
                    var context = fn.apply(this, _.toArray(arguments).slice(1)); 
                    setTimeout(function(){	                        
                        _.each(this.lines, function (pagelines) {
                            console.log("pagelines each",pagelines)
                            if(pagelines.get("item").get("quantityavailable")==0){
                                console.log("inside of 0 OrderWizardModuleCartItemsShip",pagelines.get("internalid"))
                                var liveordermod=LiveOrderModel.getInstance();
                                console.log("liveordermod OrderWizardModuleCartItemsShip",liveordermod)   
                                _.each(liveordermod.attributes.lines.models, function (outstckitemss) {
                                    console.log("liveordermod each OrderWizardModuleCartItemsShip",outstckitemss)
                                if(outstckitemss.get("item").get("quantityavailable")==0){
                                    console.log("inside of 0 cart OrderWizardModuleCartItemsShip",outstckitemss.get("internalid"))
                                    cart.removeLine({
                                        line_id: outstckitemss.get("internalid")									
                                    }).then(function() {
                                        removed++;
                                        console.log("All out of stock lines removed successfully")
                                    });																			
                                }
                            })	  																
                            }
                        })	
                    }, 200);
                                 console.log("context OrderWizardModuleCartItemsShip dilse",context)
                                 console.log("this of OrderWizardModuleCartItemsShip dilse",this)
                                 return context
                         })
                    });

Leave a comment

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