3

Via layout.xml you can add the node ifconfig that will allow for the admin to enable/disable parts of an extension. An example is in the sales section:

ifconfig="sales/msrp/enabled"

My question is, without adding a check to all my observer methods in a module, is there a way have a similar flag on observers?

Example is if you had a module that does one thing on an observer but you want to disable this on a store level.

3
  • 1
    Not possible unless your rewrite the Mage_Core_Model_App::dispatchEvent. See how that method works. I guess you have to put the verification inside your observer.
    – Marius
    Commented Jun 13, 2014 at 13:52
  • boo, that is a shame feels odd wrapping each part with the same check :( Commented Jun 13, 2014 at 13:54
  • 1
    I know. But those are the rules. take it or leave it :)
    – Marius
    Commented Jun 13, 2014 at 14:01

2 Answers 2

2

So as pointed out by Marius there is no built in way of doing this :( There are two options for making this sort of thing happen.

  1. Rewrite how the function dispatchEvent works to check for this sort of flag on each item,
  2. Just continue to check on each observer function itself,

I will stick with the second option as I really don't want to be be changing how Mage_Core_Model_App works. Though it may be an idea that could be looked into at a hackathon or a boring evening after the World Cup is over.

0

This can be reference:

File:

app/code/core/Mage/Core/Model/Layout.php

    protected function _generateAction($node, $parent) {

      if (isset($node['ifconfig']) && ($configPath = (string)$node['ifconfig'])) {
        if (!Mage::getStoreConfigFlag($configPath)) {
            return $this;
        }
      }
2
  • Thanks for the answer. I am aware how the layout does this but my question was if/how it would be possible for observers. Commented Jun 13, 2014 at 13:44
  • I am not sure it does Commented Jun 13, 2014 at 13:49

Your Answer

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

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