From 1edb92ac3c1f2a4389610ff219bc8423b9a77f9a Mon Sep 17 00:00:00 2001 From: Lucas van Staden Date: Tue, 15 Apr 2014 16:45:58 +0800 Subject: [PATCH] Change how invoice email is done to an observer event --- .../community/Fontis/EwayAu/Model/Direct.php | 22 -------- .../Fontis/EwayAu/Model/Observer.php | 54 +++++++++++++++++++ .../community/Fontis/EwayAu/etc/config.xml | 11 ++++ 3 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 src/app/code/community/Fontis/EwayAu/Model/Observer.php diff --git a/src/app/code/community/Fontis/EwayAu/Model/Direct.php b/src/app/code/community/Fontis/EwayAu/Model/Direct.php index a0cd30a..1dadf4b 100644 --- a/src/app/code/community/Fontis/EwayAu/Model/Direct.php +++ b/src/app/code/community/Fontis/EwayAu/Model/Direct.php @@ -374,26 +374,4 @@ public function parseXmlResponse($xmlResponse) return $newResArr; } - - /** - * Check if invoice email can be sent, and send it - * - * @param Mage_Sales_Model_Order_Invoice $invoice - * @param Mage_Sales_Model_Order_Payment $payment - * @return Fontis_EwayAu_Model_Direct - */ - public function processInvoice($invoice, $payment) - { - parent::processInvoice($invoice, $payment); - try { - $storeId = $invoice->getOrder()->getStoreId(); - if (Mage::helper('sales')->canSendNewInvoiceEmail($storeId)) { - $invoice->save(); - $invoice->sendEmail(); - } - } catch (Exception $e) { - mage::logException($e); - } - return $this; - } } diff --git a/src/app/code/community/Fontis/EwayAu/Model/Observer.php b/src/app/code/community/Fontis/EwayAu/Model/Observer.php new file mode 100644 index 0000000..cf5140e --- /dev/null +++ b/src/app/code/community/Fontis/EwayAu/Model/Observer.php @@ -0,0 +1,54 @@ +getOrder(); + if ($order->hasInvoices()) { + foreach ($order->getInvoiceCollection() as $invoice) { + // email out the invoices + try { + $storeId = $invoice->getOrder()->getStoreId(); + if (Mage::helper('sales')->canSendNewInvoiceEmail($storeId)) { + $invoice->sendEmail(); + } + } catch (Exception $e) { + mage::logException($e); + } + } + } + return $this; + } + +} diff --git a/src/app/code/community/Fontis/EwayAu/etc/config.xml b/src/app/code/community/Fontis/EwayAu/etc/config.xml index 3f7a550..ca4a664 100644 --- a/src/app/code/community/Fontis/EwayAu/etc/config.xml +++ b/src/app/code/community/Fontis/EwayAu/etc/config.xml @@ -74,6 +74,17 @@ + + + + + singleton + ewayau/observer + checkout_submit_all_after + + + +