Description: In Quantity pricing items when we select quantity but its showing quantity as 1 we can use this solution to solve this problem.
Entrypoint:
_.extend(ProductDetailsFullView.prototype, {
getContext: _.wrap(ProductDetailsFullView.prototype.getContext, function (fn) {
var originalRet = fn.apply(this, _.toArray(arguments).slice(1));
originalRet.description = originalRet.model.attributes.item.attributes.storedetaileddescription;
var pricingSchedule = this.model.attributes.item.attributes.onlinecustomerprice_detail.priceschedule
if (pricingSchedule) {
originalRet.showQunatityPricing = true;
} else {
originalRet.showQunatityPricing = false;
}
return originalRet;
})
});
_.extend(QuantityPricingView.prototype, {
events: {
'change [data-action="updateQuantities"]': 'updateQuantity'
},
updateQuantity: function (e) {
console.log(e.target.value, 'valueee')
this.model.set('quantityset', 500)
var quantityset = this.model.get('quantityset')
this.model.set('quantity', parseInt(quantityset))
},
getContext: _.wrap(QuantityPricingView.prototype.getContext, function getContext(fn) {
var context = fn.apply(this, _.toArray(arguments).slice(1));
var self = this;
console.log(this);
var pricingSchedule = this.model.attributes.item.attributes.onlinecustomerprice_detail.priceschedule
var quantityatfirst = this.model.attributes.item.attributes.onlinecustomerprice_detail.priceschedule[0].maximumquantity
var quantities = [];
var counter = 0;
var quantityFromModel = 0
if (pricingSchedule) {
if ($("#quantity").val()) {
quantityFromModel = this.model.attributes.quantity
} else {
this.model.set('quantity', parseInt(quantityatfirst))
}
}
_.each(pricingSchedule, function eachScheduled(schedule) {
if (schedule.maximumquantity && schedule.maximumquantity <= 50000) {
var quantity = parseInt(schedule.maximumquantity);
var price = quantity * (pricingSchedule[counter + 1].price * 1000);
price = price / 1000;
//var newPrice = price.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
var newPrice = parseFloat(price).toFixed(2);
var formattedPrice = "$" + newPrice;
var formattedQuantity = quantity.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
var dot = formattedQuantity.indexOf('.');
formattedQuantity = formattedQuantity.substring(0, dot);
var customName = formattedQuantity + '- ' + formattedPrice;
if (quantityFromModel > 0) {
if (quantityFromModel == quantity) {
quantities.push({ name: customName, value: quantity, selected: true });
} else {
quantities.push({ name: customName, value: quantity, selected: '' });
}
} else {
quantities.push({ name: customName, value: quantity, selected: '' });
}
}
counter++;
});
context.quantities = quantities;
_.each(context.priceSchedule, function (priceScheduleval) {
priceScheduleval.maximumquantity = priceScheduleval.maximumquantity + 1;
// priceScheduleval.maximumquantity=
var finalval = (priceScheduleval.maximumquantity) * (priceScheduleval.price);
priceScheduleval.price = parseFloat(finalval).toFixed(2);
priceScheduleval.price_formatted = "$" + (priceScheduleval.price);
});
// // var address = this.model.attributes.item.attributes.onlinecustomerprice_detail.priceschedule
// console.log("context final", context);
return context;
})
});
template
<div class="cart-item-summary-item-list-actionable-amount">
<label class="cart-item-summary-item-list-actionable-label-qty">{{translate 'Quantity:'}}</label>
<select name="quantity" id="quantity" class="enhanced-quantity-select-cart" data-action="updateQuantities" style="background-position: 95% 50%;">
{{#each quantities}}
<option value="{{value}}" {{#if selected}}selected{{/if}}>{{name}}</option>
{{/each}}
</select>
</div>