Example: If the main category has ID 9 and the subcategory ID 6, appears in the product:
Home -> Subcategory -> Main Category -> Product Name
The exact position of the breadcrumb instead must be:
Home-> Main Category -> Subcategory -> Product Name
The issue occurs when the parent category has a higher entity_id than it child - then the child is loaded first and is displayed first in breadcrumbs.
Code explanation
Instead of iterating over the categories collection which is sorted by ids by default, I iterate over the categories path and manually load each category from the collection to ensure that the order of categories in breadcrumbs is correct.
Issue description:
Example: If the main category has ID 9 and the subcategory ID 6, appears in the product: Home -> Subcategory -> Main Category -> Product Name
The exact position of the breadcrumb instead must be: Home-> Main Category -> Subcategory -> Product Name
The issue occurs when the parent category has a higher entity_id than it child - then the child is loaded first and is displayed first in breadcrumbs.
Code explanation
Instead of iterating over the categories collection which is sorted by ids by default, I iterate over the categories path and manually load each category from the collection to ensure that the order of categories in breadcrumbs is correct.