0

I had two modules extending same core helper class and causing a conflict:

class Amasty_Methods_Helper_Payment_Data extends Mage_Payment_Helper_Data

and

class Ebizmarts_SagePaySuite_Helper_Payment_Data extends Mage_Payment_Helper_Data

I have now made a temporary fix to them and it looks like this now:

class Amasty_Methods_Helper_Payment_Data extends Mage_Payment_Helper_Data

and

class Ebizmarts_SagePaySuite_Helper_Payment_Data extends Amasty_Methods_Helper_Payment_Data

The above temporaty fix resolved the module conflict however I have a different problem. If I disable the Amasty module, it will stop the Ebizmarts module from working. I want to make sure that both modules don't depend on each other and are working regardless if any of them is disabled.


UPDATE:

This is the full content of the Ebizmarts helper class:

class Ebizmarts_SagePaySuite_Helper_Payment_Data extends Amasty_Methods_Helper_Payment_Data
{

    public function getPaymentMethods($store = null)
    {
        $_methods = parent::getPaymentMethods($store);

        if (isset($_methods['sagepaysuite'])) {
            unset($_methods['sagepaysuite']);
        }
        return $_methods;
    }
}

Now, can you help me use isModuleOutputEnabled method the get them both working.

I have something like this but not sure how to finish it and get it working:

if (Mage::helper('sage pay... not sure what')->isModuleOutputEnabled('ammethods')) {
    class Ebizmarts_SagePaySuite_Helper_Payment_Data extends Amasty_Methods_Helper_Payment_Data {}
} 
else {
    class Ebizmarts_SagePaySuite_Helper_Payment_Data extends Mage_Payment_Helper_Data {}
}


class Ebizmarts_SagePaySuite_Helper_Payment_Data extends Amasty_Methods_Helper_Payment_Data
{

    public function getPaymentMethods($store = null)
    {
        $_methods = parent::getPaymentMethods($store);

        if (isset($_methods['sagepaysuite'])) {
            unset($_methods['sagepaysuite']);
        }
        return $_methods;
    }
}

Am I even close to get that right?

Is there a different way to solve my issue?

  • You can create your own module, which extends the Mage_Payment_Helper_Data class with a depends in your module xml configuration to be sure to be top priority. Then in your code, you can add some check if module Amasty is enabled do this and if Ebizmarts module is enable do that. And try to gather the 2 modules logics in your file. This is painful during module upgrade to keep your code maintained. By the way, rewriting is always complicated to manage, and you should try to use plugin when it is possible. – Franck Garnier Oct 20 '17 at 12:24
  • Is that how you sort situations like this? When two modules try to extend same core class you have to create a custom module to handle them? Is this the only way to make sure when Amasty module is disabled the Ebizmarts module is still working? – Greg Oct 20 '17 at 12:34
1

Don't use isModuleOutputEnabled(). That can return true even if the module is disabled. It checks the value in core_config_data instead of checking if the module is loaded. Use isModuleEnabled() instead. See here: https://stackoverflow.com/a/13956317/1286814.

Then create a temp class name to extend.

For example:

if (Mage::helper('core')->isModuleEnabled('Amasty_Methods')) {
    class Ebizmarts_SagePaySuite_Helper_Payment_Data_Temp extends Amasty_Methods_Helper_Payment_Data {}
}  
else {
    class Ebizmarts_SagePaySuite_Helper_Payment_Data_Temp extends Mage_Payment_Helper_Data {}
}

class Ebizmarts_SagePaySuite_Helper_Payment_Data extends Ebizmarts_SagePaySuite_Helper_Payment_Data_Temp {
}

You shouldn't need to worry about adding a module dependency (in case Amasty_Methods loads before SagePaySuite), since the method only checks the <active> flag in the module xml. (All modules xml gets loaded at the start.) As long as you're not depending on any functionality in Amasty_Methods, you should be good.

  • Great that worked perfectly and exactly what I was looking for! – Greg Oct 23 '17 at 10:36

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.