0
votes

I have tried to use the code I use in catalog/product/view.phtml file and where it works

$yourCatIds = array(6,12); //telkide või peoinventari rent
$productCats = $_product->getAvailableInCategories();
if (count(array_intersect($yourCatIds,$productCats))) {
    echo "text";
}

but that gives me this error:

Fatal error: Call to a member function getAvailableInCategories() on a non-object in /home/profitel/public_html/app/design/frontend/default/hellowired/template/page/2columns-right.phtml on line 25

I tried also

$parentCategory = Mage::getModel('catalog/category')->load($parentCategoryId);

but also didn't work.

1
getAvailableInCategories method - Retrieve category ids where product is availablesergio

1 Answers

2
votes

If you are in 2columns-right.phtml you cannot access directly $_product, as it is defined in the catalog block.

If you want to get the current product or current category, simply access them in this way:

$current_product = Mage::registry('current_product');

or

$currentCategory = Mage::registry('current_category');

So, your code becomes:

$yourCatIds = array(6,12);
$currentCategory = Mage::registry('current_category');
error_log('CC '. $currentCategory->getId());
if (in_array($currentCategory->getId(), $yourCatIds)) {
    echo "text";
}