From ae99928dcd3817bb5c4dc1af955586259a3243ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Sch=C3=A4fer?= Date: Mon, 17 Jan 2022 09:14:12 +0100 Subject: [PATCH] Use more generic event, SUP-6318 --- .../AutomaticInvoices/Model/Observer.php | 72 +++++++++---------- .../Spranks/AutomaticInvoices/etc/config.xml | 6 +- 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/app/code/community/Spranks/AutomaticInvoices/Model/Observer.php b/app/code/community/Spranks/AutomaticInvoices/Model/Observer.php index 601238a..f37b135 100644 --- a/app/code/community/Spranks/AutomaticInvoices/Model/Observer.php +++ b/app/code/community/Spranks/AutomaticInvoices/Model/Observer.php @@ -9,53 +9,47 @@ class Spranks_AutomaticInvoices_Model_Observer * * @param Varien_Event_Observer $observer */ - public function checkoutSubmitAllAfter(Varien_Event_Observer $observer) + public function salesModelServiceQuoteSubmitAfter(Varien_Event_Observer $observer) { /** @var Spranks_AutomaticInvoices_Helper_Config $helper */ $helper = Mage::helper('spranks_automaticinvoices/config'); // if module is disabled, do nothing - if ( ! $helper->isActive()) { + if (!$helper->isActive()) { return; } - // get the order from the onepage checkout or the orderS from the multishipping checkout - $orders = $observer->getOrders(); - if (empty($orders)) { - $orders = array($observer->getOrder()); - if (empty($orders)) { - return; - } + $order = $observer->getOrder(); + if (empty($order)) { + return; } - foreach ($orders as $order) { - /* @var $order Mage_Sales_Model_Order */ - // if orders with this payment method should not be invoiced, do nothing - if ( ! $helper->shouldInvoiceOrder($order)) { - continue; - } - // if order can be invoiced / has not been invoiced yet, invoice it - if ($order->canInvoice()) { - $captureCase = $helper->getCaptureInvoice($order); - /* @var $invoice Mage_Sales_Model_Order_Invoice */ - $invoice = $order->prepareInvoice(); - $invoice->setRequestedCaptureCase($captureCase); - $invoice->register(); - $invoice->getOrder()->setIsInProcess(true); - Mage::getModel('core/resource_transaction') - ->addObject($invoice) - ->addObject($invoice->getOrder()) - ->save(); - } else { - // order has already been invoiced, so get the invoice - $invoice = $order->getInvoiceCollection()->getFirstItem(); - } - // if invoice mail should not be sent, do nothing more - if ( ! $helper->shouldSendInvoiceEmail($order)) { - continue; - } - // if invoice has not been sent to the customer yet, send it now - if ($invoice && ! $invoice->getEmailSent()) { - $invoice->sendEmail(); - } + /* @var $order Mage_Sales_Model_Order */ + // if orders with this payment method should not be invoiced, do nothing + if (!$helper->shouldInvoiceOrder($order)) { + return; + } + // if order can be invoiced / has not been invoiced yet, invoice it + if ($order->canInvoice()) { + $captureCase = $helper->getCaptureInvoice($order); + /* @var $invoice Mage_Sales_Model_Order_Invoice */ + $invoice = $order->prepareInvoice(); + $invoice->setRequestedCaptureCase($captureCase); + $invoice->register(); + $invoice->getOrder()->setIsInProcess(true); + Mage::getModel('core/resource_transaction') + ->addObject($invoice) + ->addObject($invoice->getOrder()) + ->save(); + } else { + // order has already been invoiced, so get the invoice + $invoice = $order->getInvoiceCollection()->getFirstItem(); + } + // if invoice mail should not be sent, do nothing more + if (!$helper->shouldSendInvoiceEmail($order)) { + return; + } + // if invoice has not been sent to the customer yet, send it now + if ($invoice && !$invoice->getEmailSent()) { + $invoice->sendEmail(); } } diff --git a/app/code/community/Spranks/AutomaticInvoices/etc/config.xml b/app/code/community/Spranks/AutomaticInvoices/etc/config.xml index b651b01..2767b9c 100644 --- a/app/code/community/Spranks/AutomaticInvoices/etc/config.xml +++ b/app/code/community/Spranks/AutomaticInvoices/etc/config.xml @@ -22,15 +22,15 @@ - + model spranks_automaticinvoices/observer - checkoutSubmitAllAfter + salesModelServiceQuoteSubmitAfter - +