Add to Cart Button Does Not Work If Quantity Field Selected

In implementations of Elbrus, clicking the Add to Cart button one time does not add the chosen items to the cart. Instead, users must click this button twice. This error only occurs if the focus is on the Quantity field.

To implement this patch, you must override the events object of the Cart.AddToCart.Button.View.js file, located in the Cart module. Because of the type of change that you need to make to the View file, you must override the view instead of extending it. You can download the code samples described in this procedure here: AddtoCartButtonDoesNotWork.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 Develop Your SCA Customization.

Step 1: Create the Cart.AddToCart.Button.View.js Override File

  1. To override the Cart.AddToCart.Button.View.js file, located in the Cart module, create a directory to store your custom module.

  2. 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/Cart.Extension@1.0.0

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

    Modules/extensions/Cart.Extension@1.0.0/JavaScript

  4. Copy the following file into the new JavaScript directory:

    Modules/suitecommerce/Cart@X.Y.Z/JavaScript/Cart.AddToCart.Button.View.js

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

  5. Open Cart.AddToCart.Button.View.js and make the following change:

    Locate the following line in the new file:

                    'click [data-type="add-to-cart"]': 'addToCart' 
    
                  

    Replace the line with the following lines:

                     'mouseup [data-type="add-to-cart"]': 'addToCart' , 'click [data-type="add-to-cart"]': 'addToCart' 
    
                  
  6. 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, open the Modules/extensions/Cart.Extension@1.0.0 module directory.

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

    Modules/extensions/Cart.Extension@1.0.0/ns.package.json

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

                    { "gulp": { "javascript": [ "JavaScript/*.js" ] }, "overrides": { "suitecommerce/Cart@X.Y.Z/JavaScript/Cart.AddToCart.Button.View.js" : "JavaScript/Cart.AddToCart.Button.View.js" }
    } 
    
                  
  4. In distro.json, 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/Cart.Extension": "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.

  5. 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, the Add to Cart button works with one click.

Related Topics

SCA Patches

General Notices