0

为了开发基于付款方式和事件类型的自动订单状态更改器,我创建了以下模块:

/GT/OrderFlo/etc/config.xml

    <!--?xml version="1.0"?-->
<config>
    <modules>
        <gt_orderflow>
            <version>1.0</version>
        </gt_orderflow>
    </modules>

    <global>

        <models>            
            <orderflow>
                <class>GT_OrderFlow_Model</class>
            </orderhook>
        </models>

        <events>
            <sales_order_place_after>
                <observers>
                    <order_payment_pending_autostatus>
                        <type>singleton</type>
                        <class>orderflow/observer</class>
                        <method>implementOrderStatus</method>
                    </order_payment_pending_autostatus>
                </observers>
            </sales_order_place_after>
            <sales_order_shipment_save_after>
                <observers>
                    <order_invoice_pending_autostatus>
                        <type>singleton</type>
                        <class>orderflow/observer</class>
                        <method>implementOrderStatus</method>
                    </order_invoice_pending_autostatus>
                </observers>
            </sales_order_shipment_save_after>
            <sales_order_invoice_save_commit_after>
                <observers>
                    <order_complete_autostatus>
                        <type>singleton</type>
                        <class>orderflow/observer</class>
                        <method>implementOrderStatus</method>
                    </order_complete_autostatus>
                </observers>
            </sales_order_invoice_save_commit_after>                        
        </events>

    </global>
</config>

/GT/OrderFlow/Model/Observer.php

class GT_OrderFlow_Model_Observer
{
public function implementOrderStatus($event)
{
    $order = $event->getOrder();
    $payment_method = $this->_getPaymentMethod($order);
    $this->_log('In implementOrderStatus with payment method: '.$payment_method);
    Mage::log('In implementOrderStatus with payment method: '.$payment_method);
    $next_status = "";
    return $this;
}

private function _getPaymentMethod($order)
{
    return $order->getPayment()->getMethodInstance()->getCode();
}

private function _log($message)
{
    return Mage::log($message, null, 'gt_orderflow.log');
}
}

该代码是从http://www.atwix.com/magento/auto-invoice-and-custom-order-status-upon-checkout/复制而来的。

但是我怎样才能让它在sales_order_place_after事件发生后解雇观察者呢?

4

2 回答 2

0

您的模块是否已加载?您将需要一个文件在/app/etc/modules. 在相关说明中,我看到您将模块称为<gt_orderflow>但类前缀是GT_OrderFlow. 在区分大小写的文件系统上,这很重要,不会以这种方式工作。下面的节点config/modules映射到模块路径。

于 2013-01-22T23:02:59.237 回答
0

我认为你有一个错字

<models>             
    <orderflow>  
    -----^
        <class>GT_OrderFlow_Model</class>
    </orderhook>
    -----^
</models>
于 2013-01-22T23:53:53.150 回答