scenario – Display available quantity for matrix child items.
child items means red with large, blue with medium, only colour items ect…
explanation- We can display available quantity for matrix child items in checkout page and shopping page .
using below code to we can display .
based on the page we can extend required view .
_.extend(TransactionLineViewsCellNavigableView.prototype,{
getContext: _.wrap(TransactionLineViewsCellNavigableView.prototype.getContext, function (fn) {
var context = fn.apply(this, _.toArray(arguments).slice(1));
var url = window.location.href;
if (url.indexOf(“review”) > -1) {
var availablequantity;
var availableQuantityMatrix = context.model.attributes.item.attributes.matrix_parent.matrixchilditems_detail
var currentItem = context.model.attributes.item.attributes.itemid;
_.each(availableQuantityMatrix, function (params) {
if (params.itemid == currentItem)
{
availablequantity = params.quantityavailable;
}
})
var showavailablequantity=true;
$(“#available”).css(‘display’, “block”);
context.availablequantity=availablequantity;
context.showavailablequantity=showavailablequantity;
}
return context;
})
}
we written if condition for display available quantity for exact matrix child item .
without if condition available quantity takes first matrix child item for every matrix child item in check out page and shopping page .
after above process add below code in required tpl in my case i added in transaction_line_views_cell_navigable.tpl 31 line.
{{#if showavailablequantity}}
<td class=”transaction-line-views-cell-navigable-item-quantity” name=”item-a-quantity” id=”available”>
<p>
<span class=”transaction-line-views-cell-navigable-item-quantity-label”>{{translate ‘Available Quantity:’}} </span>
<span class=”transaction-line-views-cell-navigable-item-quantity-value”>{{availablequantity}}</span>
</p>
</td>
{{/if}}
deploy theme