1

Currently, I am trying to add new functionality whereby customize the City field from text to select in edit address book page. I made this change on my own module (path: local/Company/NewDirectory) and result is working fine at the frontend.

Then, I decided to move this functionality to overridden module. However, I am confused in defining the class prefix in the config.xml for this functionality.

<config>
<modules>
    <Company_Directory>
        <version>0.0.2</version>
    </Company_Directory>
</modules>
<global>
    <helpers>
        <directory>
            <!-- I have an overriden class at here -->
            <rewrite>
                <data>Company_Directory_Helper_Data</data>
            </rewrite>
        </directory>
    </helpers>
    <models>
        <directory>
            <!-- How to define this class prefix without overwrite the Mage's ? -->
            <class>Company_Directory_Model</class> 
            <resourceModel>directory_resource</resourceModel>
        </directory>
        <directory_resource>
            <!-- How to define this class prefix without overwrite the Mage's ? -->
            <class>Company_Directory_Model_Resource</class>
            <entities>
                <region_city>
                    <table>directory_region_city</table>
                </region_city>
            </entities>
        </directory_resource>
    </models>
    ...
</global></config>
2
  • Which models/helpers you want to override? Commented Feb 5, 2014 at 11:24
  • I managed to override Mage_Directory_Helper_Data class, but confusing on how to define the class prefix in above config.xml for my new model classes.
    – Leongelis
    Commented Feb 5, 2014 at 12:43

1 Answer 1

0

As general best practise use you module name('directory) plus your namespace(company) -> company_directory. Let's say you have a model named Calculation(located in app/code/code_pool/Company/Directory/Model/Calculation.php. Than in your code use Mage::getModel('company_directory/calculation'). Note the underscore before the slash doesn't get converted to location on the filesystem(it's just the value of the node in config.xml). Let's say you want to instantiate a helper : Mage::helper('company_directory/data') => Company_Directory_Helper_Data. Also take a look at this reference: http://www.ecomdev.org/2010/08/31/magento-module-configuration-file-reference.html


EDIT
I changed the config xml as below and combined with your proposed, now the functionality is working at frontend. But I am not sure whether these steps are best practice when adding new classes to overridden module. Hope someone here can give a friendly advice.

<models>
<company_directory>
    <class>Company_Directory_Model</class>
    <resourceModel>company_directory_resource</resourceModel>
</company_directory>
<company_directory_resource>
    <class>Company_Directory_Model_Resource</class>
    <entities>
       <region_city>
           <table>directory_region_city</table>
       </region_city>
    </entities>
</company_directory_resource></models>
12
  • Pardon for my english. By given your example model class Calculation.php, is it that I no need to define the class name prefix in config.xml, instead just use Mage::getModel('company_directory/calculation') in my code?
    – Leongelis
    Commented Feb 5, 2014 at 13:42
  • Yes, here is the connection between config.xml and Mage::getModel() for example. In your case company_director->Company_Directory_Model(a file path). Take a look at this cheat sheet for another example: magentix.fr/assets/files/magento-cheatsheet.pdf Commented Feb 5, 2014 at 13:48
  • The model class was not found, error: "No such file or directory". And here is the stack trace:#4 ..\Config.php(1346): class_exists('Mage_Company_D...') #5 ..\Mage.php(463): Mage_Core_Model_Config->getModelInstance('company_direct...', Array) #6 ..\local\Company\Directory\Helper\Data.php(92): Mage::getModel('company_direct...') #7 ..\template\customer\address\edit.phtml(177): Company_Directory_Helper_Data->getCityJson()
    – Leongelis
    Commented Feb 5, 2014 at 14:34
  • Did you update your config.xml, so that it looks like this: <models> <company_directory> <!-- How to define this class prefix without overwrite the Mage's ? --> <class>Company_Directory_Model</class> ..... </models> Commented Feb 5, 2014 at 14:37

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