Skip to main content

I want to inform customers with email all the details of their orders and iI want to be able to show the difference. For example:

Those items shipped: ...
Those items canceledcancelled: ...
Those items ...

credit memo, hold, invoice, ship, reorder, create returns... There so many situations. What should be the best way to achieve this?

Still I tried to use events for invoices (sales_order_invoice_save_after - sales_order_invoice_register):

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $order = $observer->getEvent()->getOrder();
    $stateProcessing = $order::STATE_PROCESSING;

    $collection = $order->getItemsCollection();
    foreach ($collection as $item) {
        $this->logger->info('item = '.$item->getName());
        $this->logger->info('   qty_invoiced = '.$item->getData('qty_invoiced'));
        $this->logger->info('   qty_invoicedorig = '.$item->getOrigData('qty_invoiced'));
    }

    return $this;
}

But quantities are the same, couldn't get the difference.

I want to inform customers with email all details of their orders and i want to be able to show difference. For example:

Those items shipped: ...
Those items canceled: ...
Those items ...

credit memo, hold, invoice, ship, reorder, create returns... There so many situations. What should be the best way to achieve this?

Still I tried to use events for invoices (sales_order_invoice_save_after - sales_order_invoice_register):

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $order = $observer->getEvent()->getOrder();
    $stateProcessing = $order::STATE_PROCESSING;

    $collection = $order->getItemsCollection();
    foreach ($collection as $item) {
        $this->logger->info('item = '.$item->getName());
        $this->logger->info('   qty_invoiced = '.$item->getData('qty_invoiced'));
        $this->logger->info('   qty_invoicedorig = '.$item->getOrigData('qty_invoiced'));
    }

    return $this;
}

But quantities are same, couldn't get the difference.

I want to inform customers with email all the details of their orders and I want to be able to show the difference. For example:

Those items shipped: ...
Those items cancelled: ...
Those items ...

credit memo, hold, invoice, ship, reorder, create returns... There so many situations. What should be the best way to achieve this?

Still I tried to use events for invoices (sales_order_invoice_save_after - sales_order_invoice_register):

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $order = $observer->getEvent()->getOrder();
    $stateProcessing = $order::STATE_PROCESSING;

    $collection = $order->getItemsCollection();
    foreach ($collection as $item) {
        $this->logger->info('item = '.$item->getName());
        $this->logger->info('   qty_invoiced = '.$item->getData('qty_invoiced'));
        $this->logger->info('   qty_invoicedorig = '.$item->getOrigData('qty_invoiced'));
    }

    return $this;
}

But quantities are the same, couldn't get the difference.

Source Link
iskorum
  • 103
  • 5

Magento 2 - Order Item changes

I want to inform customers with email all details of their orders and i want to be able to show difference. For example:

Those items shipped: ...
Those items canceled: ...
Those items ...

credit memo, hold, invoice, ship, reorder, create returns... There so many situations. What should be the best way to achieve this?

Still I tried to use events for invoices (sales_order_invoice_save_after - sales_order_invoice_register):

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $order = $observer->getEvent()->getOrder();
    $stateProcessing = $order::STATE_PROCESSING;

    $collection = $order->getItemsCollection();
    foreach ($collection as $item) {
        $this->logger->info('item = '.$item->getName());
        $this->logger->info('   qty_invoiced = '.$item->getData('qty_invoiced'));
        $this->logger->info('   qty_invoicedorig = '.$item->getOrigData('qty_invoiced'));
    }

    return $this;
}

But quantities are same, couldn't get the difference.