SuiteCommerce Shopping Object

in , , August 9th, 2024

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?

Things to Know When Working With the Shopping Object

  • To access this object, you must import ‘SC.Models.Init’. The shopping object is defined in a “session” variable.
  • See line 45 of the example below for method call
var addOnItems = ModelsInit.session.getItemFieldValues('addonitems', addOnItemIds).items;
  • The first parameter passed into the function is the field set id. “addOnItemIds” is an array of items.
  • Items can be accessed by the “items” attribute returned in the object from getItemFieldValues().

SuiteCommerce Shopping Object Example Code

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;
            }
        });
    }
);

Author: An Phan


Got stuck on a step in this article?

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!


Oracle NetSuite Alliance Partner & Commerce Partner

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!

We are a premium SuiteCommerce agency that creates powerful customer portals. Unlike our competitors, we have already solved your problems.

 
 

Want to keep learning?

Our team of NetSuite professionals has written articles on a wide variety of NetSuite topics, from SuiteCommerce tips, to recommended NetSuite solutions, to available support services, and more! 

Your cart