1

私は本当にこれで自分を打ち負かしてきました。誰かが私を助けてくれることを願っています。

いくつかのオブザーバー イベントが完全に機能していますが、機能していないように見えるのは 1 つだけです。

creditmemoRefund 関数は、注文にコメントを追加しません。注文 2 は正常に動作し、意図したとおりに確実に発火し、注文オブジェクトをプルします。コメントを追加しないのはなぜですか?

これが私のコードです...

config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Avi_OrderAudit>
      <version>0.0.1</version>
    </Avi_OrderAudit>
  </modules>
  <global>
<helpers>
  <orderaudit>
    <class>Avi_OrderAudit_Helper</class>
  </orderaudit>
</helpers>
<models>
  <orderaudit>
    <class>Avi_OrderAudit_Model</class>
    <resourceModel>orderaudit_mysql4</resourceModel>
  </orderaudit>
</models>
<events>
  <sales_order_place_after> <!-- identifier of the event we want to catch -->
    <observers>
      <sales_order_place_after_handler> <!-- identifier of the event handler -->
        <type>model</type> <!-- class method call type; valid are model, object and singleton -->
        <class>orderaudit/observer</class> <!-- observers class alias -->
        <method>orderPlaced</method>  <!-- observer's method to be called -->
        <args></args> <!-- additional arguments passed to observer -->
      </sales_order_place_after_handler>
    </observers>
  </sales_order_place_after>
  <sales_order_payment_capture> <!-- identifier of the event we want to catch -->
    <observers>
      <sales_order_payment_capture_handler> <!-- identifier of the event handler -->
        <type>model</type> <!-- class method call type; valid are model, object and singleton -->
        <class>orderaudit/observer</class> <!-- observers class alias -->
        <method>paymentCapture</method>  <!-- observer's method to be called -->
        <args></args> <!-- additional arguments passed to observer -->
      </sales_order_payment_capture_handler>
    </observers>
  </sales_order_payment_capture>
  <sales_order_creditmemo_refund> <!-- identifier of the event we want to catch -->
    <observers>
      <sales_order_creditmemo_refund_handler> <!-- identifier of the event handler -->
        <type>model</type> <!-- class method call type; valid are model, object and singleton -->
        <class>orderaudit/observer</class> <!-- observers class alias -->
        <method>creditmemoRefund</method>  <!-- observer's method to be called -->
        <args></args> <!-- additional arguments passed to observer -->
      </sales_order_creditmemo_refund_handler>
    </observers>
  </sales_order_creditmemo_refund>
</events>

Observer.php クラス Avi_OrderAudit_Model_Observer {

    public function orderPlaced(Varien_Event_Observer $observer)
    {
        if (Mage::getSingleton('admin/session')->isLoggedIn()) {
        //if admin
            $order = $observer->getEvent()->getOrder();
            $user = Mage::getSingleton('admin/session');
            $username = $user->getUser()->getUsername();
            $comment = "Order placed by <strong>".$username."</strong>";
            $order->addStatusHistoryComment($comment)
                ->setIsVisibleOnFront(false)
                ->setIsCustomerNotified(false);
        }
        else {
        //placed by customer online
            $order = $observer->getEvent()->getOrder();
            $order->addStatusHistoryComment('Order placed online by customer')
                ->setIsVisibleOnFront(false)
                ->setIsCustomerNotified(false);
        }
    }

    public function paymentCapture(Varien_Event_Observer $observer)
    {
        $invoice = $observer->getEvent()->getInvoice();
        $order = $invoice->getOrder();
        $user = Mage::getSingleton('admin/session');
        $username = $user->getUser()->getUsername();
        $comment = "Payment captured by <strong>".$username."</strong>";
        $order->addStatusHistoryComment($comment)
            ->setIsVisibleOnFront(false)
            ->setIsCustomerNotified(false);
    }
    public function creditmemoRefund(Varien_Event_Observer $observer)
    {
        $creditmemo = $observer->getEvent()->getCreditmemo();
        $order = $creditmemo->getOrder();
        $user = Mage::getSingleton('admin/session');
        $username = $user->getUser()->getUsername();
        $comment = "Refund by <strong>".$username."</strong>";
        $order->addStatusHistoryComment($comment)
            ->setIsVisibleOnFront(false)
            ->setIsCustomerNotified(false);

    }
}
4

1 に答える 1