0
votes

I am trying to display category name in product detail page. For that I am using

 $cat_name=Mage::registry('current_category')->getName();

It shows category name. But when I went to wishlist page & click to product image then it give error:- Fatal error: Call to a member function getName() on a non-object in /opt/lampp/htdocs/dominie/app/design/frontend/default/dominie/template/catalog/product/view.phtml.

Please help me how can I solve this issue.

2

2 Answers

0
votes

Just tested the code below and it work in v1.7 when added to template/catalog/product/view.phtml.

However Mage::registry('current_category'); is only available if when coming to a product page from a category page (not tested, but may also dependent on if you have seo url that contain the category names within the url)

<?php
  $_helper = $this->helper('catalog/output');
  $_category_detail=Mage::registry('current_category');
  echo  $_category_detail->getName(); //gives current  category name
  echo $_category_detail->getId(); //gives current category id
?>

See http://vinayp.com.np/how-to-get-category-name-and-id-on-product-page-on-magento/

To display all the categories that a product belong to do

<?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; ?>

See http://www.magentocommerce.com/boards/viewthread/27720/

0
votes

Try to define $cat_name in your wishlist module so that collection from wishlist module will also contain category name from which it was added to wishlist. This will surely reduce your overhead.