Setup Salesforce b2b commerce cloud for practice
We will setup Salesforce b2b commerce in my developer org, on which I have enabled Dev Hub so that we can create a new scratch org.
What is Dev Hub?
Dev Hub consists of objects with permissions that let administrators manage the level of access that a user and an org can have. When creating an unlocked package that you plan to distribute to other org, dev org is best option as it will ensure that your package is owned by an active org.
Dev Hub available in: Developer, Enterprise, Performance, and Unlimited Editions
Scratch orgs available in: Developer, Enterprise, Group, and Professional Editions
How to enable Dev Hub?
1. Use the System Administrator login to access your trial, Developer Edition, or production org.
2. From Setup, enter Dev Hub in the Quick Find box and select Dev Hub.
3. If you don't see Dev Hub in the Setup menu, make sure that your org is one of the supported editions.
4. To enable Dev Hub, click Enable.
Note: After you enable Dev Hub, you can’t disable it.
Note: You can’t enable Dev Hub in a sandbox. You can use either Production or developer or trail org.
Setup Steps
1. Clone the whole b2b-commerce-for-lightning repository
This will create a copy of github project in your system, which has many shell scripts which we will be run to setup our org with b2b commerce.
git clone https://github.com/forcedotcom/b2b-commerce-on-lightning-quickstart.git
2. cd to sfdx folder and execute following script, that will convert the examples from the metadata API format to the SFDX format and add them to the "path" you have specified in the sfdx-project.json file.
./convert-examples-to-sfdx.sh
The contents of the./convert-examples-to-sfdx.sh file have been modified somewhat since several keywords were deprecated. If you receive any error then just copy & paste following in that file.
convert-examples-to-sfdx.sh
#!/bin/bash
# Use this command to create a new store.
# The name of the store can be passed as a parameter.
export SF_NPM_REGISTRY="http://platform-cli-registry.eng.sfdc.net:4880/"
export SF_S3_HOST="http://platform-cli-s3.eng.sfdc.net:9000/sfdx/media/salesforce-cli"
#templateName="b2c-lite-storefront"
templateName="B2B Commerce"
function echo_attention() {
local green='\033[0;32m'
local no_color='\033[0m'
echo -e "${green}$1${no_color}"
}
storename=""
function error_and_exit() {
echo "$1"
exit 1
}
if [ -z "$1" ]
then
echo "A new store will be created... Please enter the name of the store (alphanumeric characters only): "
read storename
else
storename=$1
fi
sfdx force:community:create --name "$storename" --templatename "B2B Commerce (LWR)" --urlpathprefix "$storename" --description "Store $storename created by Quick Start script."
echo ""
storeId=""
while [ -z "${storeId}" ];
do
echo_attention "Store not yet created, waiting 10 seconds..."
storeId=$(sfdx force:data:soql:query -q "SELECT Id FROM WebStore WHERE Name='${storename}' LIMIT 1" -r csv |tail -n +2)
sleep 10
done
echo ""
echo_attention "Store found with id ${storeId}"
echo ""
echo_attention "Pushing store sources..."
set -x
sfdx force:source:push -f
set +x
echo ""
echo_attention "Setting up the store and creating the buyer user..."
# Cleaning up if a previous run failed
rm -rf experience-bundle-package
./quickstart-setup-store.sh "${storename}" || error_and_exit "Store setup failed."
3. If you don't have a dev hub already authorized, do that now by running
sfdx force:auth:web:login -d
4. Run the following command to create a scratch org and specify the username for the administrator in an email format:
The existing settings in the project-scratch-def.json file will enable all the necessary licenses and org perms and prefs required for Lightning B2B. If the scratch org creation is successful you should not need to modify any org perms or prefs. This is only available for the scratch orgs though, and will not work for developer edition orgs, sandboxes or other environments. For those orgs, follow the B2B Commerce on Lightning Experience Setup Guide.
The contents of the project-scratch-def.json file have been modified somewhat since several keywords were wrong. If you receive any error then just copy & paste following in that file.
project-scratch-def.json
{
"orgName": "My Test B2B Company",
"edition": "Developer",
"features": ["Communities", "B2BCommerce", "OrderManagement", "EnableSetPasswordInApi"],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
},
"experienceBundleSettings": {
"enableExperienceBundleMetadata": true
},
"communitiesSettings": {
"enableNetworksEnabled": true
},
"orderManagementSettings": {
"enableOrderManagement": true
},
"orderSettings": {
"enableOrders": true,
"enableEnhancedCommerceOrders": true,
"enableOptionalPricebook": true
}
}
}
Now Execute following script
sf org create scratch --definition-file config/scratch-def.json --alias <MyScratchOrg> --target-dev-hub <alias given during authenticating DevHub org> --no-namespace --set-default
Example:
sf org create scratch --definition-file config/project-scratch-def.json --alias B2BScratchOrg --target-dev-hub B2BCloud --no-namespace --set-default
A password for your user is auto-generated but it's hidden.
After execution of script you will receive following on cmd:
5. Open Scratch org
sfdx force:org:open
Note: if that fails, you might need to first set that new scratch org as your default org with
sfdx force:org:open sfdx force:config:set defaultusername=<YourScratchOrgUsernameInEmailFormat>
6. Create and set up a new store in your new scratch org using shell script
./quickstart-create-and-setup-store.sh
After this step you can use command on step5 to login to your newly created scratch org and visit setup > store to view your configured store with all dummy products, categories, catalogs and more.
This script will perform following
- register the Apex classes needed for checkout integrations and map them to your store
- associate the clone of the checkout flow to the checkout component in your store
- add the Customer Community Plus Profile clone to the list of members for the store
- import Products and necessary related store data in order to get you started
- create a Buyer User and attach a Buyer Profile to it
- create a Buyer Account and add it to the relevant Buyer Group
- add Contact Point Addresses for Shipping and Billing to your new buyer Account
- activate the store
- publish your store so that the changes are reflected
- build the search index for your store
- set a password for the new Buyer User and display the user details (including user name and password)
- setup Guest Browsing by default for B2C stores
If you have used Above steps to setup your store, the name of your Buyer Group will be "BUYERGROUP_FROM_QUICKSTART_1".

Comments
Post a Comment