Customize B2B Store Components Using Open Source Components
Open source components provide editable source code for standard B2B store components. Using open source components, you can modify component functionality without building a new component from scratch.
The source code is available in a public Git repository. Clone the repository, customize and extend the components to meet your store requirements, and then deploy the updated versions to any B2B store using tools such as Salesforce Developer Experience (Salesforce DX) and Visual Studio Code (VS Code).
For detailed instructions on cloning and working with the open source components, see the README.md file in the Git repository.
We recommend you validate and test changes in a sandbox environment before deploying them to the production environment.
Note
Example Scenario: Personalize Product Pricing
A Commerce Admin wants to customize the Product Pricing Details component on a Product Details page to:
Display the currency as a code (for example, USD) instead of a symbol ($).
Highlight the main price in a specific color.
Display the percent difference between the main price and the strikethrough (original) price.
Using an open source component, a developer can implement these changes by modifying the existing component’s code rather than rebuilding the product pricing details component from scratch.
Code changes
Open the Product Pricing Details component in VS Code:
a. Pull the latest version of the component from your Salesforce org.
b. Open the productPricingDetails component.
Open the productPricingDetailsui.html file. This file contains the HTML markup for the Product Pricing Details component.
Change all pricing displays using “symbol” ($) to “code” (USD):
a. Find the text "currency-display-as="symbol".
b. Replace all the instances with “currency-display-as=”code”.
Update component code logic to show the percent difference between the main and strikethrough prices:
a. Calculate the percent difference in the productPricingDetailsui.js file. Add the following code to the JavaScript file to determine whether to display the percent difference and to calculate that difference:
1/**2* New:3* Determine whether to display percentage difference between the strikethrough price and main price.4* @type (boolean)5* @public6*/7get displayPercentageDifference(){8 // Display percentage if strikethrough price is higher than main price.9 return this.strikethroughPrice>this.mainPrice;10}11/**12* New:13* The percentage difference between the main price and strikethrough price.14* This value is calculated as: ((strikethroughPrice - mainPrice) / mainPrice * 100.15* @type (string)16* @public17*/18get percentageDifference(){19 if(this.mainPrice && this.strikethroughPrice){20 const percentage = ((this.strikethroughPrice - this.mainPrice) / this.mainPrice) * 100;21 return `${percentage.toFixed(0)}`; // whole number percentage22}23 return '0';24 //Default to ‘0%’ if prices are not set.25}
b. Format where the percent difference shows up in the productPricingDetailsui.html file. Add the following HTML to display the percent difference: