Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: Variable in validateOrder function call of the payment module to prevent the emails on the order validation process. #1138

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions classes/BoOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* 2010-2022 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <[email protected]>
* @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;
}
}
67 changes: 38 additions & 29 deletions classes/PaymentModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ abstract class PaymentModuleCore extends Module
public $currencies = true;
public $currencies_mode = 'checkbox';
public $payment_type = OrderPayment::PAYMENT_TYPE_REMOTE_PAYMENT;
public $validateOrderAmount = true;

public function install()
{
Expand Down Expand Up @@ -162,7 +163,7 @@ public function addCheckboxCountryRestrictionsForModule(array $shops = array())
*/
public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown',
$message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false,
$secure_key = false, Shop $shop = null)
$secure_key = false, Shop $shop = null, $send_mails = true)
{
if (self::DEBUG_MODE) {
PrestaShopLogger::addLog('PaymentModule::validateOrder - Function called', 1, null, 'Cart', (int)$id_cart, true);
Expand Down Expand Up @@ -418,8 +419,7 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
// 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'
&& ($this->validateOrderAmount)
) {
// if customer is paying full payment amount
$id_order_state = Configuration::get('PS_OS_ERROR');
Expand Down Expand Up @@ -684,24 +684,25 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
if ($voucher->add()) {
// If the voucher has conditions, they are now copied to the new voucher
CartRule::copyConditions($cart_rule['obj']->id, $voucher->id);

$params = array(
'{voucher_amount}' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false),
'{voucher_num}' => $voucher->code,
'{firstname}' => $this->context->customer->firstname,
'{lastname}' => $this->context->customer->lastname,
'{id_order}' => $order->reference,
'{order_name}' => $order->getUniqReference()
);
Mail::Send(
(int)$order->id_lang,
'voucher',
sprintf(Mail::l('New voucher for your order %s', (int)$order->id_lang), $order->reference),
$params,
$this->context->customer->email,
$this->context->customer->firstname.' '.$this->context->customer->lastname,
null, null, null, null, _PS_MAIL_DIR_, false, (int)$order->id_shop
);
if ($send_mails) {
$params = array(
'{voucher_amount}' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false),
'{voucher_num}' => $voucher->code,
'{firstname}' => $this->context->customer->firstname,
'{lastname}' => $this->context->customer->lastname,
'{id_order}' => $order->reference,
'{order_name}' => $order->getUniqReference()
);
Mail::Send(
(int)$order->id_lang,
'voucher',
sprintf(Mail::l('New voucher for your order %s', (int)$order->id_lang), $order->reference),
$params,
$this->context->customer->email,
$this->context->customer->firstname.' '.$this->context->customer->lastname,
null, null, null, null, _PS_MAIL_DIR_, false, (int)$order->id_shop
);
}
}
}

Expand Down Expand Up @@ -1050,10 +1051,12 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
// Set the order status
$new_history = new OrderHistory();
$new_history->id_order = (int)$order->id;

$new_history->changeIdOrderState((int)$id_order_state, $order, true);

$new_history->addWithemail(true, $extra_vars);
if ($send_mails) {
$new_history->addWithemail(true, $extra_vars);
} else {
$new_history->add(true);
}

// Switch to back order if needed
$objHotelBookingDetail = new HotelBookingDetail();
Expand Down Expand Up @@ -1089,7 +1092,11 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
$history = new OrderHistory();
$history->id_order = (int)$order->id;
$history->changeIdOrderState($id_order_state, $order, true);
$history->addWithemail();
if ($send_mails) {
$history->addWithemail();
} else {
$history->add();
}
}

unset($order_detail);
Expand All @@ -1098,7 +1105,11 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
$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;
Expand Down Expand Up @@ -1327,9 +1338,7 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
}
}
}
if ($idHotel
&& Validate::isLoadedObject($objHotel = new HotelBranchInformation($idHotel))
) {
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) {
Expand Down
1 change: 1 addition & 0 deletions classes/webservice/WebserviceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ class WebserviceOrderCore extends PaymentModule
public function __construct()
{
$this->displayName = $this->l('Order from API');
$this->validateOrderAmount = false;
}
}
11 changes: 0 additions & 11 deletions controllers/admin/AdminOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down