سؤال

Does anyone know how to implement a custom "module" that is triggered when an order is paid or complete?

And how am I able to call the order data from that observer?

I am also working with the "Serial Codes" plugin, and I want to send an email to the person who bought this product, containing the serial code.

Is there anybody who is able to help me out?

هل كانت مفيدة؟

المحلول

You can write an observer for the sales_order_save_before event. In the observer method you are able to get the order by $observer->getEvent()->getOrder(). Then you can check for the order status/state and add your code when the order is completed. This is the safest way, with the small downside, that the Observer function will always be triggered when the order is saved. Example Code:

public function onCompleteOrder(Varien_Event_Observer $observer)
{
    /** @var $order Mage_Sales_Model_Order */
    $order = $observer->getEvent()->getOrder();

    if ($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE) {
        // do something
    }

    return $this;
}

By the way: A Magento order is usually becoming completed when

  • An invoice has been created AND
  • a shipment has been created
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top