From 0f17dec89e2a0a7c925953f4dda8737d98f112da Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Tue, 7 Mar 2023 11:58:37 +0000 Subject: [PATCH] remove disbale services from cart' --- controllers/front/OrderOpcController.php | 3 +++ modules/bankwire/controllers/front/payment.php | 3 +++ .../bankwire/controllers/front/validation.php | 3 +++ modules/cheque/controllers/front/payment.php | 3 +++ modules/cheque/controllers/front/validation.php | 3 +++ .../classes/RoomTypeServiceProductCartDetail.php | 16 ++++++++++++++++ 6 files changed, 31 insertions(+) diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index f5a5bec2b..f787834b5 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -389,6 +389,9 @@ class OrderOpcControllerCore extends ParentOrderController */ public function initContent() { + // check all service products are available + RoomTypeServiceProductCartDetail::validateServiceProductsInCart(); + parent::initContent(); // check ORDER RESTRICT condition before payment by the customer diff --git a/modules/bankwire/controllers/front/payment.php b/modules/bankwire/controllers/front/payment.php index cee1fe886..59dc5ab17 100644 --- a/modules/bankwire/controllers/front/payment.php +++ b/modules/bankwire/controllers/front/payment.php @@ -50,6 +50,9 @@ class BankwirePaymentModuleFrontController extends ModuleFrontController $total = $cart->getOrderTotal(true, Cart::BOTH); } + // check all service products are available + RoomTypeServiceProductCartDetail::validateServiceProductsInCart(); + $restrict_order = false; /*Check Order restrict condition before Payment by the customer*/ if (Module::isInstalled('hotelreservationsystem') && Module::isEnabled('hotelreservationsystem')) { diff --git a/modules/bankwire/controllers/front/validation.php b/modules/bankwire/controllers/front/validation.php index c96ff78ec..5df9b7411 100644 --- a/modules/bankwire/controllers/front/validation.php +++ b/modules/bankwire/controllers/front/validation.php @@ -49,6 +49,9 @@ class BankwireValidationModuleFrontController extends ModuleFrontController if (!$authorized) die($this->module->l('This payment method is not available.', 'validation')); + // check all service products are available + RoomTypeServiceProductCartDetail::validateServiceProductsInCart(); + // Check Order restrict condition before Payment by the customer if (Module::isInstalled('hotelreservationsystem') && Module::isEnabled('hotelreservationsystem')) { require_once _PS_MODULE_DIR_.'hotelreservationsystem/define.php'; diff --git a/modules/cheque/controllers/front/payment.php b/modules/cheque/controllers/front/payment.php index e1415337d..1d5e0f76b 100644 --- a/modules/cheque/controllers/front/payment.php +++ b/modules/cheque/controllers/front/payment.php @@ -50,6 +50,9 @@ class ChequePaymentModuleFrontController extends ModuleFrontController $total = $cart->getOrderTotal(true, Cart::BOTH); } + // check all service products are available + RoomTypeServiceProductCartDetail::validateServiceProductsInCart(); + $restrict_order = false; /*Check Order restrict condition before Payment by the customer*/ if (Module::isInstalled('hotelreservationsystem') && Module::isEnabled('hotelreservationsystem')) { diff --git a/modules/cheque/controllers/front/validation.php b/modules/cheque/controllers/front/validation.php index 6f75120a9..f280abd3f 100644 --- a/modules/cheque/controllers/front/validation.php +++ b/modules/cheque/controllers/front/validation.php @@ -48,6 +48,9 @@ class ChequeValidationModuleFrontController extends ModuleFrontController if (!$authorized) die($this->module->l('This payment method is not available.', 'validation')); + // check all service products are available + RoomTypeServiceProductCartDetail::validateServiceProductsInCart(); + /*Check Order restrict condition before Payment by the customer*/ if (Module::isInstalled('hotelreservationsystem') && Module::isEnabled('hotelreservationsystem')) { require_once _PS_MODULE_DIR_.'hotelreservationsystem/define.php'; diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php index eafa043bb..f9446f9f9 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProductCartDetail.php @@ -341,4 +341,20 @@ class RoomTypeServiceProductCartDetail extends ObjectModel } return false; } + + public static function validateServiceProductsInCart() + { + $context = Context::getContext(); + if ($cartProducts = $context->cart->getProducts()) { + $objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail(); + foreach ($cartProducts as $product) { + if (!$product['active'] && !$product['booking_product']) { + $serviceProducts = $objRoomTypeServiceProductCartDetail->getServiceProductsInCart($context->cart->id, $product['id_product']); + foreach ($serviceProducts as $serviceProduct) { + $objRoomTypeServiceProductCartDetail->removeServiceProductByIdHtlCartBooking($serviceProduct['htl_cart_booking_id']); + } + } + } + } + } } \ No newline at end of file