10

I have a class rewrite problem in Magento Onepage Checkout as I have a custom module in the local code pool and a third party extension in the community code pool both extending the same class...

I've tried to add a depends node to the ModuleA_Name.xml file of one module then extend the class of ModuleB in the Onepage.php file but this hasn't worked.

Could someone give me heads up on how to do this I know there is another way to do it using an Observer but I could really just need a solution at the moment? Also, would it be dangerous for me to use a dependency since ModuleB may only be enabled for different store/views would that mean the dependent module would no longer work?

Thanks in advance for the assistance...

ModuleA

<global>
  <rewrite>
      <moduleA>
          <from><![CDATA[#^/checkout/onepage/#]]></from>
          <to>/moduleA/onepage/</to>
      </moduleA>
      <moduleA>
          <from><![CDATA[#^/checkout/cart/add/#]]></from>
          <to>/moduleA/cart/add/</to>
      </moduleA>
  </rewrite>

ModuleB

<global>
    <models>
      <salesrep>
        <class>ModuleB_SalesRep_Model</class>
        <resourceModel>salesrep_mysql4</resourceModel>
      </salesrep>

      <salesrep_mysql4>
        <class>ModuleB_SalesRep_Model_Mysql4</class>
        <entities>
          <salesrep>
            <table>salesrep</table>
          </salesrep>
        </entities>
      </salesrep_mysql4>

      <checkout>
        <rewrite>
          <type_onepage>ModuleB_SalesRep_Model_Type_Onepage</type_onepage>
        </rewrite>
      </checkout>

      <modulebadminthemecontroller>
        <class>LucidPath_SalesRep_Controller</class>
      </modulebadminthemecontroller>
    </models>
</global>
1
  • 1
    Which Onepage class specifically, the block or the model?
    – benmarks
    May 19, 2013 at 20:32

1 Answer 1

20

You have 3 choices for resolving conflicts:

  • 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 <depends> capability to make one extension depend on another. They will then rewrite in that order

Example (option # 2)

class A_Extension_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage

You would change it to:

class A_Extension_Model_Type_Onepage extends B_Extension_Model_Type_Onepage

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

3
  • @benmarks I've added some code from each config.xml file May 19, 2013 at 22:50
  • Well I've managed to solve the class rewrite issue by extending the class of moduleA with that of moduleB May 21, 2013 at 10:06
  • Since I am using OPCheckout and the module appears in the new step but it doesn't get called by the opcheckout.js file for some reason it skips the step. I've looked in the console and can see the class: section allow but it doesn't become active... May 21, 2013 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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