Magidoc

Cloudshelf Connector for Salesforce B2C Commerce Cloud

The code for this connector is available on GitHub .

Abbreviations

For this document the following abbreviations are in place:

  • Salesforce B2C commerce cloud: SFCC
  • StoreFront Reference Architecture: SFRA
  • Business Manager: BM

Summary

This document provides general overview and technical instruction of installing of Salesforce Commerce Cloud (SFCC) LINK cartridge that lets you integrate Cloudhshelf with SFCC.

Overview

Cloudshelf cartridge (int_cloudshelf) for Salesforce B2C Commerce Cloud.

Cartridge allows to connect SFCC instance with Cloudshelf and includes the next functionalities:

  • Export products and catalogs from SFCC to Cloudshelf
  • Export stores from SFCC to Cloudshelf
  • Order management (transfer of the basket from Cloudshelf to the SFCC checkout by QR code)
  • Update order status on Cloudshelf API

The cartridge can be used by any new or existing SFCC retailer to be able to connect to Cloudshelf after simply installing the cartridge.

Compatibility

Cartridge is compatible with 6.3.0 and 7.0.0 SFRA version and Salesforce Commerce Cloud API version 24.1 (Compatibility Mode: 22.7)

Also required:

Implementation Guide

Prerequisites

#

Before installing cartridge on SFCC side make sure you have:

  • Account and API key created on Cloudshelf side - Getting Started
  • SFCC instance with setup site and product catalog
  • SFCC business user account

Installing cartridge

#

Complete the following steps to install the cartridge.

Initial Install

#

Clone repository to your computer.

Upload int_cloudshelf cartridge to your SFCC instance.

See the SFCC documentation for adding a cartridge to your storefront:

Cartridge does not contain any additional npm dependencies or client js script changes and can be simply uploaded to SFCC instance after receiving a copy of it.

Registering the Cartridge with Individual SFCC Sites

#

  1. Navigate to BM > Administration > Sites > Manage Sites > [SiteName] > Settings tab.
  2. Add ":int_cloudshelf" to the effective cartridge path.
  3. Click "Apply".

Registering the Cartridge Globally

#

  1. Navigate to Administration > Sites > Manage Sites
  2. Click on Manage the Business Manager site link
  3. Add ":int_cloudshelf"" to the effective cartridge path.
  4. Click "Apply".

Importing Metadata, Services and Jobs

#

Complete the following steps to import the Cloudshelf metadata, jobs and services.

  1. Navigate to BM > Administration > Site Development > Site Import & Export
  2. In the Upload Archive section
  3. Archive data/site_template folder from the repository and use it for upload
  4. Select Upload.
  5. On page reload select the site_template radio button
  6. Press Import Button

Depending on the SFCC environment you use, optionally it is possible to import separately metadata services and jobs.

  • Metadata files (files in data/site_template/meta folder) can be imported in BM > Administration > Site Development > Import & Export (first upload xml files then import Meta Data).
  • data/site_template/jobs.xml file can be uploaded and imported in BM > Administration > Operations > Import & Export (first upload xml files then import Jobs).
  • data/site_template/services.xml file can be uploaded and imported in BM > Administration > Operations > Import & Export (first upload xml files then import Services).

Setup

#

Configuring custom Site Preferences for Cloudshelf API key value is required. All other settings are optional.

Configuring Custom Site Preferences for API key

#

Complete the following steps.

  1. Navigate to Site > (select desired SFCC Site) > Site Preferences > Custom Preferences > Cloudshelf
  2. Select the appropriate Instance (Sandbox/Development, Staging, Production), and click Apply.
  3. Set the following using the value provided by your Cloudshelf representative: Cloudshelf API Key
  4. Click Apply.

The jobs run for every site they are assigned to. A site whose Cloudshelf API Key is empty is skipped: each job step writes one warning to the log and sends nothing to Cloudshelf for that site.

Custom Site Preferences Configurations

#

Other setting available in Navigate to Site > (select desired SFCC Site) > Site Preferences > Custom Preferences > Cloudshelf

Id
Name
Description
cloudshelfProductMetadataMapping
Product Metadata Mapping
JSON mapping of product attributes to cloudshelf product metadata properties . Key represents SFCC attribute, value cloudshelf key. Custom attribute must be specified with custom. prefix e.g. - {"custom.size": "size", "custom.badge": "symbol"}
cloudshelfCategoryMetadataMapping
Category Metadata Mapping
JSON mapping of category attributes to cloudshelf product group metadata properties . Key represents SFCC attribute, value cloudshelf key. Custom attribute must be specified with custom. prefix e.g. - {"custom.size": "size", "custom.badge": "symbol"}
cloudshelfStockLevelsToken
Stock Levels Token
Turns on live stock levels . Cloudshelf displays have to send this value to read stock from SFCC. Leave empty to keep live stock off.
cloudshelfStoreMetadataMapping
Store Metadata Mapping
JSON mapping of store attributes to cloudshelf location metadata properties . Key represents SFCC attribute, value cloudshelf key. Custom attribute must be specified with custom. prefix e.g. - {"phone": "mobile", "custom.badge": "symbol"}

