Thursday, August 15, 2013

Magento searched products no category

If you are having a problem where you cannot find the product via $_category = Mage::registry('current_category') , and you need the product category, you can try to make use the following code. In my case I checked whether the category belonged to New Releases, leave out that category and if it contains more than one category, take the first one.


// if category is not found if ($_category == NULL) { $cat_id_array = array(); $_category_id = $this->getProduct()->getCategoryIds(); $i = 0; foreach ($_category_id as $cat_id) { if ($cat_id != 7) // if category is not new release id { $cat_id_array[$i] = $cat_id; $i++; } } $_category = Mage::getModel('catalog/category')-> load($_cat_id_array[0]); //assign first category }

No comments:

Post a Comment