Adding the stock message in cart page

we can add the stock message by extending the view 

_.extend(CartLinesView.prototype, {

template: jj_cart_lines_tpl,

getContext: _.wrap(CartLinesView.prototype.getContext, function (fn) {

var originalStock = fn.apply(this, _.toArray(arguments).slice(1));

var inStockMessage = originalStock.item.attributes._inStockMessage;

var outofStockMessage = originalStock.item.attributes.outofstockmessage;

var availableQuan=this.model.attributes.item.attributes.quantityavailable;

if(availableQuan !==0){

originalStock.inStockMessage = inStockMessage;

}

else{

originalStock.outofStockMessage = outofStockMessage;

}  

return originalStock;

}),

in corresponding template

<div class=”instock-cart-message”>{{inStockMessage}}</div>

<div class=”outofstock-cart-message”>{{outofStockMessage}}</div>

Leave a comment

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