#

Jobs & Schedule

#

In BM go to Administration > Operations > Jobs.

Two jobs are part of the initial cartridge setup

  • CloudshelfDataExportFull -- Full export of SFCC products and categories to cloudshelf. Also, exports SFCC stores marked with isCloudshelf flag to Cloudshelf system as locations
  • CloudshelfDataExportDelta -- Delta export of products data to Cloudshelf

For initial full products export simply click "Run" button of CloudshelfDataExportFull job. It will exports all sites products and categories to cloudshelf and create default theme and cloudshelf entities in cloudshelf system.

A full export also removes from Cloudshelf the products, variations and categories it no longer finds in SFCC, for example products or categories that were deleted or taken offline. Only what came from this cartridge is removed. A category that is still online in SFCC is kept even when it has no products; if Cloudshelf still holds products for it, they are cleared from the category. Removing a category leaves its products in Cloudshelf, and also removes any tile that shows the category on a Cloudshelf. This is controlled by the removeMissing parameter of the ProductExport step of the CloudshelfDataExportFull job:

  • ON (default) - remove them, unless more than half of the products in Cloudshelf would be removed. That usually means the search index was empty or being rebuilt when the export ran, so nothing is removed and an error is logged. The same limit applies to categories: when more than half of them would be removed, none are, and when more than half of the categories that hold products would be emptied, none are.
  • OFF - never remove anything.
  • NO_LIMIT - remove them however many there are. Use it for one run when a large part of the catalog really has been retired.

Nothing is removed when the export stops on an error before it has read the whole catalog. The custom-cloudshelf log lists every product, variation and category that is removed.

To export stores from SFCC to Cloudshelf as location go to BM > Merchant Tools > Online Marketing > Stores > [select store] > CLOUDSHELF Tab, set isCloudShelf to be "Yes" and click "Save"

Give every store a name. A store without one is sent to Cloudshelf with its ID as its name, and the log says so.

To change jobs configs in BM go to Administration > Operations > Jobs > select a specific job

  • In Schedule and History tab you can configure triggering interval for the job
  • In Job Steps tab you can select specific sites for which export should work
  • In Job Steps tab by selecting ProductExport step you can configure export mode (FULL or Delta)

Starting a sync from Cloudshelf

#

The jobs can also be started from the Cloudshelf Manager, with the same sync buttons other platforms use. A full sync starts CloudshelfDataExportFull and a partial sync starts CloudshelfDataExportDelta, so keep those two job IDs as they are imported. Scheduled runs and runs started in BM keep working as before.

