0
votes

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?

1
so I am not quite sure, 'what you really want to achieve' ? - Mafick
I want to my Spartacus-based application, for a route /vendor/:vendorName to send this request: /cms/pages?fields=DEFAULT&pageType=VendorPage&pageLabelOrId=vendorName and then display the result like any other page - Armin
Why not just use ContentPage, and just create a VendorTemplate in Hybris side? - geffchang
The reason was that when creating a new page in SmartEdit there is the option to create a VendorPage (because of the marketplace extension). It would have been weird for the user to have to find the vendor page template under "ContentPage" and not "VendorPage". We ended up using a ContentPage and hid the VendorPage option in SmartEdit. I would still be interested if there is a way to add a new pageType to Spartacus - Armin

1 Answers

0
votes

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.