Error When Adding Items to Categories in Site Management Tools
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.
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 Develop Your SCA Customization.
Step 1. Override the ItemsSearchAPI.json File
-
To override the
ItemsSearchAPI.json
file, located in the Configuration module, create a directory to store your custom modules, for example,extensions
.For more information about module configuration with JSON, see Modify JSON Configuration Files.
-
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
-
In your new
ConfigurationExtension@1.0.0
directory, create a subdirectory calledConfiguration
. -
Copy the following file into this directory:
Modules/suitecommerce/Configuration@1.0.0/Configuration/ItemsSearchAPI.json
-
Open
ItemsSearchAPI.json
and make the changes in steps 6 and 7. -
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"],
-
In
ItemsSearchAPI.json
, add the following object to thedefault
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" } ]
-
Save the file.
Step 2. Override the Facets.Model.js File
-
To override the
Facets.Model.js
file, located in the Facets module, create a directory in theextensions
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
-
In the
FacetsExtension@1.0.0
module, create a subdirectory calledJavaScript
. -
Copy the following file into this directory:
Modules/suitecommerce/Facets@2.3.0/JavaScript/Facets.Model.js
-
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))); } }); }
-
Save the file.
Step 3. Override the CMSadapterImpl.Categories.js File
-
To override the
CMSadapterImpl.Categories.js
file, located in the CMSadapter module, create a directory in theextensions
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
-
In the
CMSadapterExtension@1.0.0
module directory, create a subdirectory calledJavaScript
. -
Copy the following file into this directory:
Modules/suitecommerce/CMSadapter@3.0.0/JavaScript/CMSadapterImpl.Categories.js
-
Open
CMSadapterImpl.Categories.js
and make the changes in steps 5 to 7. -
In
CMSadapterImpl.Categories.js
, add'SC.Configuration'
to the list of dependencies. For example:define('CMSadapterImpl.Categories' , [ 'Facets.Model' , ... , 'SC.Configuration' ]
-
In
CMSadapterImpl.Categories.js
, add theConfiguration
function parameter. For example:, function ( FacetsModel ... , Configuration )
-
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') });
-
Save the file.
Step 4. Prepare the Developer Tools for Your Overrides
-
To make sure that the Gulp tasks include your modules when you deploy, set up the
ns.package.json
files for your custom module and modifydistro.json
.Create the
ns.package.json
file in theConfigurationExtension@X.X.X
directory. Add the following code tons.package.json
in theModules/extensions/ConfigurationExtension@X.X.X
directory:{ "gulp": { "configuration": [ "Configuration/*.json" ] } }
-
Create the
ns.package.json
file in theFacetsExtension@X.X.X
directory. Add the following code tons.package.json
in theModules/extensions/FacetsExtension@X.X.X
directory:{ "gulp": { "javascript": [ "JavaScript/*" ] } }
-
Create the
ns.package.json
file in theCMSadapterExtension@X.X.X
directory. Add the following code tons.package.json
in theModules/extensions/CMSadapterExtension@X.X.X
directory:{ "gulp": { "javascript": [ "JavaScript/*" ] } }
-
In
distro.json
, add your custom modules to themodules
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
-
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 SCA Customizations to NetSuite.
-
After you deploy the customization, log in to NetSuite and go to Commerce > Websites> Configuration, and select the appropriate web site and domain.
-
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.