Magento - Product Category List

In Magento, on each product details page, I would like to indicate which categories belong.

How can I achieve this?

+3
source share
3 answers

Try:

$currentCatIds = $_product->getCategoryIds();

and

 $categoryCollection = Mage::getResourceModel('catalog/category_collection')
  ->addAttributeToSelect('name')
  ->addAttributeToSelect('url')
  ->addAttributeToFilter('entity_id', $currentCatIds)
  ->addIsActiveFilter();

Cheers, JD

+5
source

You can use the following code to display all categories associated with the selected product on the product details page.

<?php $categories = $_product->getCategoryIds(); ?>
           <?php foreach($categories as $k => $_category_id): ?>
           <?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?> 
            <a href="<?php echo $_category->getUrl() ?>"><?php echo $_category->getName() ?></a>
           <?php endforeach; ?>
+1
source

. -.

   $product = Mage::getModel('catalog/product')->load($product_id);
   $cats = $product->getCategoryIds(); 
   foreach ($cats as $category_id) {
   $_cat = Mage::getModel('catalog/category')->setStoreId(Mage::app()-  >getStore()->getId())->load($category_id);
    echo $_cat->getName();             
     }
0

Source: https://habr.com/ru/post/1760509/


All Articles