Issues with join / joinField / joinAttribute (undefined method)
-
12-12-2019 - |
Question
I'm trying to join a category with an event.
Here's what I have so far:
<?php
$rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
$categoryModel = Mage::getModel('catalog/category');
$categories = $categoryModel->getCollection()
->addAttributeToSelect(array('name'))
->addAttributeToFilter('parent_id', array('eq' => $rootCategoryId))
->addAttributeToFilter('is_active', array('eq' => 1));
$categories->joinTable('catalogevent/event', 'entity_id=category_id');
The error I receive is:
Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Category_Flat_Collection::joinTable()
Any help is greatly appreciated. I get a similar error trying to use joinField and joinAttribute.
Solution
Try
$rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
$categoryModel = Mage::getModel('catalog/category');
->getCollection()
->addAttributeToSelect(array('name'))
->addAttributeToFilter('parent_id', array('eq' => $rootCategoryId))
->addAttributeToFilter('is_active', array('eq' => 1));
$categoryModel->getSelect()->join('catalogevent/event', 'entity_id=category_id');
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange