License is listed in the LICENSE file.
This sample covers on how to configure the custom user attributes in HQ and how to consume the same in E-Commerce.
License for starter kit is listed in the LICENSE .
Follow the instructions mentioned in document to set up the development environment.
Follow the instructions mentioned in document to create the custom theme
Create a theme folder with name fabrikam-extended.
Please refer the link for adding customer/user Attributes document
In this step we will clone the search result container module. Below is the CLI for cloning the core module yarn msdyn365 clone search-result-container custom-search-result-container
In this step we will extend the custom-search-result-container module definition file to add a data action to get customerInformation.
"dataActions": {
"customerInformation": {
"path": "@msdyn365-commerce-modules/retail-actions/dist/lib/get-customer"
}
},
Need to add customerInformation in custom-search-result-container.data.ts interface as shown below
export interface ICustomSearchResultContainerData {
customerInformation: AsyncResult<Customer>;
}
Go to custom-search-result-container.tsx under src/Modules/custom-search-result-container and add existing code in render functions to consume user attribute.
One usecase we have considered in this sample is to filter the age restricted products based on customer age.
In this sample to filter the product "92055 CASUAL CARDIGAN" we have configured customAttribute to "NoShow" and the customUserAttribute to "1985". so that we can filter the age restricted products based on customer age.
Add the below code in src\modules\custom-search-result-container\custom-search-result-container.tsx in render function to consume the user and product attributes for filtering the products.
const customer = this.props.data.customerInformation.result;
const custmerAttributes = (customer && customer.Attributes) || [];
const customUserAttribute = custmerAttributes.find(att => att.Name === "customUserAttribute");
const customerAge = customUserAttribute?.AttributeValue?.IntegerValue;
if(customerAge === 1985) {
products = products.filter(product => {
const productAttributeValues = product.AttributeValues;
const productCustomAttribute = productAttributeValues?.find(att => att.Name === "customAttribute")
if(productCustomAttribute?.TextValue === "NoShow") {
return false;
}
return true;
});
}
The sample can now be tested in a web browser using the yarn start
command.
Create a sample mock for signedIn user with name plp.json under the src/pageMocks. Use the sample PLP page mock located in src/PageMocks folder. Go to browser and copy paste the URL https://localhost:4000/page?mock=plp&theme=fabrikam-extended
Note : To verify using mock of search result container, find search-result-container module in mock and rename search-result-container to custom-search-result-container and change the themes to fabrikam-extended.
"siteTheme": "fabrikam-extended",
"pageTheme": "fabrikam-extended"
"typeName": "custom-search-result-container",
"id": "custom-search-result-container",
Before Applying Filter
Product with Customer attribute value and Product attribute value , which is configured from HQ is available on category page.Casual Cardigan product in below image is the example product.
After Applying Filter
Casual Cardigan product is filtered out in below image, based on Customer attribute value and Product attribute value so, not available on category page.
Integration test case for sample can be tested in browser using below steps
Set path to Add and consume custom user attributes sample level in command propmt and run yarn testcafe chrome .\test\custom-user-attribute-tests.ts -s .\
command.
ensure that testcafe is added globally to run test case.
The software may include third party images and videos that are for personal use only and may not be copied except as provided by Microsoft within the demo websites. You may install and use an unlimited number of copies of the demo websites., You may not publish, rent, lease, lend, or redistribute any images or videos without authorization from the rights holder, except and only to the extent that the applicable copyright law expressly permits doing so.
Please find below the reference sample which was implemented using the above approach. Role based caching Readme file