Cloudshelf starts the jobs through the Salesforce Commerce API, so it needs an API client that is allowed to run jobs on your instance. Set it up once:

  1. In BM go to Administration > Site Development > Salesforce Commerce API Settings and note the Short Code and the Organization ID (for example f_ecom_zzxy_prd ).
  2. In Account Manager ( https://account.demandware.com ) go to API Client > Add API Client and fill in:
    • Display Name - for example "Cloudshelf sync" (40 characters at most).
    • Password and Confirm Password - this is the client secret. Keep it, it is not shown again.
    • Organizations - your organization.
    • Roles - click Add and select Salesforce Commerce API. The role then shows "No role scope defined": click the button on the role's row and select the instance whose jobs Cloudshelf should start.
    • Default Scopes and Allowed Scopes - sfcc.jobs.rw
    • Token Endpoint Auth Method - client_secret_basic

    Click Save and copy the new API Client ID from the list of API clients.

  3. In the Cloudshelf Manager open the Organization settings and fill in the Salesforce sync section: Short Code, Tenant ID (the Organization ID from step 1, with or without the f_ecom_ prefix), API Client ID and API Client Secret. Save.

The sync buttons are available once all four fields are filled in. If Salesforce does not start the job, the Cloudshelf Manager shows the reason, for example that the API client was not accepted or that the job is already running.

Both jobs report their progress to Cloudshelf while they run, however they were started, so the Cloudshelf Manager shows whether a sync is running, finished or failed. A status that cannot be reported is written to the custom-cloudshelf log as a warning and does not stop the export.

Live stock levels

#

Product exports tell Cloudshelf whether each variant is in stock at the time of the export. With live stock levels turned on, a display also asks SFCC for the current stock each time a shopper opens a product, shows it, and stops the purchase if the product has sold out since the last export.

The cartridge answers these requests at the Cloudshelf-StockLevels endpoint, in the format described in Real-Time Stock Levels .

To turn it on:

  1. In BM go to Site > (select desired SFCC Site) > Site Preferences > Custom Preferences > Cloudshelf and set Stock Levels Token to a long random value of your choice. While it is empty the endpoint answers every request with "not found".
  2. In the Cloudshelf Manager go to Organization settings and set:
    • Stock Level URL to https://<your storefront host>/on/demandware.store/Sites-<SiteID>-Site/default/Cloudshelf-StockLevels
    • Stock Level Auth Token to the same value as the Stock Levels Token.

What a display is told about a variant:

  • Online stock - the quantity available to sell in the inventory list assigned to the site. This is what a shopper can order.
  • Store stock - for each store with isCloudShelf set to "Yes" and an inventory list assigned, the quantity available to sell in that store's inventory list. A display in that store can show it as stock available there.
  • A perpetual inventory record is reported as 9999 available. So is a product with no inventory record in an inventory list that is set to in stock by default. With no record in any other list, 0 is reported.

Each request is written to the custom-cloudshelf log: the variant, the location asked about, what was answered and how long it took. Refused requests are logged as warnings with the reason, for example a missing or wrong token.

Logs

#

The cartridge writes to three logs. Send the first one, and the second if you have it, when you ask Cloudshelf for help with a sync.

Log
Where
What it holds
Job log
Logs/jobs/CloudshelfDataExportFull/ and Logs/jobs/CloudshelfDataExportDelta/ , one file for each run. It is also linked from the run in Administration > Operations > Jobs.
Everything one run did: its summaries, every problem and how the run ended.
custom-cloudshelf
Logs/custom-cloudshelf-*.log , one file for each day
The same lines for every run of the day, and the lines of the storefront controllers.
service-cloudshelf-graphql
Logs/service-cloudshelf-graphql-*.log , one file for each day
One entry for every request to Cloudshelf: how long it took, what was sent and what Cloudshelf answered.

What to look for in a job log:

  • Product export starting - the first line of the export, with the version of the cartridge that is running. The same version is sent to Cloudshelf with every request.
  • Product export summary - how many products and variations the run read and sent, and how many requests failed or were rejected.
  • Product export progress - written every 2,500 products while the export runs, with the same counts so far.
  • Errors - each one says what was being sent, with the first and last id, and why it failed. For example:
        
      
    A request that got no answer from Cloudshelf is sent once more before it counts as failed. When Cloudshelf answers with an error, the reason includes a traceId : quote it to Cloudshelf support.
  • The recap - when anything went wrong, the product export step ends with a warning that repeats the summary and lists the first 20 problems. The last screen of the step is then enough to see what happened.

What a failed request means for your data:

  • Products that were not sent are sent again by the next full export.
  • Variations that were not sent have their price and stock sent again by the next export, and everything else by the next full export.
  • A category whose products were not fully sent is sent once more in the same run. If that fails too, the category may show only part of its products and the Cloudshelf Manager shows a sync error. The next export, full or delta, then sends every category again, and so does each export after it until one has sent them all.
  • A product that is no longer in SFCC is kept in Cloudshelf while it still holds a variation that could not be moved to its new product. The log lists these products, and a later full export removes them.

Notes on what Salesforce writes:

  • Warnings and errors are always written. Summaries and progress are info lines. If they are missing from your logs, switch on Info for the instance in Administration > Operations > Custom Log Settings. They are few: a full export of 21,000 products in 44 categories writes about 90 lines, 19 KB.
  • Salesforce stops writing to a log file once it reaches 10 MB in a day. The cartridge keeps its logs short for that reason: the service log holds one line for a request and one for its answer, and the request and answer themselves are written, cut to 2,000 characters, only when something went wrong. With 21,000 products the service log grows by about 0.4 MB for a full export and 0.2 MB for a delta export.
  • If the service log still fills up, because the catalog is very large and the delta export runs often, switch off Communication Log Enabled for the cloudshelf.http.graphql service in Administration > Operations > Services. The job log and the custom-cloudshelf log do not depend on it.
  • For the full text of every answer from Cloudshelf, switch on Debug for the graphql log category on a sandbox. One export of a large catalog fills the log at that level, so switch it off again afterwards.

Order management

#

A shopper finishes a Cloudshelf purchase in your SFCC checkout. The display shows a QR code, the shopper scans it with their phone, and their basket opens in your storefront ready to pay.

How it works:

  1. The QR code holds a link to the cartridge's Cloudshelf-CreateBasket endpoint on your storefront. The link carries the products and quantities of the Cloudshelf basket.
  2. When the shopper opens the link, the cartridge adds those products to their SFCC basket with SFRA's standard add-to-cart and sends them to your checkout (Checkout-Begin ).
  3. The shopper pays in your checkout like any other order.

If the link is incomplete or a product cannot be added to the basket, the shopper lands on the storefront home page and a warning is written to the custom-cloudshelf log.

To set it up, add the Salesforce B2C Checkout plugin in the Cloudshelf Manager and give it the address of your storefront. Nothing else has to be set up in SFCC. The basket transfer does not use the Open Commerce API (OCAPI), so no OCAPI client and no OCAPI settings are needed.

Recognising Cloudshelf baskets

#

The cartridge sets two custom attributes on the basket it creates:

  • isCloudshelf - set to true.
  • cloudshelfData - JSON with the Cloudshelf basket ID, the IDs of the device, the Cloudshelf and the location, the ID of the sales assistant if one was assigned, and the products with their quantities.

Reporting order status to Cloudshelf

#

The CloudshelfOrderStatusUpdate job tells Cloudshelf when an order marked isCloudshelf has been paid or cancelled. It is imported without a schedule: set one in the Schedule and History tab of the job in Administration > Operations > Jobs.