Content Appears Incorrectly in a Merchandising Zone

This topic applies to

Applies to

SuiteCommerce Advanced | Elbrus | Kilimanjaro

 

In some implementations of Elbrus and Kilimanjaro, items may appear in a merchandising zone that do not meet the criteria for the zone. This error applies to merchandising zones that are added in Site Management Tools (SMT) and appear on either the product detail or cart pages.

The process to implement the fix in this patch is the same whether you update Elbrus or Kilimanjaro. To implement this patch, you create a new JavaScript file and override CMSadapter.js in the CMSadapter module. The new JavaScript file adds a new merchandising implementation in the module.

Note

This fix only applies if you are using CMS Adapter Version 3 on Kilimanjaro or CMS Adapter Version 2 on Elbrus.


For an example of the changes needed for this patch, see one of the following links for the source files, depending on your implementation:

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 CMSadapterImpl.Merchandising.js File and the CMSadapter.js Override File

This step shows how to override the CMSadapter.js file and create the CMSadapterImpl.Merchandising.js file. Both files are located in the CMSadapter module.

  1. Open the Modules/extensions directory and create a subdirectory to maintain your customizations.

    For example, create Modules/extensions/CMSadapter.Extension@1.0.0

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

    For example, create Modules/extensions/CMSadapter.Extension@1.0.0/JavaScript

  3. Copy the following file:

    Modules/suitecommerce/CMSadapter@X.Y.Z/JavaScript/CMSadapter.js

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

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

    For example: Modules/extensions/CMSadapter.Extension@1.0.0/JavaScript/CMSadapter.js

  5. Open your new copy of the CMSadapter.js file and locate the following lines:

    , 'CMSadapterImpl.Enhanced'

    Replace this line with the following code:

    , 'CMSadapterImpl.Enhanced' , 'CMSadapterImpl.Merchandising'
  6. In the new CMSadapter.js, add this line at the end of the initAdapter() method:

    this.adapterMerchandising = new CMSadapterImplMerchandising(application, CMS);

    Your code should look similar to the following:

    , initAdapter: function(application, landingRouter) { if (typeof CMS === 'undefined') { console.log('Error: CMS global variable not found - CMS adapter not initialized'); return; } this.adapterCore = new CMSadapterImplCore(application, CMS); this.adapterLanding = new CMSadapterImplLanding(application, CMS, landingRouter); this.adapterCategories = new CMSadapterImplCategories(application, CMS); this.adapterMerchandising = new CMSadapterImplMerchandising(application, CMS); }
  7. Save the file.

  8. In the new JavaScript folder, build out the new CMSadapterImpl.Merchandising.js file with the following code:

    /* @module CMSadapter @class CMSadapterImpl.Merchandising */ define('CMSadapterImpl.Merchandising' , [ 'LiveOrder.Model' , 'underscore' ] , function ( LiveOrderModel , _ ) { 'use strict'; function AdapterMerchandising(application, CMS) { this.CMS = CMS; this.application = application; this.listenForCMS(); } _.extend(AdapterMerchandising.prototype, { listenForCMS: function () { var self = this; self.CMS.on('cart:items:get', function (promise) { var linesId = [] , cartInstance = LiveOrderModel.getInstance(); cartInstance.cartLoad.then(function() { var lines = cartInstance.get('lines'); lines.each(function(line) { var item = line.get('item') , internalId = item && item.get('internalid'); if (internalId) { linesId.push(internalId); } }); promise.resolve(linesId); }); }); self.CMS.on('page:items:get', function (promise) { var linesId = [] , PDP_FULL_VIEW = 'ProductDetails.Full.View' , PDP_QUICK_VIEW = 'ProductDetails.QuickView.View' , view = self.application.getLayout().getCurrentView() , view_identifier = view && view.attributes && view.attributes.id , view_prototype_id = view && view.prototype && view.prototype.attributes && view.prototype.attributes.id; if (view && (view_identifier === PDP_FULL_VIEW || view_identifier === PDP_QUICK_VIEW || view_prototype_id === PDP_FULL_VIEW || view_prototype_id === PDP_QUICK_VIEW)) { var internalId = view.model && view.model.get('item') && view.model.get('item').get('internalid'); if (internalId) { linesId.push(internalId); } } promise.resolve(linesId); }); } }); return AdapterMerchandising; });
  9. Save CMSadapterImpl.Merchandising.js.

Step 2: Prepare the Developer Tools For Your Customization

This step shows how to create the ns.package.json file for the custom module and shows how to modify the distro.json file to make sure that the Gulp tasks include your modules when you deploy.

  1. Open your new Modules/extensions/CMSadapter.Extension@1.0.0 module.

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

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

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

    { "gulp": { "javascript": [ "JavaScript/*.js" ] }, "suitecommerce/CMSadapter@X.Y.Z/JavaScript/CMSadapter.js" : "JavaScript/CMSadapter.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 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/CMSadapter.Extension": "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, the merchandising zones for products contain only items that meet the criteria for the zone.

Related Topics