2

Hi i'm having a product collection, i'm getting those categories by $item->getCategoryIds();

On print_r($categoryIds = $item->getCategoryIds()); i'm getting

    Array
(
    [0] => 12
    [1] => 26
)
Array
(
    [0] => 22
    [1] => 26
)
Array
(
    [0] => 12
    [1] => 26
)
Array
(
    [0] => 12
    [1] => 26
)

In these category id 12 is parent for categories 26,22

So is there any way to exclude parent category i.e 12 from array ? Smething like this i'm looking for

    Array
(
    [0] => 26
)
Array
(
    [0] => 22
    [1] => 26
)
Array
(
    [0] => 26
)
Array
(
    [0] => 26
)
2

The easiest way is to not add the product to both categories, maybe make 12 a anchor category.

if you don't want this, you can load all the categories and check against $category->getPath() to filter parents...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.