DEV Community

Cover image for Custom Site Preferences and Custom Global Preferences in SFRA 📝
DanieleAurilio
DanieleAurilio

Posted on

Custom Site Preferences and Custom Global Preferences in SFRA 📝

INTRO

How many times do you have thought where you can store properties about configurations? Salesforce Commerce Cloud provides Site and Global Custom Preferences where we can store properties divided into groups. Global Custom preferences affect all sites instead Site Preferences affect only site where it's configurated.
Store properties in preferences allows us retrive it every time we need.
Setting a site custom preferences or a global custom preferences is practically the same. We are going to set up a group that contains properties that we will then use within our app.

LET’S SET UP A CUSTOM PREFERENCES 💾

If you don’t have system-objecttype-extensions.xml file you must create it under sites/sites_template/meta/.

Initialize xml and create a xml node <type-extensions type-id=“SitePreferences”> </type-extensions>.
In <type-extensions type-id=“SitePreferences”> </type-extensions> we can crate other two xml nodes called <custom-attribute-definitions> </custom-attribute-definitions> and <group-definitions> </group-definitions>.

  • In <custom-attribute-definitions> </custom-attribute-definitions> we can define our custom attribute

  • In <group-definitions> </group-definitions> we can create <attribute-group group-id="SiteCustomAttributeGroupID"> which contain <display-name xml:lang="x-default">Site Custom Attribute Group</display-name> and <attribute attribute-id="SiteCustomAttributeID" /> refers to attribute-id which I specified earlier.

image

Now we can upload system-objecttype-extensions.xml in business manager under Administration -> Site Development -> Site Import & Export.

After uploaded xml you can find your site custom preferences in Business Manager under Merchant Tools -> Site Preferences -> Custom Preferences.

Now you can access to preferences value through:

dw.system.Site.getCurrent().getCustomPreferenceValue('SiteCustomAttributeID’);

But how i explained earlier you can create also a Global Custom Preferences, but the unique difference is in <type-extensions type-id=“SitePreferences”> </type-extensions>, you have to replace type-id=“SitePreferences” with type-id="OrganizationPreferences".

And you can find your Global Custom Preferences in Business Manager under Administration -> Global Preferences -> Custom Preferences.

Discussion (0)