From 7e21d1d0dd7a2a1c4996f9e51cf77d3a213afb98 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 5 Jul 2024 15:10:41 +0530 Subject: [PATCH] optmized the code for email prevention, created seprate class for BoOrder --- classes/BoOrder.php | 31 +++++++++++++++++++++ classes/PaymentModule.php | 21 ++++++-------- classes/webservice/WebserviceOrder.php | 1 + controllers/admin/AdminOrdersController.php | 11 -------- 4 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 classes/BoOrder.php diff --git a/classes/BoOrder.php b/classes/BoOrder.php new file mode 100644 index 000000000..edb935abc --- /dev/null +++ b/classes/BoOrder.php @@ -0,0 +1,31 @@ + +* @copyright 2010-2022 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +class BoOrder extends PaymentModule +{ + public $active = 1; + public $name = 'bo_order'; + + public function __construct() + { + $this->displayName = $this->l('Back office order'); + $this->ValidateOrderAmount = false; + } +} \ No newline at end of file diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 79fe1a90b..312b226ed 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -418,8 +418,6 @@ abstract class PaymentModuleCore extends Module // If webservice order request then no need to impose equal amounts(total cart and sent amount) condition if ($order_status->logable && number_format($cart_total_paid, _PS_PRICE_COMPUTE_PRECISION_) != number_format($amount_paid, _PS_PRICE_COMPUTE_PRECISION_) - && $this->name != 'wsorder' - && $this->name != 'bo_order' && (!isset($this->ValidateOrderAmount) || $this->validateOrderAmount) ) { // if customer is paying full payment amount @@ -1106,7 +1104,11 @@ abstract class PaymentModuleCore extends Module $order = new Order((int)$order->id); // Send an e-mail to customer (one order = one email) - if ($id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_OS_CANCELED') && $this->context->customer->id) { + if ($id_order_state != Configuration::get('PS_OS_ERROR') + && $id_order_state != Configuration::get('PS_OS_CANCELED') + && $this->context->customer->id + && $send_mails + ) { $invoice = new Address($order->id_address_invoice); $delivery = new Address($order->id_address_delivery); $delivery_state = $delivery->id_state ? new State($delivery->id_state) : false; @@ -1248,9 +1250,7 @@ abstract class PaymentModuleCore extends Module // Send order confirmation/overbooking mails to the reciepients according to the order mail configuration $overBookingStates = OrderState::getOverBookingStates(); $isOverBookingStatus = in_array($id_order_state, $overBookingStates); - if (Configuration::get('PS_ORDER_CONF_MAIL_TO_CUSTOMER') - && $send_mails - ){ + if (Configuration::get('PS_ORDER_CONF_MAIL_TO_CUSTOMER')){ // If order currenct state is overbooking, the send overbooking email or send order confirmation email if ($isOverBookingStatus) { $subject = Mail::l('Order Not Confirmed', (int)$order->id_lang); @@ -1302,9 +1302,7 @@ abstract class PaymentModuleCore extends Module } } } - if (Configuration::get('PS_ORDER_CONF_MAIL_TO_SUPERADMIN') - && $send_mails - ){ + if (Configuration::get('PS_ORDER_CONF_MAIL_TO_SUPERADMIN')){ // get superadmin employees if ($superAdminEmployees = Employee::getEmployeesByProfile(_PS_ADMIN_PROFILE_, true)) { // If order currenct state is overbooking, the send overbooking email or send order confirmation email @@ -1339,10 +1337,7 @@ abstract class PaymentModuleCore extends Module } } } - if ($idHotel - && Validate::isLoadedObject($objHotel = new HotelBranchInformation($idHotel)) - && $send_mails - ) { + if ($idHotel && Validate::isLoadedObject($objHotel = new HotelBranchInformation($idHotel))) { if (Configuration::get('PS_ORDER_CONF_MAIL_TO_HOTEL_MANAGER')){ // If order currenct state is overbooking, the send overbooking email or send order confirmation email if ($isOverBookingStatus) { diff --git a/classes/webservice/WebserviceOrder.php b/classes/webservice/WebserviceOrder.php index 4b1d337e4..53f9edbee 100644 --- a/classes/webservice/WebserviceOrder.php +++ b/classes/webservice/WebserviceOrder.php @@ -26,5 +26,6 @@ class WebserviceOrderCore extends PaymentModule public function __construct() { $this->displayName = $this->l('Order from API'); + $this->ValidateOrderAmount = false; } } diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index d56966e0c..df3855665 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -24,17 +24,6 @@ * International Registered Trademark & Property of PrestaShop SA */ -class BoOrder extends PaymentModule -{ - public $active = 1; - public $name = 'bo_order'; - - public function __construct() - { - $this->displayName = $this->l('Back office order'); - } -} - /** * @property Order $object */