More frustration every day:( I hoped to breeze through basic and core API but so far there are just issues, I have tried to use level method to pull single levels of category tree instead of receiving gigantic structure using tree method, but it was just beyond me. The level method when called without arguments should return top level category – works, then it accepts 3 arguments more to filter out the results, the website code, the store view code and parent category id, all according to documentation optional. But the method body…
/**
* Retrive level of categories for category/store view/website
*
* @param string|int $website
* @param string|int $store
* @return array
*/
public function level($website = null, $store = null, $categoryId = null)
{
$ids = array();
$storeId = Mage_Catalog_Model_Category::DEFAULT_STORE_ID;
$this->_fault('website_not_exists', var_dump($website));
// load root categories of website
if (null !== $website) {
try {
$website = Mage::app()->getWebsite($website);
foreach ($website->getStores() as $store) {
/* @var $store Mage_Core_Model_Store */
$ids[] = $store->getRootCategoryId();
}
} catch (Mage_Core_Exception $e) {
$this->_fault('website_not_exists', $e->getMessage());
}
}
elseif (null !== $store) {
// load children of root category of store
if (null === $categoryId) {
try {
$store = Mage::app()->getStore($store);
$storeId = $store->getId();
$ids = $store->getRootCategoryId();
} catch (Mage_Core_Model_Store_Exception $e) {
$this->_fault('store_not_exists');
}
}
// load children of specified category id
else {
$storeId = $this->_getStoreId($store);
$ids = (int)$categoryId;
}
}
//[...]
}
Continue reading →