1

I'm currently going through the Magento Developer Certification Preparation Study Group Guide and doing the exercises. I've come across the following question and I have no idea what to do with it:

Create a dynamic rewrite of the payment/data helper only if the version of Magento is older than version 1.4, and if the ccsave payment option is enabled for the current store.

I can get the version number with Mage::app()->getVersion() and and check if ccsave is is enabled with Mage::app()->getStoreConfig('payment/ccsave/active/') but as far as I can tell one can't use these in their config.xml.

I also thought I might be able to do these checks in the _construct() method but there doesn't seem to be one for Mage_Payment_Helper_Data

Any ideas?

1

Handle an event like controller pre dispatch, get the config object and replace xml node for the helper for given version only.

The main objective here is to understand 1) you may modify xml via config object 2) rewrites are also part of big configuration xml and the can be handled dynamically.

  • Nice one, makes a lot of sense. – hammygoonan Aug 6 '14 at 16:17
0

One approach could be to rewrite the helper for all versions and decide in the method if you do your logic or just return the parent method's result, for example:

public function getInfoBlock(Mage_Payment_Model_Info $info)
{
    if (Mage::getVersion() > '1.4.0' && Mage::app()->getStoreConfig('payment/ccsave/active') {
        // do my logic
    } else {
        return parent::getInfoBlock($info)
    }
}
  • I understand the returning parent method bit, but I'm not sure why you're rewriting the model here. It was the helper that is meant to be overridden – hammygoonan Aug 6 '14 at 16:03
  • @Goonanism sorry, I mistyped. I meant to override the helper. – Thorsten Aug 7 '14 at 6:58

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.