سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top