We created to extend the function QuantityPricingView for showing the list on the website based on the quantity pricing .our requirement is to show the list of quantities based on the price. So we extend the QuantityPricingView for listing the quantity and created a function for checking our conditions. The code is added below for fetching the value from the backend. The priceScheduleList function is used in the initialization of the QuantityPricingView.
priceScheduleList: function (e) {
var self = this;
var Configuration = SC.CONFIGURATION;
var priceSchedule = []
if (Configuration.get('micrositeSolution')) {
if (this.model.get('item').get('custitem_tag_enhc_qty_pricing') && this.model.get('item').get('internalid')) {
var quantityPricingModel = new QuantityPricingModel();
quantityPricingModel.fetch({
data: {
itemId: this.model.get('item').attributes.internalid,
itemType: this.model.get('item').attributes.itemtype,
priceLevel: "161",
}
}).done(function done() {
priceSchedule = { priceschedule: quantityPricingModel.get('priceschedule') }
self.model.set('microsite_price_detail', priceSchedule.priceschedule);
self.render()
});
}
}
},
We have added a function in suitescript for fetching the quantity and price from NetSuite.the function is added below
, getQuantityPricingByPriceLevelId: function getQuantityPricingByPriceLevelId(itemId, priceLevel, itemType) {
try {
var multiCurrency = nlapiGetContext().getFeature('MULTICURRENCY');
var multiPrice = nlapiGetContext().getFeature('MULTPRICE');
var quantityPricing = nlapiGetContext().getFeature('QUANTITYPRICING');
var priceID;
var currencyID = "USD";
if ((!multiCurrency) && (!multiPrice) && (!quantityPricing)) {
priceID = "rate";
} else {
priceID = "price";
if (multiCurrency) {
var internalId = nlapiSearchRecord('currency', null, new nlobjSearchFilter('symbol', null, 'contains', currencyID))[0].getId();
// Append the currency ID to the sublist name
priceID = priceID + internalId;
}
}
// Check to see if the item is using a Quantity Schedule
// If a Quantity Schedule is used, only the base price needs to be set.
// All other prices will be set according to the schedule.
var type = '';
if (itemType === 'InvtPart') {
type = 'inventoryitem';
} else if (itemType === 'Assembly') {
type = 'assemblyitem';
} else if (itemType === 'NonInvtPart') {
type = 'noninventoryitem';
} else if (itemType === 'Service') {
type = 'serviceitem';
} else if (itemType === 'Kit') {
type = 'kititem';
}
var itemRecord = nlapiLoadRecord(type, itemId);
var qtyPriceSchedule = itemRecord.getFieldValue('quantitypricingschedule');
// get the size of the matrix
var quantityLevels = itemRecord.getMatrixCount(priceID, 'price');
var priceLevels = itemRecord.getLineItemCount(priceID);
var pricelevelNameField = "pricelevel";
var itemPrice = 0;
var quantities = [];
var prices = [];
if (quantityLevels > 1) {
for (var j = 1; j <= quantityLevels; j++) {
var quantity = itemRecord.getMatrixValue(priceID, 'price', j);
if (quantity !== '') {
quantities.push(quantity);
}
}
}
// loop through the matrix one row at a time
for (var k = 1; k <= priceLevels; k++) {
var pricelevel = itemRecord.getLineItemValue(priceID, pricelevelNameField, k);
if (pricelevel != priceLevel) {
continue;
}
// loop through each column of the matrix
for (j = 1; j <= quantityLevels; j++) {
// get the price for this cell of the matrix
itemPrice = itemRecord.getLineItemMatrixValue(priceID, 'price', k, j);
if (itemPrice) {
prices.push(itemPrice);
}
}
}
var priceSchedule = [];
var columnLength = quantities.length;
for (k = 0; columnLength > 1 && k < columnLength; k++) {
var minimumQuantity = quantities[k];
var maximumQuantity = 0;
var price = prices[k];
if (k != quantities.length - 1) {
maximumQuantity = quantities[k + 1];
priceSchedule.push({
minimumquantity: minimumQuantity,
maximumquantity: maximumQuantity,
price: price,
price_formatted: '$' + price
});
} else {
priceSchedule.push({
minimumquantity: minimumQuantity,
price: price,
price_formatted: '$' + price
});
}
}
if (priceSchedule.length) {
return {
internalid: itemId,
itemid: itemId,
pricelevel: priceLevel,
priceschedule: priceSchedule
};
} else {
return {
internalid: itemId,
itemid: itemId,
pricelevel: priceLevel
};
}
} catch (e) {
nlapiLogExecution('ERROR', 'Error on Getting Price Level by ID', e);
}
},