To display the item ETA on the PDP page of the website for out-of-stock items. The date is determined form the ETA date of that item from the open purchase order. If there are multiple open purchase orders, then need to consider the first due date. So that the ETA date will display in the PDP matrix table alongwith the purchase orders.
- If there are multiple purchase orders for an item, then only the first date or the earliest date in the “Receive by” field will be considered.
- In the matrix table, we can add a new column as “Item ETA”. If item is out of stock, then only the ETA value will display there along with the quantity.
First we have to create a item search record having criteria as internal ID & results as due date, quantity.
getEta: function (itemId) {
// console.error("InsideFn", itemId);
try {
var searchFilters = [
["status", "anyof", "PurchOrd:B", "PurchOrd:E", "PurchOrd:D"],
"AND",
["item", "anyof", itemId],
"AND",
["duedate", "notbefore", "today"]
];
var searchColumns = [
new nlobjSearchColumn("duedate", null, "GROUP"),
new nlobjSearchColumn("quantity", null, "SUM")
]
var transactionSearchObj = Application.getAllSearchResults('transaction', searchFilters, searchColumns) || {};
console.error('itemIfData', transactionSearchObj)
var result = JSON.stringify(transactionSearchObj);
return result
}
catch (e) {
console.error("Test", e)
}
}
The above is the script result of what we searched.
Now use this script in the SuiteScript model file by creating a function. Here getEta() is a fn. Then we call this function in the Service Controller file under get function.
get: function get() {
try{
var data = this.request.getParameter('data');
// console.error('data',data)
return JJestimateTimeestimateTime.getEta(data);
}catch(e){
console.error("Test 2", e)
}
}
By using this we are getting the values in the form of String in the console of Website. Now We have to write the code in the Javascript related view file.
Here we first write the code under intialize function. The line (Utils.getAbsoluteUrl(getExtensionAssetsPath(“services/estimateTime.Service.ss”))) will fetch the values from the service file which further getting its values from service controller.
var itemId = this.model.get('internalid');
var url = Utils.getAbsoluteUrl(getExtensionAssetsPath("services/estimateTime.Service.ss"))
$.get(url, { data: JSON.stringify(itemId) })
.done(function (data) {
var data = JSON.parse(data);
self.etaData = data;
self.render();
})
GetContext():
var quntityavail = this.model.attributes.quantityavailable
if (quntityavail == 0) {
var etaduedate = !!(this.etaData) ? this.etaData[0].columns.duedate : '';
var quanitityonOrder = !!(this.etaData) ? this.etaData[0].columns.quantity : '';
if (quanitityonOrder > 0) {
var quantitycheck = true;
}
else {
quantitycheck = false;
}
}
After writing the above code we will change the values from String to particular path.
Thereafter, we can intialize the variable under getContext() where we can declare the variable path & asign the conditions accordingly in the tpl file.