3

I am facing one error in Magento Admin part, When I try to create a category it shows following fatal Error :

Fatal error: Call to a member function getId() on a non-object in C:\wamp\www\magento\lib\Varien\Data\Tree\Dbp.php on line 331

 public function loadEnsuredNodes($category, $rootNode)
 {
    $pathIds = $category->getPathIds();
    $rootNodeId = $rootNode->getId();
    $rootNodePath = $rootNode->getData($this->_pathField);

    $select = clone $this->_select;
    $select->order($this->_table.'.'.$this->_orderField . ' ASC');

So can anyone help me? how to fix this issues? can anyone suggest me the solution?

7ochem
  • 2,183
  • 1
  • 34
  • 42
hadi
  • 49
  • 1
  • 5

3 Answers3

6

Run this SQL query and it should clean it right up :)

INSERT INTO catalog_category_entity(entity_id,entity_type_id,attribute_set_id,parent_id,created_at,updated_at,path,POSITION,level,children_count) VALUES (1,3,0,0,'0000-00-00 00:00:00','2009-02-20 00:25:34','1',1,0,1),(2,3,3,0,'2009-02-20 00:25:34','2009-02-20 00:25:34','1/2',1,1,0); INSERT INTO catalog_category_entity_int(value_id,entity_type_id,attribute_id,store_id,entity_id,value) VALUES (1,3,32,0,2,1),(2,3,32,1,2,1); INSERT INTO catalog_category_entity_varchar(value_id,entity_type_id,attribute_id,store_id,entity_id,value) VALUES (1,3,31,0,1,'Root Catalog'),(2,3,33,0,1,'root-catalog'),(3,3,31,0,2,'Default Category'),(4,3,39,0,2,'PRODUCTS'),(5,3,33,0,2,'default-category');

BrettD
  • 381
  • 1
  • 4
  • 12
0

UGH. Core code debugging. I have to do this all the time.

Put a try catch on that code and error_log the results. It will give you a better idea of which line has the problem. Check your php log for the results

public function loadEnsuredNodes($category, $rootNode)
 {
    try {
       $pathIds = $category->getPathIds();
       $rootNodeId = $rootNode->getId();
       $rootNodePath = $rootNode->getData($this->_pathField);

       $select = clone $this->_select;
       $select->order($this->_table.'.'.$this->_orderField . ' ASC');

    } catch (Exception $e) {
        error_log($e);
    } 

If the error persists, then then try using the code in an isolated environment. Create a file test.php and put it in magento root.

<?php
   umask(0);
   require_once 'app/Mage.php';
   Mage::app('admin');
   echo "<PRE>";

   $category_id = 12;
   $rootNode = ??? load a root node what is this?

   $category = Mage::getModel('catalog/category')->load($category_id);
   var_dump($category->debug());

   $pathIds = $category->getPathIds();
   var_dump($pathIds);

   $rootNodeId = $rootNode->getId();
   var_dump($rootNodeId);

etc

CarComp
  • 1,929
  • 1
  • 21
  • 47
0

This answer

INSERT INTO catalog_category_entity(entity_id,entity_type_id,attribute_set_id,parent_id,created_at,updated_at,path,POSITION,level,children_count) VALUES (1,3,0,0,'0000-00-00 00:00:00','2009-02-20 00:25:34','1',1,0,1),(2,3,3,0,'2009-02-20 00:25:34','2009-02-20 00:25:34','1/2',1,1,0);
INSERT INTO catalog_category_entity_int(value_id,entity_type_id,attribute_id,store_id,entity_id,value) VALUES (1,3,32,0,2,1),(2,3,32,1,2,1); 
INSERT INTO catalog_category_entity_varchar(value_id,entity_type_id,attribute_id,store_id,entity_id,value) VALUES (1,3,31,0,1,'Root Catalog'),(2,3,33,0,1,'root-catalog'),(3,3,31,0,2,'Default Category'),(4,3,39,0,2,'PRODUCTS'),(5,3,33,0,2,'default-category');    

Helped me, thanx for saving my day!... but i had a table prefix in my database so incase it don¨t work for anyone change... all i belive 3 " INSERT INTO catalog_category_entity " with "INSERT INTO _add_your_database prefix here_catalog_category_entity

and it should work... anyhow big thanx for the help!

Nerdroid
  • 13,398
  • 5
  • 58
  • 69