2

I have two custom modules: ModuleA and ModuleB.

Each one rewrites Core Product Model via:

<global>
    <models>
        <catalog>
            <rewrite>
                <product>AD_ModuleA_Model_Product</product>
            </rewrite>
        </catalog>
    </models>
</global>

and class header: class AD_ModuleA_Catalog_Model_Product extends Mage_Catalog_Model_Product

and

<global>
    <models>
        <catalog>
            <rewrite>
                <product>AD_ModuleB_Model_Product</product>
            </rewrite>
        </catalog>
    </models>
</global>

and class header: class AD_ModuleB_Catalog_Model_Product extends Mage_Catalog_Model_Product

but AFAIK, it's not correct syntax since Magento doesn't support multiple rewrites in such case. I've put debugging line Mage::log('AD_ModuleB_Catalog_Model_Product file has been loaded') before its class definition, but it even doesn't load a class file.

Is there another way to extent Core Product Model in multiple independent custom models?

Thanks.

2

Step:Don't used two module to overwrite class

  • Merge the code from one conflicting file into another and switch off the rewrite config.xml in one

  • Switch off the rewrite in one config.xml and then make the conflicting extension PHP file extend the other extension

  • Use the capability to make one extension depend on another. They will then rewrite in that order

try this

class AD_ModuleA_Catalog_Model_Product extends AD_ModuleB_Catalog_Model_Product

seemore:

https://stackoverflow.com/questions/14815717/multiple-modules-overriding-same-core-file-in-magento

http://www.webshopapps.com/blog/2010/11/resolving-magento-extension-conflicts/

Edit:

Step1: modify AD_ModuleA.xml which is depends on module AD_ModuleB module.AD_ModuleA.xml code is

<?xml version="1.0" ?>
<config>
    <modules>
        <AD_ModuleA>
            <active>true</active>
            <codePool>community</codePool>
       <depends><AD_ModuleB/></depends> <!-- depends on module ModuleB -->
        </AD_ModuleA>
    </modules>
</config>

Step2: AD_ModuleB.xml depends on Mage_Catalog module

AD_ModuleB.xml code is

<?xml version="1.0" ?>
<config>
    <modules>
        <AD_ModuleB>
            <active>true</active>
            <codePool>community</codePool>
        <depends><Mage_Catalog/></depends> <!-- depends on module Mage_Catalog  -->
        </AD_ModuleB>
    </modules>
</config>

Step3: Remove write code from rewrite code AD_ModuleB module config.xml

<global>
    <models>
        <catalog>
            <rewrite>
                <product>AD_ModuleB_Model_Product</product>
            </rewrite>
        </catalog>
    </models>
</global>

Step4: change rewrite class code

class AD_ModuleA_Model_Product extends  AD_ModuleB_Model_Product 

and

class  AD_ModuleB_Model_Product extends Mage_Catalog_Model_Product

Step5: class AD_ModuleB_Catalog_Model_Product class is wrong but you was define it should be

AD_ModuleB_Model_Product

http://blog.belvg.com/get-ready-for-magento-certified-developer-exam-describing-methods-for-resolving-module-conflicts.html

  • What if ModuleA and ModuleB are owned by different authors? – Serhii Matrunchyk Sep 29 '14 at 18:17
  • it not depend on author .more study blog.belvg.com/… – Amit Bera Sep 29 '14 at 18:19
  • Can't make it working. What exactly should I write on config.xmls of ModuleA and ModuleB? – Serhii Matrunchyk Sep 29 '14 at 19:29
  • Why AD_ModuleB_Catalog_Model_Product class is wrong? My directory structure is AD\ModuleB\Catalog\Model\Product.php – Serhii Matrunchyk Sep 30 '14 at 17:35
  • 1
    magentocommerce.com/wiki/5_-modules_and_development/0-_module_development_in_magento/custom_module_with_custom_database_table – Amit Bera Sep 30 '14 at 17:38
0

Open the moduleB class.

Change

class AD_ModuleB_Catalog_Model_Product extends Mage_Catalog_Model_Product

with

class AD_ModuleB_Catalog_Model_Product extends AD_ModuleA_Catalog_Model_Product

that's all (in most cases).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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