Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

reading the current Category -Id
 
schmelzgeist
Sr. Member
 
Total Posts:  92
Joined:  2008-05-27
Marzipane World Capital (Lübeck, Germany)
 

is there any function to read the Id of the Current Category when surfing through the Catalog? smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Georg Ringer
Member
 
Avatar
Total Posts:  63
Joined:  2008-07-04
Linz, Austria
 

Hi,

should work with

$category Mage::registry('current_category');

georg

 
Magento Community Magento Community
Magento Community
Magento Community
 
schmelzgeist
Sr. Member
 
Total Posts:  92
Joined:  2008-05-27
Marzipane World Capital (Lübeck, Germany)
 

thanks, but it doesn’t . when ever i try to access the variable, my page disappears, not even a var_dump() works. :( i don’t get it, if ‘current_category’ is not set, it should return a null that would be displayed by var_dump() or not?  smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
schmelzgeist
Sr. Member
 
Total Posts:  92
Joined:  2008-05-27
Marzipane World Capital (Lübeck, Germany)
 

hah, found out!

$currentcat$this->getCurrentCategory()->getID();
 
Magento Community Magento Community
Magento Community
Magento Community
 
airclic
Jr. Member
 
Total Posts:  26
Joined:  2008-04-14
 

Hello,

where do you put this code: $currentcat = $this->getCurrentCategory()->getID();
I try in:
app/code/local/Mage/Catalog/Blocl/Product/mymodule.php
or
app/design/frontend/defaut/mytemplate/templatecatalog/product/mymodule.phtml
but i have the same error:
Fatal error: Call to a member function getID() on a non-object in /home/k1003/app/code/local/Mage/Catalog/Block/Product/Upproduct.php on line 11

What’s the file where i can get the current category ?

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
schmelzgeist
Sr. Member
 
Total Posts:  92
Joined:  2008-05-27
Marzipane World Capital (Lübeck, Germany)
 

take the code into ‘app/design/frontend/defaut/mytemplate/template/catalog/product/mymodule.phtml ‘

it seems that you have this error because you work in that file with your own class?  i just used it at the beginning of the file, before any inclusion of my code

<?php     
   
     $collection 
Mage::getModel('catalog/category')->getTreeModelInstance()->getCollection();
     
$currentcat$this->getCurrentCategory()->getID();
     
?>
     
<div class="kategorie-all">
         <
div class="kategorie-all-header">
             <
h4><?php echo $this->htmlEscape($this->getCurrentCategory()->getName()) ?></h4>
         </
div>
         
          <
div class="kategorie-all-top">
              <
div class="kategorie-all-block">
     
<?php $i=0;$xx=0;
      
           foreach(
$collection as $category):   </snip>
 
Magento Community Magento Community
Magento Community
Magento Community
 
airclic
Jr. Member
 
Total Posts:  26
Joined:  2008-04-14
 

OK, i juste want a module to display the best rating product of the current category.
To start, i need the current category…
The php file is this, with all the tests to get the current category:

class Mage_Catalog_Block_Product_Ratingproduct extends Mage_Core_Block_Template
{
    
public function __construct()
    
{
        parent
::__construct();

         
//$currentcat = Mage_Catalog_Model_Layer_Filter_Category::getCategory();
         //or   
         //$currentcat = Mage::helper('catalog')->getCategory();
         //or
        //$currentcat = $this->getCurrentCategory();            
    //$this->setAttribute('currentcat', $currentcat);
    
}
}

but nothink work (valur NULL or error)
Maybe i donc inherit the goog class…

If you can help me.

 
Magento Community Magento Community
Magento Community
Magento Community
 
schmelzgeist
Sr. Member
 
Total Posts:  92
Joined:  2008-05-27
Marzipane World Capital (Lübeck, Germany)
 

hmm… try the one Georg Ringer mentioned above. smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
airclic
Jr. Member
 
Total Posts:  26
Joined:  2008-04-14
 

Thanks, I advance:
in my last test i don’t now why ilt’s dont work...but now:
$category = Mage::registry(’current_category’);
is ok smile

Just one question: how to pass the object $category in the phtml file (it’s not acknowledged in phtml)?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top