0

I used Category Collection but is show error in product count is fixed it but after that is show error in Set product is and attribute set. I am trying this by Problematically. My code: $storeId = $_SESSION["store_id"] ? $_SESSION["store_id"] : $this->session->userdata('store_id');

public function get_categories() 
{
    $storeId = store_id;
    $web_id = website_id;
    $rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
    $categories = Mage::getModel('catalog/category')
        ->getCollection()
        ->setStoreId($storeId)
        ->addFieldToFilter('is_active', 1)
        ->addAttributeToFilter('path', array('like' => "1/{$rootCategoryId}/%"))
        //->setProductStoreId($storeId)
        ->addFieldToFilter('store_id',$storeId)
        // ->setLoadProductCount(1)
        ->getSize(1)
        // ->addAttributeToSelect('*')
        // ->addAttributeToSelect(array('name'),'inner')
        ->addAttributeToSelect(array('name','url'));

    foreach ($categories as $_category)
    {
        $img = $_category->getImageUrl();
        $data[] = array('category_id' => $_category->getEntityId(), 'category_name' => $_category->getName(), 'image' => $imgUrl);
    }
    return $data;
}

Now this code is showing Fatal error: Call to a member function addAttributeToSelect() on a non-object

1
  • 1
    I believe you need to use setPageSize instead of getSize method.
    – Prateek
    Commented Dec 8, 2015 at 5:54

1 Answer 1

1

use bellow code

    $storeId = 1;
    $web_id = 1;
    $rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
    $categories = Mage::getModel('catalog/category')->getCollection()
            ->setStoreId($storeId)
            ->addAttributeToSelect('name')
            ->addAttributeToSelect('is_active')
            ->addAttributeToSelect('path')
            ->addFieldToFilter('is_active', 1)
            ->addAttributeToFilter('path', array('like' => "1/{$rootCategoryId}/%"))
            //->setPageSize(1)
            //->setCurPage(1)
            ;

    foreach ($categories as $_category)
    {
        $img = $_category->getImageUrl();
        $data[] = array('category_id' => $_category->getEntityId(), 'category_name' => $_category->getName(), 'image' => $imgUrl);
    }
     print_r($data)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.