Magento API bug in catalog_category.level

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;
            }
        }
//[...]
    }


…has an if statements constructed in that way that implies $store to be mandatory in order to take into account $categoryId, but this is all for nothing as if you set $website then $store AND $categoryId will be ignored!

If you think that this is the only problem that you are wrong, because the arguments from webservice are not passed correctly to this method, they are passed through first argument ($website) as an array, and this renders Fatal Error:

Fatal error: Call to a member function getStores() on a non-object in /sklep/app/code/core/Mage/Catalog/Model/Category/Api.php on line 57
,

Real nightmare, I need to try if I will be able to create custom API calls, maybe there is a chance…

This entry was posted in magento and tagged , , . Bookmark the permalink.