Resolve the Internal Error on Attempt to Visit a Newly Created Commerce Category in SuiteCommerce Advanced Elbrus

In an Elbrus implementation, The categories for the website is configured using Commerce Categories. The default setup for this record reside in the Facets.Translator.js file, which is located in the Facets module.

This section explains how to fix the internal error shown when visiting a newly created Commerce Category on SuiteCommerce Advanced Elbrus.

Solution

1. Open the file Facets JavaScriptFacets.Translator.js 

2. Replace the existing FacetsTranslator constructor method for the following implementation: 

//@constructor @param {Array}facets @param {Object} options @param {Object} configuration
	function 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)
			,	delimiterBetweenDifferentFacets = this.configuration.facetDelimiters.betweenDifferentFacets
			,	delimiterBetweenFacetNameAndValue = this.configuration.facetDelimiters.betweenFacetNameAndValue
			,	delimitedUrlFragment = facets + delimiterBetweenFacetNameAndValue
			,	delimiter_added = false;


			facetsToInclude.push(this.configuration.facetDelimiters.betweenFacetsAndOptions);


			if (facets.substring(0, delimiterBetweenDifferentFacets.length) !== delimiterBetweenDifferentFacets)
			{
				delimitedUrlFragment = delimiterBetweenDifferentFacets + delimitedUrlFragment;
				delimiter_added = true;
			}


			_.each(facetsToInclude, function (facetName)
			{
				var i = delimitedUrlFragment.indexOf(delimiterBetweenDifferentFacets + facetName + delimiterBetweenFacetNameAndValue);


				if (i !== -1 && i < index)
				{
					index = delimiter_added ? i - 1 : 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);
			}


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

3. After confirming the results locally, deploy the changes to the user’s NetSuite account

Leave a comment

Your email address will not be published. Required fields are marked *