Magento – Call one module model from other module model

magento-1.9modelmodule

I have a design like below

enter image description here

I have two independent modules and one common module. That means independent module will pull information from common module.

I defined below in common module config.

<config>
    <global>
        <models>
            <services>
                <class>My_Common_Model</class>
            <services>
        <models>
    </global>
</config>

Then I tried to call a method in common module model from module_1 controller like below,

$stores = Mage::getModel('services/store')->getAvailableStore();

But is throws error like model undefined.

Then I included the common model configuration in Module_1 config.xml also. Its working now.

Is it the normal behavior? Cant we call any method in one modules model from other modules controller with defined tag in its native module itself?

I don't know how to ask this question better than this.

Module 1 Controller:

<?php
    class My_Module_UserController extends Mage_Core_Controller_Front_Action{

        function userAssignStoreAction(){

            $stores = Mage::getModel('stores/store')->getAvailableStore();

            echo $productModel;
            die;
        }
    }
?>

below is common module config file:

<config>
    <modules>
        <My_Common>
            <version>0.0.1</version>
        </My_Common>
    </modules>
    <global>
        <models>
            <stores>
                <class>My_Common_Model</class>
            </stores>
        </models
    </global>
</config>

below is module 1 config:

<global>
        <models>
            <services>
                <class>My_Module_Model</class>
            </services>
           <!-- WITHOUT BELOW DECLARATION UNABLE TO CALL COMMON MODEL METHOD FROM MODULE 1 CONTROLLER -->
            <stores>
                <class>My_Common_Model</class>
            </stores>
        </models>
    </global>

Best Answer

You should be able to call your custom model from anywhere in Magento, the same way you call any other core model e.g Mage::getModel('catalog/product')

Did you check to make sure module_1 is active?

Related Topic