SAP / spartacus-docs

Spartacus documentation published in GitHub Pages
Apache License 2.0
9 stars 22 forks source link

Can PageType be extended? #193

Closed gladius-mtl closed 5 years ago

gladius-mtl commented 5 years ago

This question (with some answers) came up in the public Spartacus Slack. Is this information covered in our documentation?

From Slack: https://spartacus-storefront.slack.com/archives/CD16V16FR/p1562243781288200

Alessandro Ruzzon [Jul 4th at 8:36 AM] architectural question: what is the purpose of the PageType defined in cms.model.ts file? Asking because it seems not extendable, and we may need in general different kinds of pages. 12 replies

Wei [11 days ago] It is used in many places. For example, if page is "ContentPage", we use "pageLabel" to load cms page data; if page is "ProductPage", we use product code.

Alessandro Ruzzon [11 days ago] is it intended to be extended in future? At the moment this is not possible. Thinking of a special page which may contain a specific item

Wei [11 days ago] Yes, it will be extended. PageType is defined in backend. To create a new page type, you have to create a cms item which extends AbstractPageModel, and in your impex data, insert the page data for that new type.

Alessandro Ruzzon [11 days ago] ok, but at the moment, for what i see, the whole logic behind the PageType is not extendable, in the Spartacus part. So, if I would need to have a new type of page that should contain specific details of an item, I should treat it as a normal content page. right?

Tobias Ouwejan [10 days ago] Page types are extendible in the backend as Wei said, but I would be happy to hear some good reason to go there. Ideally all pages are treated the same, currently only pdp and plp have specific treatment. This is because of their parameters (i.e. productCode).

Tobias Ouwejan [10 days ago] What makes you think the page type logic is not extendible? Can you name a scenario that you have in mind that isn't working?

Alessandro Ruzzon [10 days ago] I would have to implement an “Artist” page, where artist is an item in commerce, so I am trying to understand if i should mimic the same architecture of the “ProductPage” or just do a content page where components will fetch data of specific artist taking the artistCode from the router params.

For my understanding, looking at the code, adding more (custom) page types in spartacus won’t be that easy:

https://github.com/SAP/cloud-commerce-spartacus-storefront/blob/develop/projects/core/src/model/cms.model.ts#L9 https://github.com/SAP/cloud-commerce-spartacus-storefront/blob/develop/projects/core/src/cms/store/selectors/page.selectors.ts#L20 GitHub SAP/cloud-commerce-spartacus-storefront Spartacus is a lean, Angular-based JavaScript storefront for SAP Commerce Cloud that communicates exclusively through the Commerce REST API. - SAP/cloud-commerce-spartacus-storefront GitHub SAP/cloud-commerce-spartacus-storefront Spartacus is a lean, Angular-based JavaScript storefront for SAP Commerce Cloud that communicates exclusively through the Commerce REST API. - SAP/cloud-commerce-spartacus-storefront

Alessandro Ruzzon [6 days ago] @Tobias Ouwejan any more ideas?

Krzysztof Platis [5 days ago] Hi @Alessandro Ruzzon! You should be able to achieve your goal using just Content Pages. Please create a new Conent Page in CMS with page label i.e. /artist. Then in your app.module add a custom Angular route with dynamic parameter i.e. artist/:artistCode and define page label explicitly for this route data: { pageLabel: '/artist' }. See: https://sap.github.io/cloud-commerce-spartacus-storefront-docs/adding-and-customizing-routes/#how-to-add-content-page-with-dynamic-params (edited) sap.github.io Adding and Customizing Routes (DRAFT) SAP Spartacus JavaScript Storefront Documentation.

Krzysztof Platis [5 days ago] Then in the implementation of the CMS component, please get the value of route param artistCode from Angular's ActivatedRoute object (or our RoutingService) and call to the backend API for any additional data of this artist, if needed, and show it.

Please let me know if it helps.

Krzysztof Platis [5 days ago] Example of this approach is our order/:orderCode route for content page with page label /order (edited)

Alessandro Ruzzon [5 days ago] ok, great! thanks for the hints :+1: will try that out.

gladius-mtl commented 5 years ago

All this info is covered in the routing documentation.