CompactCodeEU / FixProductBreadcrumbs

This is a Fix for Magento 2.2.4 and 2.2.5 where the Product Breadcrumbs are generated with JS normally and contain unwanted text.
GNU General Public License v3.0
32 stars 13 forks source link

#5 Fix wrong order of categories #9

Closed maciejslawik closed 4 years ago

maciejslawik commented 4 years ago

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.