Error Loading Shopping Page Due to Uncaught TypeError

In some implementations of Elbrus, the shopping page returns a blank page and the following error is returned in the log for the page:

Uncaught TypeError: Cannot read property 'indexOf' of undefined

This error can occur because the URL includes the percent sign (%) and SuiteCommerce does not correctly handle the symbol. This patch overrides Utils.js in the Utilities module to add the getDecodedURLParameter function and correctly handle the symbol. You can download the code samples described in this procedure here: ShoppingPageErrorUncaughtTypeError.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 that you cannot extend, and therefore requires you to use a custom module to override the existing module file. For more information, see Develop Your SCA Customization.

Step 1: Create the Utils.js Override File

  1. To override the Utils.js file, located in the Utilties module, open the Modules/extensions directory and create a subdirectory to maintain your customizations.

    Give this directory a name similar to the module being customized. For example, create Modules/extensions/UtilitiesExtension@1.0.0

  2. In your new UtilitiesExtension@1.0.0 directory, create a subdirectory called JavaScript.

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

  3. Copy the following file:

    Modules/suitecommerce/Utilities@X.Y.Z/JavaScript/Utils.js

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

  4. Paste a copy in the JavaScript directory for the new module.

    For example: Modules/extensions/Utilities@X.Y.Z/JavaScript/Utils.js

  5. Open your new copy of Utils.js and make the following change.

    Add the following getDecodedURLParameter function before the existing parseUrlOptions function:

                    function getDecodedURLParameter (url_parameter)
    {
      url_parameter = url_parameter || '';
      var position;
    
      for(var temporal = ''; (position = url_parameter.indexOf('%')) >= 0; url_parameter =
        url_parameter.substring(position + 3))
        {
          temporal += url_parameter.substring(0, position);
          var x = url_parameter.substring(position, position + 3);
      
          try
          {
            temporal += decodeURIComponent(x);
          }
          catch (e)
          {
             temporal += x;
          }
        }
      return temporal + url_parameter;
    } 
    
                  

    Your final result should look similar to the following:

                      ...
        return baseUrl;
      }
    
      function getDecodedURLParameter (url_parameter)
      {
      // new function
      }
    
      function parseUrlOptions (options_string)
      {
      ... 
    
                  
  6. Add the call to the getDecodedURLParameter function in SC.Utils:

                    var Utils = SC.Utils = {
       ...
    ,   deepCopy: deepCopy
    ,   getDecodedURLParameter: getDecodedURLParameter 
    }; 
    
                  
  7. Locate the following line in the parseUrlOptions function:

                    options[current_token[0]] = decodeURIComponent(current_token[1]); 
    
                  

    Replace this line with the following line:

                    options[current_token[0]] = Utils.getDecodedURLParameter(current_token[1]); 
    
                  
  8. Save the file.

Step 2: Prepare the Developer Tools For Your Customization

  1. To make sure that the Gulp tasks include your modules when you deploy, set up the ns.package.json file for your custom module and modify distro.json.

    Open the Modules/extensions/UtilitiesExtension@1.0.0 module directory.

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

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

  3. Build the ns.package.json file using the following code:

                    { 
      "gulp": {
        "javascript": [
          "JavaScript/*.js"
        ]
      },
      "overrides": {
        "suitecommerce/Utilities@X.Y.Z/JavaScript/Utils.js" : "JavaScript/Utils.js"
      }
    } 
    
                  
  4. Open the distro.json file. This is located in your root directory.

  5. Add your custom modules to the modules object.

    Your code should look similar to the following example:

                    {
      "name": "SuiteCommerce Advanced Elbrus",
      "version": "2.0",
      "buildToolsVersion": "1.3.0",
      "folders": {
        "modules": "Modules",
        "suitecommerceModules": "Modules/suitecommerce",
        "extensionsModules": "Modules/extensions",
        "thirdPartyModules": "Modules/third_parties",
        "distribution": "LocalDistribution",
        "deploy": "DeployDistribution"
      },
      "modules": {
        "extensions/UtilitiesExtension": "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 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.

  2. Confirm your results.

    Upon successful deployment, URLs that contain the percent sign symbol load properly.

Related Topics

SCA Patches

General Notices