Magento Forum

   
Extending ‘Varien_Data_Tree_Dbp’ class to make custom category tree. 
 
artis1
Jr. Member
 
Total Posts:  2
Joined:  2011-02-10
 

Hello everyone!

I have a need of creating custom category tree in backend that is displayed like the original magento categories, but without need of them being edited. Now i’m at the point that i need to create the tree from my category table.

I tried to inspect the mage catalog module and found out that displaying a tree starts from ‘Varien_Data_Tree_Dbp’ class and also noticed that class ‘Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree’ extends ‘Varien_Data_Tree_Dbp’ class
and so tried to make my own model class extend from the ‘Varien_Data_Tree_Dbp’ class too but with no luck.

Few snippets how i’m trying to do it (i renamed the class to generic names for privacy sake)

This is my model with constructor(Similar to ...Resource_Eav_Mysql4_Category_Tree class):

class Namespace_Mymodule_Model_Customcategory extends Varien_Data_Tree_Dbp
{
    
public function __construct()
    
{
        $this
->_init('mymodule/customcategory');
        
        
$resource Mage::getSingleton('core/resource');

        
parent::__construct(
            
$resource->getConnection('core_write'),
            
$resource->getTableName('mymodule/customcategory'),
            array(
                
Varien_Data_Tree_Dbp::ID_FIELD       => 'id',
                
Varien_Data_Tree_Dbp::PATH_FIELD     => 'path',
                
Varien_Data_Tree_Dbp::ORDER_FIELD    => 'position',
                
Varien_Data_Tree_Dbp::LEVEL_FIELD    => 'level',
            )
        );
    
}

}

and with this line i try to instantiate the model in one of the adminhtml tab blocks:

$tree Mage::getModel('mymodule/customcategory');

But everytime i try to instantiate it i’m just getting a blank screen, no error messages or anything.

Can i actually extend Varien_Data_Tree_Dbp class like this (well magento did it with resource model class so why couldn’t i?)?

Am I even going the right way considering that my goal is to create possibility to display categories in tree view in backend and source them from custom table?

I’m stuck, so any help is highly appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
artis1
Jr. Member
 
Total Posts:  2
Joined:  2011-02-10
 

Bumping thread.
I also tried instantiating the class alone with new operator and couldn’t do it anyway.

 
Magento Community Magento Community
Magento Community
Magento Community
 
KalpeshMehta
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2011-02-26
India
 

You can override whole class Varien_Data_Tree_Dbp by placing it’s content in local folder.

Copy the contents of file and paste it at: app/code/local/Varien/Data/Tree/Dbp.php and modify the content as per your need.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top