Skip to main content
Post Undeleted by Pratik Oza
deleted 396 characters in body
Source Link
Pratik Oza
  • 4k
  • 12
  • 17

Try following codesales_order_place_after: This event is dispatched after the order payment is placed.

<?php
use Magento\Framework\Event\ObserverInterface;

class Example implements ObserverInterface
{
    protected $orderFactory;

    public$order function= __construct$observer->getEvent(
        \Magento\Quote\Model\QuoteFactory $quoteFactory,
        \Magento\Sales\Model\Order $orderFactory
    ) {
        $this->orderFactory = $orderFactory;
    }

    public function execute>getOrder(\Magento\Framework\Event\Observer $observer);
  $incrementId = {$order->getIncrementId();
        $orderIds

sales_order_save_after: This event is called every time the order is saved. For eg. Order status changed, invoiced, shipped & credit memo.

$order = $observer->getEvent()->getOrderIds>getOrder();
        $orderId = $orderIds[0];
    }
}$order->getId();

Try following code:

<?php
use Magento\Framework\Event\ObserverInterface;

class Example implements ObserverInterface
{
    protected $orderFactory;

    public function __construct(
        \Magento\Quote\Model\QuoteFactory $quoteFactory,
        \Magento\Sales\Model\Order $orderFactory
    ) {
        $this->orderFactory = $orderFactory;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $orderIds = $observer->getEvent()->getOrderIds();
        $orderId = $orderIds[0];
    }
}

sales_order_place_after: This event is dispatched after the order payment is placed.

$order = $observer->getEvent()->getOrder();
$incrementId = $order->getIncrementId();

sales_order_save_after: This event is called every time the order is saved. For eg. Order status changed, invoiced, shipped & credit memo.

$order = $observer->getEvent()->getOrder();
$orderId = $order->getId();
Post Deleted by Pratik Oza
Source Link
Pratik Oza
  • 4k
  • 12
  • 17

Try following code:

<?php
use Magento\Framework\Event\ObserverInterface;

class Example implements ObserverInterface
{
    protected $orderFactory;

    public function __construct(
        \Magento\Quote\Model\QuoteFactory $quoteFactory,
        \Magento\Sales\Model\Order $orderFactory
    ) {
        $this->orderFactory = $orderFactory;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $orderIds = $observer->getEvent()->getOrderIds();
        $orderId = $orderIds[0];
    }
}