使用 HTTP post:
URI: https://{{host}}/occ/v2/{{storefront}}/cms/components
负载的例子:
{ "idList": [ "{{componentId1}}", "{{componentId2}}", ... ] }
要批量返回多个CMS组件数据,您可以使用SAP Commerce Cloud的CMS API中提供的以下方法:
使用 FlexibleSearch 查询 API
FlexibleSearch API 是一个灵活的查询API,可以使用它来检索CMS组件的数据。您可以使用以下步骤来批量返回多个CMS组件数据:
构建 FlexibleSearch 查询,以检索您需要的CMS组件数据。
使用 FlexibleSearchService API 执行查询,以检索符合查询条件的所有 CMS 组件数据。
遍历结果列表并获取每个组件的属性和值。
以下是示例代码:
String query = "SELECT {c.pk} FROM {CMSComponent AS c WHERE {c.catalogVersion} = ?catalogVersion}"; Map<String, Object> queryParams = new HashMap<>(); queryParams.put("catalogVersion", catalogVersionService.getCatalogVersion("yourCatalogVersion", "yourCatalogId")); final SearchResult<CMSComponentModel> searchResult = flexibleSearchService.search(query, queryParams); List<CMSComponentModel> components = searchResult.getResult(); for (CMSComponentModel component : components) { String name = component.getName(); String typeCode = component.getItemtype(); // ... }
使用 CMSComponentService 查询 API
另一个可行的方法是使用 CMSComponentService API。您可以使用以下步骤来批量返回多个CMS组件数据:
构建 CMSComponentType 以指定要检索的CMS组件类型。
调用 CMSComponentService API 的 getComponentsForType 方法,并传递 CMSComponentType 作为参数。
获取返回的CMS组件列表并遍历它们,以获取每个组件的属性和值。
以下是示例代码:
CMSComponentType type = cmsComponentService.getCMSType("yourComponentTypeCode"); List<CMSComponent> components = cmsComponentService.getComponentsForType(type); for (CMSComponent component : components) { String name = component.getName(); String typeCode = component.getItemtype(); // ... }
使用CMS Component Web Service是通过OCC API批量检索CMS组件数据的一种简单方法。您可以使用以下步骤来批量返回多个CMS组件数据:
构建带有catalogVersion参数的URL,以指定要检索的CMS组件所属的目录版本。
调用CMS Component Web Service并传递URL作为参数。
获取返回的CMS组件列表并遍历它们,以获取每个组件的属性和值。
以下是示例代码:
String catalogVersion = "yourCatalogVersion"; String url = "/cmscomponents?catalogId=yourCatalogId&catalogVersion=" + catalogVersion; List<CMSComponentData> components = commerceWebService.get(url, new TypeReference<List<CMSComponentData>>() {}); for (CMSComponentData component : components) { String name = component.getName(); String typeCode = component.getTypeCode(); // ... }
无论您选择哪种方法,都应该先熟悉 SAP Commerce Cloud 的 CMS API 文档,并根据您的具体需求调整查询条件和方法参数。