Category Product Lists Return Page Not Found
In some implementations of the 2018.2 release of SuiteCommerce Advanced, category product lists return Page Not Found when viewing a table or list.
The following patch corrects a problem in Facets.Translator.js, which is part of the Facets module. To implement this patch, create a custom module to extend the prototype
object for the FacetsTranslator
function. You can download the code samples described in this procedure here: CategoryPageNotFound.zip.
Before proceeding, familiarize yourself with Best Practices for Customizing SCA.
Step 1: Extend the Facets.Translator.js File
-
Create an extensions directory to store your custom module. Depending on your implementation, this directory might already exist.
-
Create a custom module with a name similar to the module being customized.
For example,
Modules/extensions/FacetsExtension@1.0.0
. -
In your new FacetsExtension@1.0.0 directory, create a subdirectory called
JavaScript
.For example:
Modules/extensions/FacetsExtension@1.0.0/JavaScript
-
In your new JavaScript subdirectory, create a JavaScript file to extend Facets.Translator.js.
Name this file according to best practices.
For example:
Facets.Translator.Extension.js
-
Open this file and extend the
FacetsTranslator()
method as shown in the following code snippet:define('Facets.Translator.Extension' , [ 'Facets.Translator' , 'underscore' , 'jQuery' , 'SC.Configuration' , 'Utils' , 'UrlHelper' ] , function ( FacetsTranslator , _ , jQuery , Configuration ) { 'use strict'; _.extend(FacetsTranslator.prototype, { FacetsTranslator (facets, options, configuration, category) { // Enforces new if (!(this instanceof FacetsTranslator)) { return new FacetsTranslator(facets, options, configuration, category); } // Facets go Here this.facets = []; // Other options like page, view, etc. goes here this.options = {}; // This is an object that must contain a fallbackUrl and a lists of facet configurations this.configuration = configuration || default_config; // Get the facets that are in the sitesettings but not in the config. // These facets will get a default config (max, behavior, etc.) - Facets.Translator // Include facet aliases to be conisdered as a possible route var facets_data = Configuration.get('siteSettings.facetfield') , facets_to_include = []; _.each(facets_data, function(facet) { if (facet.facetfieldid !== 'commercecategory') { facets_to_include.push(facet.facetfieldid); // If the facet has an urlcomponent defined, then add it to the possible values list. facet.urlcomponent && facets_to_include.push(facet.urlcomponent); // Finally, include URL Component Aliases... _.each(facet.urlcomponentaliases, function(facet_alias) { facets_to_include.push(facet_alias.urlcomponent); }); } }); facets_to_include = _.union(facets_to_include, _.pluck(Configuration.get('facets'), 'id')); facets_to_include = _.uniq(facets_to_include); this.facetsToInclude = facets_to_include; this.isCategoryPage = !!category; if (_.isBoolean(category) && category) { var index = facets.length , facetsToInclude = this.facetsToInclude.slice(0) , facets_delimiter = this.configuration.facetDelimiters.betweenDifferentFacets , facet_value_delimiter = this.configuration.facetDelimiters.betweenFacetNameAndValue; facetsToInclude.push(this.configuration.facetDelimiters.betweenFacetsAndOptions); _.each(facetsToInclude, function(facetname) { facetname = facets_delimiter + facetname + facet_value_delimiter; var i = facets.lastIndexOf(facetname); if (i !== -1 && i < index) { index = i; } }); var categoryUrl = facets.substring(0, index); facets = facets.substring(index); if (categoryUrl[0] !== '/') { categoryUrl = '/' + categoryUrl; } if (categoryUrl[categoryUrl.length - 1] === '/') { categoryUrl = categoryUrl.substring(0, categoryUrl.length - 1); } if (facets && facets[0] === facets_delimiter) { facets = facets.substring(1, facets.length); } this.categoryUrl = categoryUrl; } else if (_.isString(category)) { this.categoryUrl = category; } // We cast on top of the passed in parameters. if (facets && options) { this.facets = facets; this.options = options; } else if (_.isString(facets)) { // It's a url this.parseUrl(facets); } else if (facets) { // It's an API option object this.parseOptions(facets); } } }); });
-
Save the file.
Step 2: Prepare the Developer Tools For Your Customization
-
Open your new FacetsExtension@1.0.0 module directory.
-
Create a file in this directory and name it ns.package.json.
Modules/extensions/FacetsExtension@1.0.0/ns.package.json
-
Build the ns.package.json file using the following code:
{ "gulp": { "javascript": [ "JavaScript/*.js" ] } }
-
Open the distro.json file. This is located in your root directory.
-
Add your custom modules to the
modules
object.Your code should look similar to the following example:
{ "name": "SuiteCommerce Advanced 2018.2.0 (sc-2018.2.0)", "version": "2.0", "isSCA": true, "buildToolsVersion": "sc-2018.2.0", "folders": { "modules": "Modules", "suitecommerceModules": "Modules/suitecommerce", "extensionsModules": "Modules/extensions", "thirdPartyModules": "Modules/third_parties", "distribution": "LocalDistribution", "deploy": "DeployDistribution" }, "modules": { "extensions/FacetsExtension": "1.0.0", "suitecommerce/Account": "sc-2018.2.0", //...
This step 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. -
Add
Facets.Translator.Extension
as a dependency to SCA entry point within theSC.Shopping.Starter
entrypoint of the JavaScript array.Your distro.js file should look similar to:
"tasksConfig": { //... "javascript": [ //... { "entryPoint": "SC.Shopping.Starter", "exportFile": "shopping.js", "dependencies": [ //... "Instrumentation.Cart", "SiteSearch", "Facets.Translator.Extension" ], //...
-
Save the distro.json file.
Step 3: Test and Deploy Your Customization
-
Test your source code customizations on a local server (see Test SCA Customizations on a Local Server) or deploy them to your NetSuite account (see Deploy SCA Customizations to NetSuite). If you are currently running SCA on a local server, your changes should appear on your local site immediately.
-
Confirm your results.
Upon successful deployment, Commerce Categories filter based on the selected facet values.