CPQ integration with Salesforce B2B Commerce
Summarize
Summary of CPQ Integration with Salesforce B2B Commerce
This guide provides step-by-step instructions for configuring Configure Price Quote (CPQ) to work with Salesforce B2B Commerce. It is essential for users to have Commerce enabled, the CPQ Base Managed Package installed, and appropriate administrative access to follow the setup process effectively.
Show less
Prerequisites
- Commerce must be enabled in Salesforce.
- The CPQ Base Managed Package should be installed.
- System Administrator or similar access is required.
Installation Steps
Download and install the Salesforce Command Line Interface (CLI) if not already installed. Then follow these steps:
- Extract the logik-b2b.zip file containing components for integration.
- Navigate to the directory of extracted files via command line.
- Run the command to authenticate and log into Salesforce.
- Deploy the source using the provided command, confirming success.
Post-installation Setup
After installation, complete the following tasks:
- Configure Field Level Security for the Cart Item and Product2 fields to ensure visibility for relevant profiles.
- Set up the Runtime Client Token in Salesforce's Custom Settings by copying the token from Logik.
- Enable Visualforce page access for the store's administration settings.
- Configure the Experience Builder to add custom components or variations as needed.
Add to Cart API Endpoint
The Add to Cart API enables users to manage cart items effectively:
- POST: To add items to the active cart or create a new cart.
- PATCH: To add items to a specified cart.
Required parameters include configurableProductId, configurationId, webstoreId, and effectiveAccountId.
Key Outcomes
Upon successful configuration, users can seamlessly integrate CPQ with Salesforce B2B Commerce, enhancing the ability to manage product configurations and streamline the purchasing process. This integration facilitates a more efficient sales workflow, ensuring better customer experiences and operational efficiency.
Learn how to configure CPQ to work with Salesforce B2B Commerce.
Prerequisites
This guide assumes the following:
- Commerce is enabled in Salesforce
- The CPQ Base Managed Package is installed
- System Administrator or similar access is available in order to perform the steps listed
Install files to Salesforce
- If it isn't already installed, download and install the Salesforce Command Line Interface (CLI) using the instructions here:
- Download and extract the logik-b2b.zip file, which contains the components used for the B2B integration, from github.com.
- On Mac, double-click the file. Its contents will be extracted automatically in the same location.
- On Windows, right-click and select Extract All". Follow the prompts that appear on screen.
a. refer the following:
- Start Terminal (Mac or Linux) or Powershell (Windows).
- Navigate to the directory containing the extracted files. For example, if the files were extracted in the Downloads folder, type and enter the command
cd Downloads/logik-b2b. - Run the
lscommand to see a list of files and folders in that directory.You should see
srcandsfdx-project.json, as well as a plain text copy of this guide. - Run the following command, making the changes indicated just below:
sfdx auth:web:login --setalias myOrg -r https://example-dev-ed.my .salesforce.com- Replace the URL following
-rwith the one that the Logik-B2B integration will be set up on. - The text following
--setaliasis a nickname that is used to identify and reference the correct Salesforce org. The examplemyOrgwill be used for the purposes of this guide. Be sure to use your own alias in the following steps.
The URL specified in the previous login command will be opened in the default browser.
- Replace the URL following
- Log in and authorize the "Salesforce CLI" connected app.
- In the command line, run the command
sfdx force:source:deploy -p src -u myOrg.After a few moments, the command line will return a confirmation message, "Deploy Succeeded."
If the Salesforce org isnʼt already open in a browser, it can be opened by running the command
sfdx force:org:open -u myOrg.
Post-installation setup in Salesforce
You must complete the following steps after installing the components to Salesforce.
Setting Field Level Security:
- From Setup Home, go to the Object Manager tab, or navigate to Objects and Fields > Object Manager.
- From Object Manager, search for and open Cart Item (CartItem).
- Go to Fields & Relationships. Search for and open the field Configuration Id (ConfigurationId__c).
- Click Set Field-Level Security.
- Make sure the Visible option is selected and Read-Only is not selected for profiles that will be configuring products in Commerce, and then click Save.
A similar set of steps need to be followed for a Product2 field.
- From Object Manager, search for and open Product (Product2).
- Go to Fields & Relationships. Open the field CPQ Enabled (LGK__IsConfigurable__c).
- Click “Set Field-Level Security”. Make sure the Visible option is selected for any shopper profiles. Read-Only can either be enabled or disabled.
- Save.
More field level security permissions are required if using the Add to Cart API. First, from Object Managed, search for and open Configuration Line Item (LGK ConfigurationLineItem c). Then, make sure shopper profiles have Field-Level Security to Visible for the following fields:
- Quantity
- ProductId
- Price
- ConfigurationId
- Type
In addition, the following CartItem fields will need to be set to Visible (Read-Only must not be checked):
- ConfigurationId (this should already be done for the UI integration)
- Quantity
- ProductId
- Price
- Type
Obtaining and applying the runtime token
-
In Logik, create a Runtime Client, with an Origin matching the Logik base URL. Click Copy to get the client token.
- In Salesforce, from Setup home, go to Custom Code > Custom Settings.
-
For Logik Tenant, click Manage.
-
If settings already exist, click “Edit”. Otherwise, click “New” above the “Default Organization Level Value” header.
-
For the Runtime Client Token field, paste the copied token for the runtime client. Make sure the URL field(s) are set to the same URL as one of the runtime clientʼs Origins in CPQ Admin.
- Save.
Setting Visualforce page access
- From Setup home, go to Feature Settings > Digital Experiences > All Sites.
-
For your store, click Workspaces.
-
Go to Administration > Pages > Go to Salesforce Platform for Application Development.
- Under “Site Visualforce Pages”, click Edit.
-
Move
commerceConfigurationWindowfrom Available to Enabled and save.
Configuring the Experience Builder
- From the Commerce home page, open Experience Builder.
-
Click Home on the top left to open the list of pages. Search or navigate to Product and click Product Detail. Either add the custom Logik button to the existing Product Detail page, or use the packaged page as a variation.
- To add the button to an existing page:
- Click the lightning bolt on the left and go to Custom Components (the last section in the list).
-
Drag the Configurator from the list and move it to where you want it in the layout.
- To use the packaged page as a variation:
- Reopen the page navigation menu on the top left.
- On the Product Detail option, click the three dots and go to the Page Variations tab.
-
Click New Page Variation and choose “Configurable Product Detail” as the layout.
- Give the variation a name and click Create.
- To add the button to an existing page:
Add to Cart API
Endpoint: /services/apexrest/add-to-cart
Methods: Receives and returns application/json
POST: Use to add items to the currently active cart. (If a cart is not active, a cart is created.) Requires the following:
configurableProductIdconfigurationIdwebstoreIdeffectiveAccountId
webstoreId and effectiveAccountId are part of Salesforce Commerceʼs standard APIs, so that information should be readily available to users.configurableProductId and
configurationId must correspond to the same configurable product.
configurableProductIdconfigurationIdcartId
Response: an array of cart item (CartItem) records.
Example request (create new quote):
{
"configurableProductId": "01t8a0000061GQPAA2",
"configurationId": "7e45beb9-790c-46ef-a05f-9195718bcda7",
"effectiveAccountId": "0018a00001nsFoNAAU",
"webstoreId": "0ZE8a000000XwckGAC"
}
Example request (add to existing quote):
{
"configurableProductId": "01t8a0000061GQPAA2",
"configurationId": "7e45beb9-790c-46ef-a05f-9195718bcda7",
"cartId": "0a68a000000kXQeAAM"
}
Example response:
[
{
"attributes": {
"type": "CartItem",
"url": "/services/data/v56.0/sobjects/CartItem/0a98a000000kWtlAAE"
},
"CartId": "0a68a000000kXDsAAM",
"Product2Id": "01t8a0000061GQPAA2",
"Type": "Product",
"CartDeliveryGroupId": "0a78a000000kWwxAAE",
"SalesPrice": 10000.00,
"UnitAdjustedPrice": 10000.00,
"TotalLineAmount": 10000.00,
"TotalPrice": 10000.00,
"TotalPriceAfterAllAdjustments": 10000.00,
"LGK__ConfigurationId__c": "7e45beb9-790c-46ef-a05f-9195718bcda7",
"Name": "LGK Machine",
"Id": "0a98a000000kWtlAAE"
},
{
"attributes": {
"type": "CartItem",
"url": "/services/data/v56.0/sobjects/CartItem/0a98a000000kWtkAAE"
},
"CartId": "0a68a000000kXDsAAM",
"Product2Id": "01t8a0000061GQOAA2",
"Type": "Product",
"CartDeliveryGroupId": "0a78a000000kWwxAAE",
"Quantity": 1.00,
"SalesPrice": 0.00,
"UnitAdjustedPrice": 0.00,
"TotalLineAmount": 0.00,
"TotalPrice": 0.00,
"TotalPriceAfterAllAdjustments": 0.00,
"Name": "Warranty",
"Id": "0a98a000000kWtkAAE"
},
{
"attributes": {
"type": "CartItem",
"url": "/services/data/v56.0/sobjects/CartItem/0a98a000000kWtjAAE"
},
"CartId": "0a68a000000kXDsAAM",
"Product2Id": "01t8a0000061GQKAA2",
"Type": "Product",
"CartDeliveryGroupId": "0a78a000000kWwxAAE",
"Quantity": 1.00,
"SalesPrice": 0.00,
"UnitAdjustedPrice": 0.00,
"TotalLineAmount": 0.00,
"TotalPrice": 0.00,
"TotalPriceAfterAllAdjustments": 0.00,
"Name": "1.5T Magnet",
"Id": "0a98a000000kWtjAAE"
},
{
"attributes": {
"type": "CartItem",
"url": "/services/data/v56.0/sobjects/CartItem/0a98a000000kWtiAAE"
},
"CartId": "0a68a000000kXDsAAM",
"Product2Id": "01t8a0000061GQGAA2",
"Type": "Product",
"CartDeliveryGroupId": "0a78a000000kWwxAAE",
"Quantity": 1.00,
"SalesPrice": 1.50,
"UnitAdjustedPrice": 1.50,
"TotalLineAmount": 1.50,
"TotalPrice": 1.50,
"TotalPriceAfterAllAdjustments": 1.50,
"Name": "MRI Platform Table",
"Id": "0a98a000000kWtiAAE"
},
{
"attributes": {
"type": "CartItem",
"url": "/services/data/v56.0/sobjects/CartItem/0a98a000000kWthAAE"
},
"CartId": "0a68a000000kXDsAAM",
"Product2Id": "01t8a0000061GQLAA2",
"Type": "Product",
"CartDeliveryGroupId": "0a78a000000kWwxAAE",
"Quantity": 1.00,
"SalesPrice": 2.50,
"UnitAdjustedPrice": 2.50,
"TotalLineAmount": 2.50,
"TotalPrice": 2.50,
"TotalPriceAfterAllAdjustments": 2.50,
"Name": "MRI Scanner",
"Id": "0a98a000000kWthAAE"
},
{
"attributes": {
"type": "CartItem",
"url": "/services/data/v56.0/sobjects/CartItem/0a98a000000kWtgAAE"
},
"CartId": "0a68a000000kXDsAAM",
"Product2Id": "01t8a0000061GQRAA2",
"Type": "Product",
"CartDeliveryGroupId": "0a78a000000kWwxAAE",
"Quantity": 25.00,
"SalesPrice": 1.00,
"UnitAdjustedPrice": 1.00,
"TotalLineAmount": 1.00,
"TotalPrice": 1.00,
"TotalPriceAfterAllAdjustments": 1.00,
"Name": "MRI Gradient Coils",
"Id": "0a98a000000kWtgAAE"
},
{
"attributes": {
"type": "CartItem",
"url": "/services/data/v56.0/sobjects/CartItem/0a98a000000kWtfAAE"
},
"CartId": "0a68a000000kXDsAAM",
"Product2Id": "01t8a0000061GQHAA2",
"Type": "Product",
"CartDeliveryGroupId": "0a78a000000kWwxAAE",
"Quantity": 25.00,
"SalesPrice": 3.00,
"UnitAdjustedPrice": 3.00,
"TotalLineAmount": 3.00,
"TotalPrice": 3.00,
"TotalPriceAfterAllAdjustments": 3.00,
"Name": "MRI Radio Frequency Coils",
"Id": "0a98a000000kWtfAAE"
}
]