Error When Adding Items to Categories in Site Management Tools

This topic applies to

Applies to

SuiteCommerce Advanced | Vinson

 

This patch contains a fix for an error on a category or subcategory that contains more than 10 items in Site Management Tools. SMT generates an error if you try to add more items to a category or subcategory that already contains more than 10 items. This error occurs because the default query sent to Items API to retrieve the items includes facets and the Items API returns no more than 10 results for queries that include facets.

This patch adds a Search API fieldset named CmsAdapterSearch. To install the patch, you must override files in the Configuration, Facets, and CMSadapter modules and add the new CmsAdapterSearch fieldset in the SuiteCommerce Advanced configuration. For an example of the changes needed for this patch, see AddingItemstoCategoriesinSMT.zip.

Note

In general, NetSuite best practice is to extend JavaScript using the JavaScript prototype object. This improves the chances that your customizations continue to work when migrating to a newer version of SuiteCommerce Advanced. However, this patch requires you to modify files that you cannot extend, and therefore requires you to override the existing module files in a custom module. For more information, see Customize and Extend Core SuiteCommerce Advanced Modules.


Step 1. Override the ItemsSearchAPI.json File

This step shows how to override the ItemsSearchAPI.json file, located in the Configuration module. For more information about module configuration with JSON, see Modify JSON Configuration Files.

  1. If you have not done so already, create a directory to store your custom modules, for example, extensions.

  2. Open this directory and create a subdirectory to maintain your customizations.

    Give this directory a name similar to the module being customized. For example:

    Modules/extensions/ConfigurationExtension@1.0.0

  3. In your new ConfigurationExtension@1.0.0 directory, create a subdirectory called Configuration.

  4. Copy the following file into this directory:

    Modules/suitecommerce/Configuration@1.0.0/Configuration/ItemsSearchAPI.json

  5. Open ItemsSearchAPI.json and make the changes in steps 6 and 7.

  6. In ItemsSearchAPI.json, replace the following line:

    "enum": ["Facets", "itemDetails", "relatedItems", "correlatedItems", "merchandisingZone", "typeAhead", "itemsSearcher"],

    With the following JSON object:

    "enum": ["Facets", "itemDetails", "relatedItems", "correlatedItems", "merchandisingZone", "typeAhead", "itemsSearcher", "CmsAdapterSearch"],
  7. In ItemsSearchAPI.json, add the following object to the default object:

    { "id": "CmsAdapterSearch", "fieldset": "search" }

    The default object should look similar to the following code after this step:

    "default": [ { "id": "Facets", "fieldset": "search", "include": "facets" }, ... { "id": "CmsAdapterSearch", "fieldset": "search" } ]
  8. Save the file.

Step 2. Override the Facets.Model.js File

This step shows how to override the Facets.Model.js file, located in the Facets module.

  1. Create a directory in the extensions directory to store the custom module.

    Give this directory a name similar to the module being customized. For example:

    Modules/extensions/FacetsExtension@1.0.0

  2. In the FacetsExtension@1.0.0 module, create a subdirectory called JavaScript.

  3. Copy the following file into this directory:

    Modules/suitecommerce/Facets@2.3.0/JavaScript/Facets.Model.js

  4. Open Facets.Model.js and make the following change.

    Replace the existing initialize function:

    initialize: function () { // Listen to the change event of the items and converts it to an ItemDetailsCollection this.on('change:items', function (model, items) { if (!(items instanceof ItemDetailsCollection)) { // NOTE: Compact is used to filter null values from response model.set('items', new ItemDetailsCollection(_.compact(items))); } }); }

    With the following JavaScript code:

    initialize: function () { if (options && options.searchApiMasterOptions) { this.searchApiMasterOptions = options.searchApiMasterOptions; } // Listen to the change event of the items and converts it to an ItemDetailsCollection this.on('change:items', function (model, items) { if (!(items instanceof ItemDetailsCollection)) { // NOTE: Compact is used to filter null values from response model.set('items', new ItemDetailsCollection(_.compact(items))); } }); }
  5. Save the file.

Step 3. Override the CMSadapterImpl.Categories.js File

This step shows how to override the CMSadapterImpl.Categories.js file, located in the CMSadapter module.

  1. Create a directory in the extensions directory to store the custom module.

    Give this directory a name similar to the module being customized. For example:

    Modules/extensions/CMSadapterExtension@1.0.0

  2. In the CMSadapterExtension@1.0.0 module directory, create a subdirectory called JavaScript.

  3. Copy the following file into this directory:

    Modules/suitecommerce/CMSadapter@3.0.0/JavaScript/CMSadapterImpl.Categories.js

  4. Open CMSadapterImpl.Categories.js and make the changes in steps 5 to 7.

  5. In CMSadapterImpl.Categories.js, add 'SC.Configuration' to the list of dependencies. For example:

    define('CMSadapterImpl.Categories' , [ 'Facets.Model' , ... , 'SC.Configuration' ]
  6. In CMSadapterImpl.Categories.js, add the Configuration function parameter. For example:

    , function ( FacetsModel ... , Configuration )
  7. In CMSadapterImpl.Categories.js, replace the following line:

    var model = new FacetsModel();

    With the following JavaScript code:

    var model = new FacetsModel({ searchApiMasterOptions: Configuration.get('searchApiMasterOptions.CmsAdapterSearch') });
  8. Save the file.

Step 4. Prepare the Developer Tools for Your Overrides

This step shows how to set up the ns.package.json files for your custom module and modify distro.json to make sure that the Gulp tasks include your modules when you deploy.

  1. Create the ns.package.json file in the ConfigurationExtension@X.X.X directory. Add the following code to ns.package.json in the Modules/extensions/ConfigurationExtension@X.X.X directory:

    { "gulp": { "configuration": [ "Configuration/*.json" ] } }
  2. Create the ns.package.json file in the FacetsExtension@X.X.X directory. Add the following code to ns.package.json in the Modules/extensions/FacetsExtension@X.X.X directory:

    { "gulp": { "javascript": [ "JavaScript/*" ] } }
  3. Create the ns.package.json file in the CMSadapterExtension@X.X.X directory. Add the following code to ns.package.json in the Modules/extensions/CMSadapterExtension@X.X.X directory:

    { "gulp": { "javascript": [ "JavaScript/*" ] } }
  4. In distro.json, add your custom modules to the modules object.

    This ensures that the Gulp tasks include your module when you deploy.  In this example, the custom modules are added at the beginning of the list of modules. However, you can add the modules anywhere in the modules object. The order of precedence in this list does not matter.

    { "name": "SuiteCommerce Advanced Vinson Release", "version": "2.0", "buildToolsVersion": "1.2.1", "folders": { "modules": "Modules", "suitecommerceModules": "Modules/suitecommerce", "thirdPartyModules": "Modules/third_parties", "distribution": "LocalDistribution", "deploy": "DeployDistribution" }, "modules": { "extensions/ConfigurationExtension": "X.X.X", "extensions/FacetsExtension": "X.X.X", "extensions/CMSadapterExtension": "X.X.X",

Step 5. Deploy Your Override

  1. To test this customization, you must first deploy it to your NetSuite account. You may need to modify the SuiteCommerce Advanced configuration, therefore you must deploy it first. See Deploy to NetSuite.

  2. After you deploy the customization, log in to NetSuite and go to Setup > SuiteCommerce Advanced > Configuration, and select the appropriate web site and domain.

  3. On the Advanced > Search Results tab, make sure that CmsAdapterSearch appears for the search fieldset. If it does not appear, you must add it and click Save.

    You can now add more than 10 items to a category in Site Builder.

Related Topics