Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only showing last category #29

Open
quickwit-dev opened this issue Aug 11, 2020 · 2 comments
Open

only showing last category #29

quickwit-dev opened this issue Aug 11, 2020 · 2 comments

Comments

@quickwit-dev
Copy link

I have 3 level categories but for some reason on only see the last category not the last

@jtomaszewski
Copy link

Same here. $product->getCategoryIds() returns only the last category somehow. Magento 2.4.1 . Wondering how it can be fixed?

@jtomaszewski
Copy link

jtomaszewski commented Feb 6, 2021

OK, I've found the fix. The code for loading categories need to looks like this:

        $productCategories = $this->getCurrentProduct()->getCategoryCollection();
        if (count($productCategories) === 0) {
            return [];
        }

        $productCategory = current(iterator_to_array($productCategories));
        $categories = $productCategory->getParentCategories();
        $excludedCategoriesIds = $this->getExcludedCategoriesIds();
        $filteredCategories = array_filter(
            $categories,
            function ($category) use($excludedCategoriesIds) {
                return !in_array($category->getId(), $excludedCategoriesIds);
            }
        );
        return $filteredCategories;

If you want, you can use our fork https://github.com/groomershop/module-full-breadcrumbs that has that fixed. Beware, that fork changes a bit the way the breadcrumbs template looks and behaves ; it assumes that you use theme-creativeshop . If you don't, you'll have to tweak the breadcrumbs.phtml and maybe move the <block name="full_breadcrumbs" /> somewhere else in your catalog_product_view.xml .

P.S. I think whether it needs to be changed or not might depend on your store setting. Like, there's this setting in magento, that controls whether the product's categories contains all its' categories' ancestors; or just the deepest children? I'm not expert in magento, so I'm not sure, but just leaving this as a side comment.

jtomaszewski added a commit to groomershop/module-full-breadcrumbs that referenced this issue Feb 6, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…iveshop ; show breadcrumbs for all categories ancestors, not just the final child (fixes EaDesgin#29)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants