frontends icon indicating copy to clipboard operation
frontends copied to clipboard

[BUG] Category breadcrumbs path is missing

Open StanislovasRamanauskas opened this issue 2 years ago • 6 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

Currently useBreadcrumbs() composable only returns names array for category breadcrumbs. Paths are missing so link to category cannot be created.

E.G.

{
  "name": "Food"
}

Helper function to get breadcrumbs getCategoryBreadcrumbs() also gather only names:

export function getCategoryBreadcrumbs(
  category: Category | null | undefined,
  options?: {
    /**
     * Start at specific index if your navigation
     * contains root names which should not be visible.
     */
    startIndex?: number;
  }
) {
  const breadcrumbs =
    category?.translated?.breadcrumb || category?.breadcrumb || [];
  const startIndex = options?.startIndex || 0;
  if (breadcrumbs.length <= startIndex) return [];
  return breadcrumbs.slice(startIndex).map((element) => {
    return {
      name: element,
    };
  });
}

Breadcrumbs in product.seoCategory / category API response also contain only names. So I think this is issue both in BE and FE parts: Screenshot from 2023-04-14 00-07-12

Expected Behavior

As declared in useBreadcrumbs return type I expect category breadcrumb with path returned:

type Breadcrumb = {
    name: string;
    path?: string;
};

Steps To Reproduce

No response

Environment

- OS:
- Node:
- npm:

Anything else?

No response

StanislovasRamanauskas avatar Apr 13 '23 21:04 StanislovasRamanauskas

Thx for submitting this already known issue (NEXT-24954). We have an discussion with the product area that is responsible to return the path via API. Also good to have this issue here to do not forget it. Will ping you when I have news about this.

Possible solutions:

In this file: src/Core/Content/Category/Service/CategoryBreadcrumbBuilder.php we could add after line 89 this line of code: $criteria->addAssociation('seoUrls'); and then we would have already the seoUrls in the response (slower).

Otherwise we could change public function getPlainBreadcrumb(): array function in src/Core/Content/Category/CategoryEntity.php and instead a flat array we return a super simple object that contains name and path (maybe path is already loaded, did not checked, then this would be faster).

BrocksiNet avatar Apr 14 '23 06:04 BrocksiNet

@patzick could we use the same technic we used for "duplicated" seoURL''s calls to solve this issue? Like looking in the list if we have this seoURL already and then adding the link instead of waiting for the changed response? Just an idea.

BrocksiNet avatar Jun 07 '23 07:06 BrocksiNet

@StanislovasRamanauskas here is an example of how to solve this in frontends (but this is just a workaround): https://github.com/shopware/frontends/pull/258/files

And I do not know if we will merge this into the demo-store.

BrocksiNet avatar Jun 15 '23 07:06 BrocksiNet

For reference: NEXT-24954

BrocksiNet avatar Dec 13 '23 09:12 BrocksiNet

@BrocksiNet Is there any news update about this issue 😄.

junaidfarooqui avatar Sep 10 '24 06:09 junaidfarooqui

I am preparing the MR to get the new Endpoints into the Core of Shopware. After that, we can update the composables and have a proper solution. :raised_hands: But I need to find out which version it will be released.

BrocksiNet avatar Sep 10 '24 06:09 BrocksiNet

The changes are already in the trunk so we can start with the frontend part. This is not blocked anymore.

BrocksiNet avatar Oct 02 '24 08:10 BrocksiNet