Root Category (id: 1) - Apparel (id: 2) -- Shirts (id:4) -- Pants (id:5) - Accessories (id: 3) -- Handbags (id:6) -- Jewelry (id:7)
In Magento, we can get product category identifiers using $productObj->getCategoryIds()
$productObj = Mage::getModel('catalog/product')->load($product_id); $categoryIds = $productObj->getCategoryIds();
which will return an array of product category identifiers. I have a definite need to get the first level parent of a product category. Accepts, for example, the tree of categories above, if the product is classified in the Pants category, I want to get the first level category, which is Clothing (in this case, only the product is marked in the Trousers category, but not in the Clothing category).
Question: What method can I use to get the parent category of a subcategory, or can I get a first-level category from a product?
source share