Skip to content

Instantly share code, notes, and snippets.

@willboudle
Last active January 2, 2016 13:09
Show Gist options
  • Select an option

  • Save willboudle/8307653 to your computer and use it in GitHub Desktop.

Select an option

Save willboudle/8307653 to your computer and use it in GitHub Desktop.
Magento get category from product
//$_product = Mage::getModel('catalog/product')->load($productID);
-----------------------------------
$catCollection = $_product->getCategoryCollection();
foreach($catCollection as $cat){
print_r($cat->getData());
//echo $cat->getName();
//echo $cat->getUrl();
}
-----------------------------------
$catIds = $_product->getCategoryIds();
$catCollection = Mage::getResourceModel('catalog/category_collection')
//->addAttributeToSelect('name')
//->addAttributeToSelect('url')
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', $catIds)
->addIsActiveFilter();
foreach($catCollection as $cat){
print_r($cat->getData());
//echo $cat->getName();
//echo $cat->getUrl();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment