I think this is a really easy question but given my level in programming it's not that easy for me.

I wonder if there is a way of stopping or don't trigger an observer after some event ocurrs, this is because the observer that I am doing is in an infinite loop and I want to stop it from doing that loop.

I hope it's my question is clearly enough.

Thanks

UPDATE: An example could be: The observer is trigger in the event: core_config_data_save_after and when this observer is started you want to update a value in the core_config_data table, but when you save it the observer is started again and there is the loop

有帮助吗?

解决方案

One possible solution would be to use the registry and set a flag - you simply return from your observer should the registry flag be set on any future hits.

i.e.

public function myObserver(Varien_Event_Observer $observer)
{
    if (Mage::registry('my_observer_has_run')) {
        return $this;
    }

    .... Your Code Here ....

    Mage::register('my_observer_has_run', true);
}

其他提示

You should be able to locate the observer your wanting and set <type>disabled</type>

<frontend>
<events>
        <controller_action_predispatch>
            <observers>
                <log>
                    <class>log/visitor</class>
                    <method>initByRequest</method>
                </log>
            </observers>
        </controller_action_predispatch>
        .... other events
    </events>

locally modified XML to disable the above found observer:

<frontend>
    <events>
        <controller_action_predispatch>
            <observers><log><type>disabled</type></log></observers>
        </controller_action_predispatch>
    </events>
</frontend>

Code and and more details:

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top