From d476f9ae52a295a1b75b7e5f35bdf19712dc029c Mon Sep 17 00:00:00 2001 From: Daniil Tkachev Date: Mon, 14 Oct 2024 14:21:04 +0200 Subject: [PATCH] UNZER-497 Send order confirmation only on order with status OK --- src/Model/Order.php | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/src/Model/Order.php b/src/Model/Order.php index 1b39ad2c..54d41b0d 100644 --- a/src/Model/Order.php +++ b/src/Model/Order.php @@ -36,15 +36,13 @@ class Order extends Order_parent * @param Basket $oBasket * @param User $oUser * @return int|bool - * @throws Exception - * @throws \Doctrine\DBAL\Driver\Exception - * + * @throws \UnzerSDK\Exceptions\UnzerApiException * @SuppressWarnings(PHPMD.ElseExpression) */ public function finalizeUnzerOrderAfterRedirect( Basket $oBasket, User $oUser - ) { + ): bool|int { $orderId = Registry::getSession()->getVariable('sess_challenge'); $orderId = is_string($orderId) ? $orderId : ''; $iRet = self::ORDER_STATE_PAYMENTERROR; @@ -64,21 +62,13 @@ public function finalizeUnzerOrderAfterRedirect( $unzerService = $this->getServiceFromContainer(Unzer::class); $unzerPaymentStatus = $paymentService->getUnzerPaymentStatus(); - // copies user info $this->setUser($oUser); - // copies user info $this->assignUserInformation($oUser); - - // copies basket info $this->loadFromBasket($oBasket); $oUserPayment = $this->setPayment($oBasket->getPaymentId()); - - // set folder information, order is new $this->setFolder(); - - //saving all order data to DB $this->save(); if (!$this->getFieldData('oxordernr')) { @@ -90,35 +80,22 @@ public function finalizeUnzerOrderAfterRedirect( $this->setUnzerOrderNr((string)$unzerOrderId); $unzerService->resetUnzerOrderId(); - // deleting remark info only when order is finished Registry::getSession()->deleteVariable('ordrem'); - - //#4005: Order creation time is not updated when order processing is complete $this->updateOrderDate(); - - // store orderid $oBasket->setOrderId($orderId); - - // updating wish lists $this->updateWishlist($oBasket->getContents(), $oUser); - - // updating users notice list $this->updateNoticeList($oBasket->getContents(), $oUser); - - // marking vouchers as used and sets them to $this->_aVoucherList (will be used in order email) $this->markVouchers($oBasket, $oUser); - - // send order by email to shop owner and current user - // don't let order fail due to stock check while sending out the order mail - Registry::getSession()->setVariable('blDontCheckProductStockForUnzerMails', true); - $iRet = $this->sendOrderByEmail($oUser, $oBasket, $oUserPayment); - Registry::getSession()->deleteVariable('blDontCheckProductStockForUnzerMails'); - $this->setOrderStatus($unzerPaymentStatus); if ($unzerPaymentStatus === 'OK') { $this->markUnzerOrderAsPaid(); $this->setTmpOrderStatus($unzerOrderId, 'FINISHED'); + // send order by email to shop owner and current user + // don't let order fail due to stock check while sending out the order mail + Registry::getSession()->setVariable('blDontCheckProductStockForUnzerMails', true); + $iRet = $this->sendOrderByEmail($oUser, $oBasket, $oUserPayment); + Registry::getSession()->deleteVariable('blDontCheckProductStockForUnzerMails'); } else { Registry::getSession()->setVariable('orderCancellationProcessed', true); $this->setOrderStatus($unzerPaymentStatus); //ERROR if paypal