Magento Enterprise Catalog活动

发布于 2025-01-03 03:49:04 字数 1160 浏览 0 评论 0原文

我正在开发一个扩展,该扩展将在保存时从 Magento(企业)接收 CatalogEvent 信息,并对信息进行自定义处理。

这是我用来监听事件的代码:

<?xml version="1.0"?>
<config>
  <global>
    <models>
        <mage4ucustomredirect>
             <class>Mage4u_Customredirect</class>
        </mage4ucustomredirect>
    </models>
    <events>
       <enterprise_catalogevent_event>
            <observers>
                <abc>
                    <type>singleton</type>
                    <class>Mage4u_Customredirect_Model_Observer</class>
                    <method>on_enterprise_catalogevent_event</method>
                </abc>
            </observers>
       </enterprise_catalogevent_event>
    </events>
  </global>
</config>

这是观察者:

class Mage4u_Customredirect_Model_Observer
{
    public function on_enterprise_catalogevent_event(Varien_Event_Observer $observer)
    {  
        Mage::log( "on_enterprise_catalogevent_event" );
    }

}
?>

当我保存 CatalogEvent 时,我没有收到调用。你能发现我的代码有什么问题吗?

I'm working on an extension that will receive CatalogEvent information from Magento (Enterprise) when saved and do custom processing on the information.

Here's the code I use to listen to the event:

<?xml version="1.0"?>
<config>
  <global>
    <models>
        <mage4ucustomredirect>
             <class>Mage4u_Customredirect</class>
        </mage4ucustomredirect>
    </models>
    <events>
       <enterprise_catalogevent_event>
            <observers>
                <abc>
                    <type>singleton</type>
                    <class>Mage4u_Customredirect_Model_Observer</class>
                    <method>on_enterprise_catalogevent_event</method>
                </abc>
            </observers>
       </enterprise_catalogevent_event>
    </events>
  </global>
</config>

and this is the observer:

class Mage4u_Customredirect_Model_Observer
{
    public function on_enterprise_catalogevent_event(Varien_Event_Observer $observer)
    {  
        Mage::log( "on_enterprise_catalogevent_event" );
    }

}
?>

When I save the CatalogEvent, I do not receive the call. Can you spot any problems with my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不忘初心 2025-01-10 03:49:04

您的观察者不会被调用,因为 enterprise_catalog_event 是一个模型,但不是事件

请参阅 app/code/core/Enterprise/CatalogEvent/etc/config.xml

<config>
    :
    <global>
        <models>
            <enterprise_catalogevent>
                <class>Enterprise_CatalogEvent_Model</class>
                <resourceModel>enterprise_catalogevent_resource</resourceModel>
            </enterprise_catalogevent>
            <enterprise_catalogevent_resource>
                :
                <entities>
                    <event>
                        <table>enterprise_catalogevent_event</table>
                    </event>
                    :
                </entities>
            </enterprise_catalogevent_resource>
        </models>
        :
    </global>
    :
</config>

Afaik enterprise_catalogevent/event 不会调度自己的保存事件,但您可以观察通用 < code>model_save_before 或 model_save_after 事件,用于在创建/保存此类模型时接收回调。

您只需要首先识别传递给这些通用事件的对象:

$oObject = $observer->getEvent()->getObject();
if ($oObject instanceof Enterprise_CatalogEvent_Model_Event) {
    if ($oObject->isObjectNew()) {
        // it is/was a create
    else {
        // it is/was a save
    }        
}

Your observer isn't called, because enterprise_catalog_event is a model, but not an event.

See app/code/core/Enterprise/CatalogEvent/etc/config.xml:

<config>
    :
    <global>
        <models>
            <enterprise_catalogevent>
                <class>Enterprise_CatalogEvent_Model</class>
                <resourceModel>enterprise_catalogevent_resource</resourceModel>
            </enterprise_catalogevent>
            <enterprise_catalogevent_resource>
                :
                <entities>
                    <event>
                        <table>enterprise_catalogevent_event</table>
                    </event>
                    :
                </entities>
            </enterprise_catalogevent_resource>
        </models>
        :
    </global>
    :
</config>

Afaik enterprise_catalogevent/event does not dispatch its own save events, but you could observe the generic model_save_before or model_save_after event, to receive callbacks whenever such model is being created/saved.

You just need to identify the object being passed to these generic events first:

$oObject = $observer->getEvent()->getObject();
if ($oObject instanceof Enterprise_CatalogEvent_Model_Event) {
    if ($oObject->isObjectNew()) {
        // it is/was a create
    else {
        // it is/was a save
    }        
}
夏末染殇 2025-01-10 03:49:04

请尝试这个:

<events>
   <enterprise_catalogevent_event>
        <observers>
            <mage4u_customredirect_model_observer>
                <type>singleton</type>
                <class>Mage4u_Customredirect_Model_Observer</class>
                <method>on_enterprise_catalogevent_event</method>
            </mage4u_customredirect_model_observer>
        </observers>
   </enterprise_catalogevent_event>
</events>

Please try this:

<events>
   <enterprise_catalogevent_event>
        <observers>
            <mage4u_customredirect_model_observer>
                <type>singleton</type>
                <class>Mage4u_Customredirect_Model_Observer</class>
                <method>on_enterprise_catalogevent_event</method>
            </mage4u_customredirect_model_observer>
        </observers>
   </enterprise_catalogevent_event>
</events>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文