When working in SuiteCommerce, there are a variety of methods to use to access data in the shopping context provided by the commerce API.
The shopping session object is retrieved from the Models.Init.js file found in the source code under Commons > SspLibraries > SuiteScript.
Not yet familiar with SuiteScript? Before jumping in and working with SuiteScript, be sure to check out this introductory article to get an overview of what it is: What is SuiteScript?
var addOnItems = ModelsInit.session.getItemFieldValues('addonitems', addOnItemIds)
define('AddOnItems.Model',
[
'SC.Model',
'SC.Models.Init',
'underscore'
],
function (
SCModel,
ModelsInit,
_
) {
'use strict';
return SCModel.extend({
name: 'AddOnItems.Model',
getAddOnItems: function (data) {
var returnObj = {};
try {
var columns = _.pluck(data.addOnItemsConfig, 'fieldId'),
fieldValues = nlapiLookupField('item', data.itemId, columns),
addOnItemIds = [];
addOnItemsConfig = _.map(data.addOnItemsConfig, function (configType) {
var field_value = fieldValues[configType.fieldId];
configType.itemIds = field_value ? field_value.split(',') : [];
addOnItemIds = _.union(configType.itemIds, addOnItemIds);
return configType;
});
addOnItemIds = _.uniq(addOnItemIds);
if (addOnItemIds.length) {
var addOnItems = ModelsInit.session.getItemFieldValues('addonitems', addOnItemIds).items;
}
}
catch (e) {
returnObj.error = e;
}
return returnObj;
}
});
}
)
We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!
If you have general questions about SuiteCommerce or more specific questions about how our team can support your business as you implement NetSuite or SuiteCommerce, feel free to contact us anytime. Anchor Group is a certified Oracle NetSuite Alliance Partner and Commerce Partner equipped to handle all kinds of NetSuite and SuiteCommerce projects, large or small!
Tagged with Training