Reputation: 239
I have created a custom cms components that has a couple of custom attributes that I need to access in the spartacus storefront. in the API endpoint /cms/pages (PagesController) I just get a basic representation of this component, without the custom attributes.
"uid" : "sofortComponent",
"uuid" : "eyJpdGVtSWQiOiJzb2ZvcnRDb21wb25lbnQiLCJjYXRhbG9nSWQiOiJlbGVjdHJvbmljcy1zcGFDb250ZW50Q2F0YWxvZyIsImNhdGFsb2dWZXJzaW9uIjoiT25saW5lIn0=",
"typeCode" : "***APMComponent",
"modifiedtime" : "2020-11-24T13:02:05.847+01:00",
"name" : "SOFORT @",
"container" : "false",
"media" : {
"code" : "sofort-icon",
"mime" : "image/png",
"url" : "/medias/?context=bWFzdGVyfGltYWdlc3wxNzU0fGltYWdlL3BuZ3xpbWFnZXMvaGVlL2hkMy84Nzk3MzAyOTE1MTAyLnBuZ3w4MzMxNmEzNTFhODBkYzEzYzVmNmUxZjgzNzI2MzU0MGI3MzJlNjg1ZWQzZjlhY2FjMWMxNDNkNDUyOTEzODQ4"
}
}, {
"uid" : "creditCardComponent",
"uuid" : "eyJpdGVtSWQiOiJjcmVkaXRDYXJkQ29tcG9uZW50IiwiY2F0YWxvZ0lkIjoiZWxlY3Ryb25pY3Mtc3BhQ29udGVudENhdGFsb2ciLCJjYXRhbG9nVmVyc2lvbiI6Ik9ubGluZSJ9",
"typeCode" : "...",
"modifiedtime" : "2020-11-23T14:03:28.472+01:00",
"name" : "Credit Card",
"container" : "false"
}, ... ]
My component (sofortComponent) has an attribute that I want to populate, but I can't find any documentation on how to do this.
I've tried adding a populator to the cmsRenderingCmsItemConverterCustomPopulators
, but that doesn't allow me to add complex attributes to the model (strings yes, but complicated items no..) Or maybe I am doing it wrong.
Can anyone guide me to the docs or an example?
Upvotes: 1
Views: 1239
Reputation: 1260
The fields exposed in the OCC api are driven by so-called pre-configured sets. While the default resources have pre-configured sets associated, you need to create your pre-configured sets for new types. This is documentation, see https://help.sap.com/viewer/9d346683b0084da2938be8a285c0c27a/1808/en-US/8c404c5886691014a48c88f4a49f9bf3.html
The pre-configured sets are provided for BASIC, DEFAULT and FULL sets. If you do not request a specific field mapping, the OCC mapping that is configured for DEFAULT will be used. You can however specify the field mapping in the request, either by using one of the pre-configured sets or by naming out specific fields. Or a combination of both, i.e. FULL pre-configured + customer fields that are not part of the pre-configured set.
In Spartacus you can configure the field mapping, by providing an endpoint configuration. This is documented at https://sap.github.io/spartacus-docs/connecting-to-other-systems/#configuring-endpoints. This means that even if you do not have pre-configured sets at all in the backend, you should still be able to request the data.
Upvotes: 0
Reputation: 1221
backend.occ.endpoints.pages
= 'cms/pages?fields=...'
? See https://sap.github.io/spartacus-docs/connecting-to-other-systems/#configuring-endpointsOccCmsPageNormalizer
to map your new fields of the Occ model to the Spartacus UI model. See https://sap.github.io/spartacus-docs/connecting-to-other-systems/#extending-the-ui-modelUpvotes: 1