SAP / spartacus

Spartacus is a lean, Angular-based JavaScript storefront for SAP Commerce Cloud that communicates exclusively through the Commerce REST API.
Apache License 2.0
738 stars 383 forks source link

[onhold] Header, breadcrumbs, title not updated for category variation page #5680

Open ktxed opened 4 years ago

ktxed commented 4 years ago

In a variation page of the product listing page the CMSProductListTemplate is not used directly instead a custom CMS product list component with a similar purpose is displayed. ProductListSlot is replaced with a dedicated MyProductListSlot containing this custom CMS component. My scenario requires different a product listing page for products of a specific category and it also requires using the regular product listing page for other products.

In this setup navigating via the navigation bar from this page to another page for example Contact Us page and back reproduces the behaviour mentioned: breadcrumbs, title, header are not updated.

From my analysis I can see that in CategoryPageMetaResolver a few checks are performed to determine whether the CMSProductListTemplate CMS component is used.

private hasProductListComponent(page: Page): boolean {
    return !!Object.keys(page.slots).find(
      key =>
        !!page.slots[key].components.find(
          comp => comp.typeCode === 'CMSProductListComponent'
        )
    );
  }

I've tried a fix like the one below which solves the problem.

private hasProductListComponent(page: Page): boolean {
    return !!Object.keys(page.slots).find(
      key =>
        !!page.slots[key].components.find(
          comp => comp.typeCode === 'CMSProductListComponent' || comp.typeCode === 'MyCMSProductListComponent'
        )
    );
  }

However this solution is not applicable in practice in the long term because it relies on patching node_modules resources (/node_modules/@spartacus/core/fesm2015/spartacus-core.js)

Ideally hasProductListComponent should be changed to allow dynamically configuring other product listing pages-like CMS components via the ConfigurationModule.withConfig() mechanism keeping the rest of the logic in the resolver untouched.

ktxed commented 4 years ago

Problem seems to reproduce on a variation page based on the standard ProductListPage with a template based on ProductListPageTemplate with one exception that the CMSProductListComponentand its slot are replaced.

Later edit: the problem still reproduces when using the standard ProductListPageTemplate on a variation page. Unfortunately I got a false positive since I was actually testing with the quick fix mentioned above in spartacus-core.js.

Xymmer commented 4 years ago

@tobi-or-not-tobi can you comment

CarlEricLavoie commented 4 years ago

@Xymmer @tobi-or-not-tobi - we are facing a similar issue see https://github.com/SAP/cloud-commerce-spartacus-storefront/issues/6376 which is still happening in 1.5-next.0.2

giancorderoortiz commented 3 years ago

Please fix conflicts in pr(if any), and approve/reject. Would like to test this fix soon.

Pucek9 commented 3 years ago

"if the page type can be solved in the resolver with semantic route, then it makes no sense to do a configuration that defines what page it is based on the component" ~Stan I set it to hold as recommended