0

When i am trying to search any product name in mobile rwd theme then i am getting the below error.

Fatal error: Call to a member function getId() on a non-object in /home3/wowdeals/public_html/app/design/frontend/rwd/rwd-ariel/template/catalog/product/list.phtml on line 51

Here is a piece of code:

<?php
$_category = Mage::registry('current_category');
$currentCategoryId= $_category->getId();
// echo $currentCategoryId;

$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addCategoryFilter($_category)
->setOrder('price', 'ASC')
->load();
?>

Kindly help me.

0

Thats probably because there is no current category registered on the search list.

You can change your code to the following to fix that:

<?php
$_category = Mage::registry('current_category');
if ($_category) {
$currentCategoryId= $_category->getId();
}

$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*');

if ($_category) {
$_productCollection->addCategoryFilter($_category);
}
$_productCollection->setOrder('price', 'ASC')
->load();
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.