Add Custom Entity Field Data to the Profile Model: SCA

Post Featured Image

You can fetch customer entity custom fields by using the commerce API method getCustomFields() on the customer object.

define('UserCustomFields'
, [
    'Profile.Model'
  , 'SC.Models.Init'
  ]
, function
  (
    ProfileModel
  , ModelsInit
  )
{
  'use strict';

  ProfileModel.get = _.wrap(ProfileModel.get, function (fn)
  {
    var profile = fn.apply(this, _.toArray(arguments).slice(1));
    profile.customfields = ModelsInit.customer.getCustomFields();

    return profile;
  });
});

Update the modules object to include a path to your new module (eg "customizations/UserCustomFields": "1.0.0"), and also update the ssp-libraries : dependencies array to include the new file ("UserCustomFields").

As a reminder, if you want to surface a custom entity field onto the frontend, you must make sure that it is configured to appear in the web store.

To do this, edit the field and ensure that the Applies > Web Store and Applies > Customer checkboxes are checked.

Leave a comment

Your email address will not be published. Required fields are marked *