Thursday, May 16, 2013

Adding new model for existing or core module in magento

Hi,
if you add new model for existing module you have to follow below code
that if you extend one core module ex catalog,checkout etc.. and you need to add new model then follow below steps
extending catalog module to local folder
1. add resource in config.xml that is
 <global>
        <models>
            <sugarcode_catalog>
                <class>Sugarcode_Catalog_Model</class>
                <resourceModel>sugarcode_catalog_resource</resourceModel>                
            </sugarcode_catalog>            
            <sugarcode_catalog_resource>
                <class>Sugarcode_Catalog_Model_Resource</class>
                <entities>
                    <newmodel>
                        <table>tablename_new</table>
                    </newmodel>                   
                </entities>
            </sugarcode_catalog_resource>
                
        </models>
    </global> 

i extend catalog module and added newmodel as new model
2. create a table tablename_new manually in Db
3. create a model files that is local\Catalog\Model\Newmodel.php local\Catalog\Model\Resource\Newmodel.php local\Catalog\Model\Resource\Newmodel\Collection.php
please check attached files in this post
http://www.magentocommerce.com/boards/viewthread/387252/
now you can call
$obj=Mage::getModel(’sugarcode_catalog/newmodel’)->getCollection(); print_r($obj);

No comments:

Post a Comment