is there a way to directly interact with the `Cust...
# suitecommerce
k
is there a way to directly interact with the
Customer Segments
with the Theme Dev Tools? Or is it limited to only Extensions / methods? https://system.netsuite.com/help/helpcenter/en_US/APIs/SuiteCommerce/Extensibility/Frontend/UserProfile.html#getCustomerSegments
e
In a extension you could get the necessary data related to customer segments and pass it to your desired view/template with the
addContextDefinition
method from the Layout component. You can pass a single property or an object.
☝🏻 1
k
In SCS not Advanced as well?
e
Yes
k
I have a proof of concept going, but something still seems off. The customer segments arent always mappable and I get different behavior between local and production. Am I going about this correctly?
Copy code
define("FWC.Extension", ["underscore", "Utils"], function (_, Utils) {
  {
    "use strict";
    return {
      mountToApp: function (container) {
        var Layout = container.getComponent("Layout");
        var userProfile = container.getComponent('UserProfile');
        var alternateLogo = false;
        if (userProfile.length) {
          userProfile.getCustomerSegments().then(function (customerSegments) {
          for (i = 0; i < customerSegments.length; i++) {
            console.log("Customer Segment ID: " + customerSegments[i].id);
            if (customerSegments[i].id == '1338793') {
              console.log("Cutomer segment is equal to 1338793, setting alternateLogo boolean to true");
              alternateLogo = true;
            }
          }
        });
        }
        Layout.addToViewContextDefinition('Header.Logo.View', 'FWCExtras', 'object', function (context) {
          //console.log("Context console log for Header Logo View: " + JSON.stringify(context));
          return {
            alternateLogo
          };
        })
      }
    }
  }
});
e
Two observations, I would add the full logic segment (promises) under addToViewContexDefinition, or create a separate function for that logic and call it under addToViewContextDefinition. Second, I think you might be missing a property name/key for the object you are returning. Other than that it looks correct to me, I would just return a boolean for testing purposes and display it on the template.
k
What do you mean by full logic segment? Do you have a reference in the docs?
e
What I mean is to move all the logic you have for returning the
alternateLogo
inside the addToViewContextDefinition, if not you will always return false. I do not think there is docs for that, it is more understanding that you have a promise that will not be resolved by the time you return your value.
k
mountToApp: function (container) {
var Layout = container.getComponent("Layout"); if (Layout) { Layout.addToViewContextDefinition( "Header.Logo.View", "FWCExtras", "object", function (context) { //console.log("Context console log for Header Logo View: " + JSON.stringify(context)); var fwc, alternateLogo = false, userProfile = container.getComponent('UserProfile'); if (userProfile) { userProfile.getCustomerSegments().then(function (customerSegments) { for (i = 0; i < customerSegments.length; i++) { console.log("Customer Segment ID: " + customerSegments[i].id); if (customerSegments[i].id == '1338793') { console.log("Cutomer segment is equal to 1338793, setting alternateLogo boolean to true"); alternateLogo = true; } } }); fwc = { alternateLogo } return fwc; } return {}; } ); } }
@eminero Like this, correct? Still having some difficulties with it. It seems to work intermittently? Which is odd...