Search code examples
sap-commerce-cloudspartacus-storefront

Add new Cms PageType "VendorPage"


Is there an easy way to add the PageType "VendorPage" to Spartacus?

Our Use case: We are using the marketplace extension in Hybris, which adds the VendorPage PageType. We now created a VendorPage Template (which is restricted to the VendorPage type) that makes it possible to create multiple vendor pages in SmartEdit. We want to access those pages via a URL that's something like: /vendor/vendorName. However, Spartacus always trys to fetch a ContentPage by default:

/cms/pages?fields=DEFAULT&pageType=ContentPage&pageLabelOrId=/vendor/vendorName

I investigated and found the router reducer, where the matching to the PageType takes place

if (params['productCode']) {
        context = { id: params['productCode'], type: PageType.PRODUCT_PAGE };
      } else if (params['categoryCode']) {
        context = { id: params['categoryCode'], type: PageType.CATEGORY_PAGE };
      } else if (params['brandCode']) {
        context = { id: params['brandCode'], type: PageType.CATEGORY_PAGE };
      } else if (state.data.pageLabel !== undefined) {
        context = { id: state.data.pageLabel, type: PageType.CONTENT_PAGE };
      } else if (!context) {
        ....

I then tried to replace this "CustomSerializer" in our application but then had to also define a custom "PageContext" type which lead to a "CmsActivatedRouteSnapshot" and at one point I got stuck because I landed in the state ngRx RouterState definition.

Am I going about this all wrong? Is there an easier way to add a new Cms PageType in Spartacus? Or maybe there is another way to achieve what we need?


Solution

  • I am not sure that it's still actual for you ...

    Currently the logic for detecting the pageType by route is hardcoded in the CustomSerializer class.

    Yes, you are right in theory, to override the logic of detecting pageType we just need to provide self implemented CustomSerializer class for RouterStateSerializer, but I honestly believe that it impossible for now.

    By the way, Spartacus team already has an issue about this problem, you can find more details here https://github.com/SAP/spartacus/issues/7187.