Page With URL Fragments Redirects Too Many Times

This topic applies to

Applies to

SuiteCommerce Advanced | Elbrus | Kilimanjaro

In some implementations of the Elbrus and Kilimanjaro releases of SuiteCommerce Advanced, some pages return ERR_TOO_MANY_REDIRECTS instead of displaying the Product Details page or a 404 error. This error occurs when the URL contains one or more URL fragments. The patch instructions described below correct this problem.

To implement this patch, create a custom module to override ProductDetails.Router.js, which is part of the ProductDetails module. You can download the code samples described in this procedure here: PageWithURLFragmentsRedirectsTooManyTimes.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 a file in a way that you cannot extend, and therefore requires you to use a custom module to override the existing module file. For more information, see Customize and Extend Core SuiteCommerce Advanced Modules.


Step 1: Create the Override File

  1. Create an extensions directory to store your custom module. Depending on your implementation, this directory might already exist.

  2. Within this directory, create a custom module with a name similar to the module being customized.

    For example, create Modules/extensions/ProductDetailsExtension@1.0.0.

  3. In your new ProductDetailsExtension@1.0.0 directory, create a subdirectory called JavaScript.

    For example: Modules/extensions/ProductDetailsExtension@1.0.0/JavaScript

  4. Copy the following source file and paste into the correct location:

    Copy This File:

    Place a Copy Here:

    Modules/suitecommerce/ProductDetails@X.Y.Z/JavaScript/ ProductDetails.Router.js

    Modules/extensions/ProductDetailsExtension@1.0.0/JavaScript

    In this example, X.Y.Z represents the version of the module in your implementation of SuiteCommerce Advanced.

  5. Open your new copy of ProductDetails.Router.js and locate the following lines:

    if (api_query.id && item.get('urlcomponent') && SC.ENVIRONMENT.jsEnvironment === 'server') { nsglobal.statusCode = 301; nsglobal.location = product.generateURL(); } if (data.corrections && data.corrections.length > 0) { if (item.get('urlcomponent') && SC.ENVIRONMENT.jsEnvironment === 'server') { nsglobal.statusCode = 301; nsglobal.location = data.corrections[0].url + product.getQuery(); } else { return Backbone.history.navigate('#' + data.corrections[0].url + product.getQuery(), {trigger: true}); } }
  6. Replace these lines with the following code:

    if (api_query.id && item.get('urlcomponent') && SC.ENVIRONMENT.jsEnvironment === 'server') { var productUrl = product.generateURL(); productUrl = productUrl[0] === '/' ? productUrl : '/' + productUrl; nsglobal.statusCode = 301; nsglobal.location = productUrl; } if (data.corrections && data.corrections.length > 0) { if (item.get('urlcomponent') && SC.ENVIRONMENT.jsEnvironment === 'server') { var url = data.corrections[0].url; url = url[0] === '/' ? url : '/' + url; nsglobal.statusCode = 301; nsglobal.location = url + product.getQuery(); } else { return Backbone.history.navigate('#' + data.corrections[0].url + product.getQuery(), {trigger: true}); } }
  7. Save the file.

Step 2: Prepare the Developer Tools For Your Customization

  1. Open your Modules/extensions/ProductDetailsExtension@1.0.0 module directory.

  2. Create a file in this directory and name it ns.package.json.

    Modules/extensions/ProductDetailsExtension@1.0.0/ns.package.json

  3. Paste the following code in your new ns.package.json file:

    { "gulp": { "javascript": [ "JavaScript/*.js" ] }, "overrides": { "Modules/suitecommerce/ProductDetails@X.Y.Z/JavaScript/ProductDetails.Router.js" : "JavaScript/ProductDetails.Router.js" } }

    Important

    You must replace the string X.Y.Z with the version of the module in your implementation of SuiteCommerce Advanced.


  4. Open the distro.json file. This file is located in your root directory.

  5. Add your custom module to the modules object.

    Your code should look similar to the following example:

    { "name": "SuiteCommerce Advanced Kilimanjaro", "version": "2.0", "isSCA": true, "buildToolsVersion": "1.3.1", "folders": { "modules": "Modules", "suitecommerceModules": "Modules/suitecommerce", "extensionsModules": "Modules/extensions", "thirdPartyModules": "Modules/third_parties", "distribution": "LocalDistribution", "deploy": "DeployDistribution" }, "modules": { "extensions/ProductDetailsExtension": "1.0.0", "extensions/MyExampleCartExtension1": "1.0.0", ...

    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.

  6. Save the distro.json file.

Step 3: Test and Deploy Your Customization

  1. Test your source code customizations on a local server (see SCA on a Local Server) or deploy them to your NetSuite account (see Deploy to NetSuite). If you are currently running SCA on a local server, your changes should appear on your local site immediately.

  2. Confirm your results. Upon successful deployment, instead of showing ERR_TOO_MANY_REDIRECTS, the browser shows a 404 error or the Product Details page.

Related Topics