Version: eXtendPS-DE 1.3.7 and above
Audience: Administrator, Developer

Use Case

  • Set item images based on the dimension value received in the PromoStandards response.
  • Set item images based on customs rule determined by the data received in the PromoStandards response.

Prerequisites

Ensure that the mapping of the PromoStandards item image types to NetSuite item image fields is set up in eXtendPS-DE Setup page by your NetSuite Administrator.

The hook function will determine which image value to set, but the field and image class type mapping will be determined from the configuration in on the Item Images subtab of the etendPS-DE Setup page.

See eXtendPS-DE Setup Configuration Guide for more information on the eXtendPS-DE Setup page.

Configuration Details

  • Configuring the hook function
    • Search for and open the suite_promo_transformers.js file.
    • Add the function getMatchedImageUrl()
      .
    • Add your custom rule to it.
    • Save the file.
  • Sample function
    The following sample function sets the image URL with the highest dimension coming in response on an item based on the item field and image class type mapping specified on the eXtendPS-DE Setup page.

    Note: If image dimensions are not returned in the response, then the very first image with the mapped class type received will be set on the item record's image field.
/**
  * @param    {Object} args
  * @property {String} args.productId
  * @property {String} args.vendorId
  * @property {String} args.imageClassId
  * @property {String} args.partId
  * @property {String} args.fieldId
  * @property {Array}  args.mediaContent
  */
  function getMatchedImageUrl (args) {
    var mediaContent = args.mediaContent;
    var classType = args.classType;
    var fieldId = args.fieldId;
    var mediaUrlObject = {};
    var tempImageWidthHeightObject = {
      width: '',
      height: ''
    };
 
    log.debug({ title: 'getMatchedImageUrl mediaContent', details: mediaContent });
    mediaContent.forEach(function (mediaData) {
      var height = mediaData.height || '';
      var width = mediaData.width || '';
 
      var classTypeArray = [];
      if (mediaData.ClassTypeArray && mediaData.ClassTypeArray[0] && mediaData.ClassTypeArray[0].ClassType && mediaData.ClassTypeArray[0].ClassType[0]) {
        classTypeArray = mediaData.ClassTypeArray[0].ClassType;
      }
 
      classTypeArray.forEach(function(classTypeObject) {
        var classTypeId = classTypeObject.classTypeId || '';
        if (classTypeId === classType) {
          if (tempImageWidthHeightObject.height && tempImageWidthHeightObject.width && width && height && (parseFloat(height) > parseFloat(tempImageWidthHeightObject.height)) && (parseFloat(width) > parseFloat(tempImageWidthHeightObject.width)) ) {
            tempImageWidthHeightObject = {
              width: width,
              height: height
            };
            mediaUrlObject[fieldId] = mediaData.url;
          } else if (!tempImageWidthHeightObject.width && !tempImageWidthHeightObject.height) {
            tempImageWidthHeightObject = {
              width: width,
              height: height
            };
            mediaUrlObject[fieldId] = mediaData.url;
          }
        }
      });
    });
 
    return mediaUrlObject;
  }