SmartEdit
SmartEdit is a content management system that facilitates the creation and management of content within the SAP Commerce Cloud environment. It was once hailed as a versatile tool capable of handling various content-related tasks. Its strengths lay in its tight integration with SAP's data model, allowing users to effortlessly access product data, images, and categories to enrich their content. This seamless connection reduced the need for complex data feeds throughout the architecture.
Read more
Check the Content Management System Overview to learn more about the features of the SmartEdit module.
Bootstrapping SmartEdit with Alokai Storefront
To use the SmartEdit integration in your Storefront, perform the following steps:
1
Install the module
From the root of your Storefront project, run the following command:
npx @vsf-enterprise/storefront-cli add-module cms-smartedit
Follow the instructions in the command line to complete the installation. The command will:
- install the Alokai SmartEdit API Client
@vsf-enterprise/smartedit-api
in the Middleware, - install the Alokai SmartEdit SDK module
@vsf-enterprise/smarttedit-sdk
in the Storefront, - copy the
webApplicationInjector.js
file to the Storefrontpublic
directory
You can find the changelogs for the installed packages here.
2
Update configuration
In the apps/storefront-middleware/sf-modules/cms-smartedit/config.ts
file, you need to update the api
object with your SAP Commerce Cloud's API configuration:
export const config = {
location: "@vsf-enterprise/smartedit-api/server",
configuration: {
api: {
uri: SAPCC_API_URI,
- baseSiteId: "apparel-uk",
+ baseSiteId: "<your-base-site-id>",
- catalogId: "apparelProductCatalog",
+ catalogId: "<your-catalog-id>",
- catalogVersion: "Online",
+ catalogVersion: "<your-catalog-version>",
- defaultLanguage: "en",
+ defaultLanguage: "<your-default-language>",
- defaultCurrency: "USD",
+ defaultCurrency: "<your-default-currency>",
},
unified: {
// ...
},
},
} satisfies Integration<MiddlewareConfig>;
Bootstrapping SmartEdit
Before you start using our SmartEdit integration, you need to install Alokai extension into your SAP Commerce Cloud. The extension will install component types for our out-of-the-box frontend components.
Installing extension
Requirements:
- SAP Commerce (Hybris) version 2211.24 or later
- SmartEdit using Angular version 17
- Deployment type codes available with the number 19968 Data Types
1
Copy extension files to the bin/custom directory.
2
Add the alokaismartedit extension to config/localextensions.xml
:
<extension dir="${HYBRIS_BIN_DIR}/custom/alokaismartedit"/>
3
Build
cd bin/platform
. ./setantenv.sh
ant clean all
ant updatesystem
Enabling Live Preview
Alokai module for SmartEdit ships with an out-of-the-box support for the Live Preview feature. The moment you start editing a page in SmartEdit, the following happens:
1
Loading the preview route
SmartEdit loads your Storefront within an iframe. The loaded URL consists of:
- the WCMS > Website > Website-ID > WCMS Properties > WCMS Cockpit Preview URL setting in Backoffice,
- the storefrontPreviewRoute setting in SmartEdit,
- a preview token passed as the cmsTicketId query param
Configuration required
We recommend setting WCMS Cockpit Preview URL to either http://localhost:3000 (Next) or http://localhost:3333 (Nuxt) and storefrontPreviewRoute to cx-preview (default).
As a result, example loaded URL looks like this:
http://localhost:3000/cx-preview?cmsTicketId=<preview-token>
2
Redirecting to a proper Storefront route
The cx-preview page component extracts value of the preview token from the cmsTicketId query param and uses it to fetch the currently edited page data from SmartEdit. Then it uses the label property to redirect to a correct Storefront page.
For example, when the currently edited SmartEdit page has label equal to test, the /test Storefront route will be loaded.
Nested page labels (e.g. /example/nested/label) are supported as well.
3
Rendering the currently edited page
The loaded Storefront route handler fetches the page data from SmartEdit and renders it using the RenderCmsContent wrapper. It fulfills the HTML Markup Contract by adding properties recognized by SmartEdit to HTML elements representing slots and components.
<div
class="smartEditComponent"
data-smartedit-component-type="SimpleResponsiveBannerComponent"
data-smartedit-component-id="ApparelUKHompageSplashBannerComponent"
data-smartedit-component-uuid="somecompositekeyserialization"
data-smartedit-catalog-version-uuid="apparel-deContentCatalog/Staged"
>
<!-- component code -->
</div>
4
Initializing the Live Preview
Finally, the loaded Storefront route calls the initLivePreview() utility provided by our SmartEdit SDK module. As a result, the webApplicationInjector.js script is loaded and the page becomes editable.
sdk.smartedit.utils.initLivePreview({
page,
allowedOrigins: ['your-sap-environment-uri-and-port'],
});
Configuration required
Make sure you are calling initLivePreview() with correct allowedOrigins to avoid CORS issues. If the webApplicationInjector.js script provided by Alokai does not work with your SmartEdit environment, replace it with your version. If you moved the script outside of the /public directory, call initLivePreview() with correct scriptSrc.
Setting up Page Templates
Storefront code is designed to work out-of-the-box with three custom Page Templates:
- a dynamic page template for fully-dynamic CMS pages,
- a category page template for category pages enhanced with CMS content,
- a product page template for product pages enhanced with CMS content.
To use these templates, you need to create them in your SmartEdit environment:
1
Create a new page template in SmartEdit
In the SAP Commerce Cloud Back office, navigate to the Page Template
page. Then click a +
button to create a new page template.
2
Define the slots
In the newly created page template, specify the slots where you can add components. For dynamic page, you should add:
componentsAboveFold
for components above the fold,componentsBelowFold
for components which should be lazy-loaded.
For category page, you should add:
componentsTop
for components above the product list,componentsBottom
for components below the product list.
For product page, you should add:
componentsBottom
for components below the main product data.
3
Add valid component types
For each slot, add all the Alokai component types in Valid Component Types
field.
4
Change the template name
As all the page templates are named Page Template
by default, you should change the name in the Administration
tab to be able to distinguish them in the SmartEdit.
5
Add the template to the page type
In the Page Type
page, add the newly created template to the Content Page
in Common
-> Restricted Page Templates
field.