diff --git a/admin/themes/default/template/controllers/orders/modals/_add_product.tpl b/admin/themes/default/template/controllers/orders/modals/_add_product.tpl index 862f86584..8e19a24a2 100644 --- a/admin/themes/default/template/controllers/orders/modals/_add_product.tpl +++ b/admin/themes/default/template/controllers/orders/modals/_add_product.tpl @@ -65,9 +65,8 @@ - {if sizeof($invoices_collection)} -
+
+ + diff --git a/classes/Cart.php b/classes/Cart.php index f435da614..24e8a1b49 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1633,6 +1633,8 @@ class CartCore extends ObjectModel $ecotax_total = 0; $totalDemandsPrice = 0; $objCartBookingData = new HotelCartBookingData(); + $objServiceProductCartDetail = new ServiceProductCartDetail(); + $objAdvPayment = new HotelAdvancedPayment(); foreach ($products as $product) { // skip products if selection os for only room or only normal products if ($product['booking_product']) { @@ -1745,7 +1747,6 @@ class CartCore extends ObjectModel } if (!$product['booking_product']) { if (Product::SELLING_PREFERENCE_STANDALONE == $product['selling_preference_type']) { - $objServiceProductCartDetail = new ServiceProductCartDetail(); if ($servicePorducts = $objServiceProductCartDetail->getServiceProductsInCart( $this->id, [], @@ -1771,7 +1772,6 @@ class CartCore extends ObjectModel } else if (Product::SELLING_PREFERENCE_HOTEL_STANDALONE == $product['selling_preference_type'] || Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE == $product['selling_preference_type'] ) { - $objServiceProductCartDetail = new ServiceProductCartDetail(); if ($type == Cart::ONLY_ROOM_SERVICES || $type == Cart::ONLY_CONVENIENCE_FEE || $type == Cart::ONLY_ROOM_SERVICES_WITHOUT_AUTO_ADD @@ -1822,7 +1822,6 @@ class CartCore extends ObjectModel } } } else if (Product::SELLING_PREFERENCE_WITH_ROOM_TYPE == $product['selling_preference_type']) { - $objServiceProductCartDetail = new ServiceProductCartDetail(); if ($servicesWithRoom = $objServiceProductCartDetail->getServiceProductsInCart( $this->id, [], @@ -1877,7 +1876,6 @@ class CartCore extends ObjectModel // If customer has selected advance payment of the cart if ($type == Cart::ADVANCE_PAYMENT || $type == Cart::ADVANCE_PAYMENT_ONLY_PRODUCTS) { - $objAdvPayment = new HotelAdvancedPayment(); $advProductPrice = $objAdvPayment->getProductMinAdvPaymentAmountByIdCart( $this->id, $cartRoomInfo['id_product'], diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 6b10f40e4..8bbf7373b 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -996,7 +996,7 @@ abstract class PaymentModuleCore extends Module if ($hotelProducts = $objServiceProductCartDetail->getServiceProductsInCart( $this->context->cart->id, [], - null, + $product['id_hotel'], 0, null, $product['id_product'] @@ -1334,7 +1334,6 @@ abstract class PaymentModuleCore extends Module '{products_txt}' => $product_list_txt, '{discounts}' => $cart_rules_list_html, '{discounts_txt}' => $cart_rules_list_txt, - '{total_paid}' => Tools::displayPrice($total_paid, $this->context->currency, false), '{total_products}' => Tools::displayPrice($total_products, $this->context->currency, false), '{total_discounts}' => Tools::displayPrice(-$order->total_discounts, $this->context->currency, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $this->context->currency, false), diff --git a/classes/Product.php b/classes/Product.php index 07ab39229..34f8b3b59 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -4110,51 +4110,50 @@ class ProductCore extends ObjectModel if (!$context) { $context = Context::getContext(); } + $sql = 'SELECT p.`id_product`, pl.`name`, p.`ean13`, p.`upc`, p.`active`, p.`reference`, m.`name` AS manufacturer_name, stock.`quantity`, product_shop.advanced_stock_management, p.`customizable`, p.`booking_product`, p.`allow_multiple_quantity` + FROM `'._DB_PREFIX_.'product` p + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.') + LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (p.`id_manufacturer` = m.`id_manufacturer`)'; + $sql .= Product::sqlStock('p', 0); + $sql .= Shop::addSqlAssociation('product', 'p'); - $sql = new DbQuery(); - $sql->select('p.`id_product`, pl.`name`, p.`ean13`, p.`upc`, p.`active`, p.`reference`, m.`name` AS manufacturer_name, stock.`quantity`, product_shop.advanced_stock_management, p.`customizable`, p.`booking_product`'); - $sql->from('product', 'p'); - $sql->join(Shop::addSqlAssociation('product', 'p')); - $sql->leftJoin('product_lang', 'pl', ' - p.`id_product` = pl.`id_product` - AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl') - ); - $sql->leftJoin('manufacturer', 'm', 'm.`id_manufacturer` = p.`id_manufacturer`'); - if ($booking_product) { - if ($id_hotel) { - $sql->innerJoin( - 'htl_room_type', - 'hrt', - 'p.`id_product` = hrt.`id_product` AND hrt.`id_hotel` = '.(int)$id_hotel - ); - } - } else { - if (Product::SELLING_PREFERENCE_HOTEL_STANDALONE == $selling_preference_type && $id_hotel) { - $sql->innerJoin( - 'htl_room_type_service_product', - 'hrtsp', - 'p.`id_product` = hrtsp.`id_product` AND hrtsp.`id_element` = '.(int)$id_hotel.' AND hrtsp.`element_type` = '.(int)RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL - ); + if ($id_hotel) { + if (!is_null($booking_product)) { + if ($booking_product) { + $sql .= ' INNER JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product` AND hrt.`id_hotel` = '.(int)$id_hotel.')'; + } else { + $sql .= ' INNER JOIN `'._DB_PREFIX_.'htl_room_type_service_product` hrtsp ON (p.`id_product` = hrtsp.`id_product` AND hrtsp.`id_element` = '.(int)$id_hotel.' AND hrtsp.`element_type` = '.(int)RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL.')'; + } + } else { + $sql .= ' LEFT JOIN `'._DB_PREFIX_.'htl_room_type` hrt ON (p.`id_product` = hrt.`id_product` AND hrt.`id_hotel` = '.(int)$id_hotel.')'; + $sql .= ' LEFT JOIN `'._DB_PREFIX_.'htl_room_type_service_product` hrtsp ON (p.`id_product` = hrtsp.`id_product` AND hrtsp.`id_element` = '.(int)$id_hotel.' AND hrtsp.`element_type` = '.(int)RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL.')'; } } - $where = 'pl.`name` LIKE \'%'.pSQL($query).'%\' + $sql .= ' WHERE 1'; + if (!is_null($booking_product)) { + $sql .= $booking_product ? ' AND p.`booking_product` = 1' : ' AND p.`booking_product` = 0'; + } elseif ($id_hotel) { + $sql .= ' AND IF (p.`booking_product` = 1, (p.`id_product` = hrt.`id_product`) , (p.`id_product` = hrtsp.`id_product` AND hrtsp.`id_element` = '.(int)$id_hotel.' AND hrtsp.`element_type` = '.(int)RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL.'))'; + } + if ($selling_preference_type) { + $sql .= ' AND p.`selling_preference_type` = '.(int)$selling_preference_type; + } + + $sql .= ' AND (pl.`name` LIKE \'%'.pSQL($query).'%\' OR p.`ean13` LIKE \'%'.pSQL($query).'%\' OR p.`upc` LIKE \'%'.pSQL($query).'%\' OR p.`reference` LIKE \'%'.pSQL($query).'%\' OR p.`supplier_reference` LIKE \'%'.pSQL($query).'%\' OR EXISTS(SELECT * FROM `'._DB_PREFIX_.'product_supplier` sp WHERE sp.`id_product` = p.`id_product` AND `product_supplier_reference` LIKE \'%'.pSQL($query).'%\')'; - - $sql->orderBy('pl.`name` ASC'); - if (Combination::isFeatureActive()) { - $where .= ' OR EXISTS(SELECT * FROM `'._DB_PREFIX_.'product_attribute` `pa` WHERE pa.`id_product` = p.`id_product` AND (pa.`reference` LIKE \'%'.pSQL($query).'%\' + $sql .= ' OR EXISTS(SELECT * FROM `'._DB_PREFIX_.'product_attribute` `pa` WHERE pa.`id_product` = p.`id_product` AND (pa.`reference` LIKE \'%'.pSQL($query).'%\' OR pa.`supplier_reference` LIKE \'%'.pSQL($query).'%\' OR pa.`ean13` LIKE \'%'.pSQL($query).'%\' - OR pa.`upc` LIKE \'%'.pSQL($query).'%\'))'; + OR pa.`upc` LIKE \'%'.pSQL($query).'%\')))'; } - $sql->where($where); - $sql->join(Product::sqlStock('p', 0)); + + $sql .= ' ORDER BY pl.`name` ASC'; $result = Db::getInstance()->executeS($sql); diff --git a/classes/order/Order.php b/classes/order/Order.php index ac2fc6107..fbbbadc4b 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2654,16 +2654,16 @@ class OrderCore extends ObjectModel // check rooms in booking $objHotelBooking = new HotelBookingdetail(); if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) { - $res = $res && $this->checkList($orderBookings, $action, $includeCheckIn); + $res &= $this->checkList($orderBookings, $action, $includeCheckIn); } // check hotel linked products $objServiceProductOrderDetail = new ServiceProductOrderDetail(); if ($hotelProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($this->id, 0, 0, Product::SELLING_PREFERENCE_HOTEL_STANDALONE)) { - $res = $res && $this->checkList($hotelProducts, $action, false); + $res &= $this->checkList($hotelProducts, $action, false); } if ($standaloneProducts = $objServiceProductOrderDetail->getServiceProductsInOrder($this->id, 0, 0, Product::SELLING_PREFERENCE_STANDALONE)) { - $res = $res && $this->checkList($standaloneProducts, $action, false); + $res &= $this->checkList($standaloneProducts, $action, false); } return $res; diff --git a/classes/order/OrderReturn.php b/classes/order/OrderReturn.php index 0026d8af5..508746c2a 100644 --- a/classes/order/OrderReturn.php +++ b/classes/order/OrderReturn.php @@ -368,7 +368,7 @@ class OrderReturnCore extends ObjectModel } $sql = 'SELECT orr.`id_order`, orr.`state`, orr.`id_order_return`, orr.`payment_mode`, orr.`id_transaction`, orr.`id_return_type`, orr.`return_type`, ors.`id_cart_rule`, orr.`date_add`, orr.`date_upd`, orr.`refunded_amount`, - hbd.`is_cancelled`, IF(ord.`id_htl_booking`, COUNT(ord.`id_htl_booking`), 0) AS total_rooms + hbd.`is_cancelled`, SUM(IF(ord.`id_htl_booking`, 1, 0)) AS total_rooms FROM `'._DB_PREFIX_.'order_return` orr LEFT JOIN `'._DB_PREFIX_.'order_return_detail` ord ON (ord.`id_order_return` = orr.`id_order_return`) diff --git a/classes/pdf/HTMLTemplateInvoice.php b/classes/pdf/HTMLTemplateInvoice.php index fcdcef77e..99dc872fb 100644 --- a/classes/pdf/HTMLTemplateInvoice.php +++ b/classes/pdf/HTMLTemplateInvoice.php @@ -325,10 +325,11 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate $totalDemandsPriceTE = 0; $totalDemandsPriceTI = 0; foreach ($order_details as $type_key => $type_value) { - if (isset($processed_product[$type_value['product_id'].'_'.$type_value['selling_preference_type']])) { + $processProuctKey = $type_value['product_id'].'_'.$type_value['selling_preference_type'].'_'.$type_value['id_order_detail']; + if (isset($processed_product[$processProuctKey])) { continue; } - $processed_product[$type_value['product_id'].'_'.$type_value['selling_preference_type']] = $type_value['product_id']; + $processed_product[$processProuctKey] = $type_value['product_id']; if ($type_value['is_booking_product']) { if ($display_product_images) { diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 3759e3d9b..018dc37b5 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1129,6 +1129,7 @@ class AdminOrdersControllerCore extends AdminController array( 'order' => $objOrder, 'currency' => new Currency($objOrder->id_currency), + 'invoices_collection' => $objOrder->getInvoicesCollection(), ) ); $modal = array( @@ -1188,6 +1189,7 @@ class AdminOrdersControllerCore extends AdminController $smartyVars['orderCurrency'] = $objOrder->id_currency; $smartyVars['currencySign'] = $objCurrency->sign; $smartyVars['link'] = $this->context->link; + $smartyVars['invoices_collection'] = $objOrder->getInvoicesCollection(); // set context currency So that we can get prices in the order currency $this->context->currency = $objCurrency; @@ -3804,7 +3806,8 @@ class AdminOrdersControllerCore extends AdminController (int)$this->context->language->id, pSQL(Tools::getValue('product_search')), 0, - Product::SELLING_PREFERENCE_HOTEL_STANDALONE + null, + $idHotel )) { $objServiceProductOption = new ServiceProductOption(); foreach ($products as $key => &$product) { @@ -5066,16 +5069,24 @@ class AdminOrdersControllerCore extends AdminController $response['error'] = Tools::displayError('The order object cannot be loaded.'); } elseif (!Validate::isUnsignedInt($productInformations['product_quantity'])) { $response['status'] = false; - $response['error'] = Tools::displayError('Please Enter a valid Quantity.'); + $response['error'] = Tools::displayError('Please enter a valid quantity.'); } elseif (!Validate::isPrice($productInformations['product_price_tax_incl'])) { $response['status'] = false; $response['error'] = Tools::displayError('Please enter a valid tax included price.'); } elseif (!Validate::isPrice($productInformations['product_price_tax_excl'])) { $response['status'] = false; $response['error'] = Tools::displayError('Please enter a valid tax excluded price.'); + } elseif (!Validate::isPrice(($productInformations['product_quantity'] * $productInformations['product_price_tax_incl']))) { + $response['status'] = false; + $response['error'] = Tools::displayError('The product can not be added with entered price and quantities.'); } elseif (!Validate::isLoadedObject($objProduct = new Product($idProduct, false, $objOrder->id_lang))) { $response['status'] = false; $response['error'] = Tools::displayError('The product object cannot be loaded.'); + } elseif ($objProduct->booking_product + || $objProduct->selling_preference_type == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE + ) { + $response['status'] = false; + $response['error'] = Tools::displayError('Invalid product. Please try adding any other product.'); } elseif ($objProduct->selling_preference_type != Product::SELLING_PREFERENCE_STANDALONE && (!$addressTax->id_hotel || !Validate::isLoadedObject($objHotel = new HotelBranchInformation($addressTax->id_hotel))) @@ -5169,7 +5180,7 @@ class AdminOrdersControllerCore extends AdminController } if ($response['status']) { - // If product is standalone the we have to create a new order for this product + // If product is standalone and current order is for a hotel then we have to create a new order for this product $response['new_id_order'] = 0; if ($objProduct->selling_preference_type == Product::SELLING_PREFERENCE_STANDALONE && $addressTax->id_hotel) { $objPaymentModule = new BoOrder(); @@ -5202,7 +5213,7 @@ class AdminOrdersControllerCore extends AdminController $response['error'] = Tools::displayError('Some error occurred while processing the order.'); } } else { - // If product is Hotel standalone then we will ad in the same orders + // If product is Hotel standalone then we will add in the same orders // If order is valid, we can create a new invoice or edit an existing invoice if ($objOrder->hasInvoice()) { @@ -5240,8 +5251,8 @@ class AdminOrdersControllerCore extends AdminController $objOrderInvoice->add(); } else { // Update current invoice - $objOrderInvoice->total_paid_tax_excl += (float)$objCart->getOrderTotal(false, $total_method); - $objOrderInvoice->total_paid_tax_incl += (float)$objCart->getOrderTotal($useTaxes, $total_method); + $objOrderInvoice->total_paid_tax_excl += (float)$objCart->getOrderTotal(false, $totalMethod); + $objOrderInvoice->total_paid_tax_incl += (float)$objCart->getOrderTotal($useTaxes, $totalMethod); $objOrderInvoice->total_products += (float)$objCart->getOrderTotal(false, Cart::ONLY_PRODUCTS); $objOrderInvoice->total_products_wt += (float)$objCart->getOrderTotal($useTaxes, Cart::ONLY_PRODUCTS); $objOrderInvoice->update(); @@ -5827,6 +5838,15 @@ class AdminOrdersControllerCore extends AdminController )) { $response['status'] = false; $response['error'] = Tools::displayError('Product information not found.'); + } elseif (!Validate::isUnsignedInt($editProductInfo['product_quantity'])) { + $response['status'] = false; + $response['error'] = Tools::displayError('Please enter a valid quantity.'); + } elseif (!Validate::isPrice($editProductInfo['product_price_tax_excl'])) { + $response['status'] = false; + $response['error'] = Tools::displayError('Please enter a valid tax excluded price.'); + } elseif (!Validate::isPrice(($editProductInfo['product_quantity'] * $editProductInfo['product_price_tax_excl']))) { + $response['status'] = false; + $response['error'] = Tools::displayError('The product can not be added with entered price and quantities.'); } if ($response['status']) { diff --git a/controllers/front/OrderConfirmationController.php b/controllers/front/OrderConfirmationController.php index c55620e57..0517ad6bb 100644 --- a/controllers/front/OrderConfirmationController.php +++ b/controllers/front/OrderConfirmationController.php @@ -376,6 +376,13 @@ class OrderConfirmationControllerCore extends FrontController $type_value['total_price_tax_incl'] = $serviceProduct['total_price_tax_incl']; $type_value['product_quantity'] = $serviceProduct['quantity']; $type_value['option_name'] = $serviceProduct['option_name']; + $type_value['location'] = $serviceProduct['option_name']; + + if ($hotelInfo = $objHtlBranchInfo->hotelBranchesInfo($this->context->language->id, 2, 1, $serviceProduct['id_hotel'])) { + $type_value['hotel_location'] = $hotelInfo['hotel_name'].', '.$hotelInfo['city']. + ($hotelInfo['state_name']?', '.$hotelInfo['state_name']:'').', '. + $hotelInfo['country_name'].', '.$hotelInfo['postcode']; + } $cart_hotel_service_products[] = $type_value; } } else if ($type_value['selling_preference_type'] == Product::SELLING_PREFERENCE_STANDALONE) { diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 2ade98d22..d35f793c3 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -467,7 +467,7 @@ class OrderDetailControllerCore extends FrontController 'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id), 'refundReqBookings' => $refundReqBookings, 'refundReqProducts' => $refundReqProducts, - 'completeRefundRequestOrCancel' => $order->hasCompletelyRefunded(0, 1), + 'completeRefundRequestOrCancel' => $order->hasCompletelyRefunded(Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG), 'refundedAmount' => $refundedAmount, 'shop_name' => strval(Configuration::get('PS_SHOP_NAME')), 'order' => $order, diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index b144bb6ef..130260393 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -433,6 +433,7 @@ class OrderOpcControllerCore extends ParentOrderController */ public function initContent() { + $this->_assignCheckoutValidationVars(); parent::initContent(); /* id_carrier is not defined in database before choosing a carrier, set it to a default one to match a potential cart _rule */ @@ -1108,6 +1109,7 @@ class OrderOpcControllerCore extends ParentOrderController { $response = array('success' => false); if ($this->context->cart->getProducts()) { + $this->_assignCheckoutValidationVars(); $this->_assignCheckoutVars(); $this->_assignShoppingCart(); $response['success'] = true; diff --git a/controllers/front/ParentOrderController.php b/controllers/front/ParentOrderController.php index 9b55fcc04..4933453a2 100644 --- a/controllers/front/ParentOrderController.php +++ b/controllers/front/ParentOrderController.php @@ -291,21 +291,26 @@ class ParentOrderControllerCore extends FrontController protected function _assignCheckoutVars() { - if ($orderRestrictErr = HotelCartBookingData::validateCartBookings()) { - $this->errors = array_merge($this->errors, $orderRestrictErr); - } $show_option_allow_separate_package = (!$this->context->cart->isAllProductsInStock(true) && Configuration::get('PS_SHIP_WHEN_AVAILABLE')); $advanced_payment_api = (bool)Configuration::get('PS_ADVANCED_PAYMENT_API'); - $this->context->smarty->assign(array( 'THEME_DIR' => _THEME_DIR_, 'PS_ROOM_PRICE_AUTO_ADD_BREAKDOWN' => Configuration::get('PS_ROOM_PRICE_AUTO_ADD_BREAKDOWN'), - 'orderRestrictErr' => count($orderRestrictErr) ? 1 : 0, 'show_option_allow_separate_package' => $show_option_allow_separate_package, 'advanced_payment_api' => $advanced_payment_api )); } + protected function _assignCheckoutValidationVars() + { + if ($orderRestrictErr = HotelCartBookingData::validateCartBookings()) { + $this->errors = array_merge($this->errors, $orderRestrictErr); + } + $this->context->smarty->assign(array( + 'orderRestrictErr' => count($orderRestrictErr) ? 1 : 0, + )); + } + protected function _assignShoppingCart() { $summary = $this->context->cart->getSummaryDetails(); diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index d98b1faad..753e14b31 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -957,22 +957,88 @@ class HotelCartBookingData extends ObjectModel $errors[] = $objModule->l('No booking found in the cart.', 'HotelOrderRestrictDate'); } - // validate service products if not active, deleted or not associated to a specific room type then remove from cart + // validate service products if not active, deleted or not associated to a specific room type/hotels then remove from cart $objServiceProductCartDetail = new ServiceProductCartDetail(); $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); - if ($serviceProducts = $objServiceProductCartDetail->getAllServiceProduct($context->cart->id)) { + if ($serviceProducts = $objServiceProductCartDetail->getServiceProductsInCart($context->cart->id)) { foreach ($serviceProducts as $service) { + $toRemoveService = 0; if (!Validate::isLoadedObject($product = new Product($service['id_product']))) { - $objServiceProductCartDetail->removeServiceProductByIdHtlCartBooking($service['htl_cart_booking_id'], $service['id_product']); + $toRemoveService = 1; } else { if (!$product->active) { - $objServiceProductCartDetail->removeServiceProductByIdHtlCartBooking($service['htl_cart_booking_id'], $service['id_product']); + $toRemoveService = 1; } else { - if (!$objRoomTypeServiceProduct->isRoomTypeLinkedWithProduct($service['id_product_room_type'], $service['id_product'])) { - $objServiceProductCartDetail->removeServiceProductByIdHtlCartBooking($service['htl_cart_booking_id'], $service['id_product']); + if ($product->selling_preference_type == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE) { + // service with room type must have association with valid hotel cart booking + if (Validate::isLoadedObject($objHotelCartBooking = new HotelCartBookingData($service['id_hotel_cart_booking']))) { + // check if added room type is associated with valid service product + $serviceAssociations = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType( + $service['id_product'], + RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE, + $objHotelCartBooking->id_product + ); + if (!isset($serviceAssociations['room_type']) + || !in_array($objHotelCartBooking->id_product, $serviceAssociations['room_type']) + ) { + $toRemoveService = 1; + } + } else { + $toRemoveService = 1; + } + } else { + if (ServiceProductOption::productHasOptions($service['id_product'])) { + if (!Validate::isLoadedObject(new ServiceProductOption($service['id_product_option']))) { + $toRemoveService = 1; + } + } elseif ($service['id_product_option']) { + $toRemoveService = 1; + } + + if (!$toRemoveService) { + if ($product->selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE) { + // service with hotel must have association with valid hotel + if (Validate::isLoadedObject($objHotelBranch = new HotelBranchInformation($service['id_hotel']))) { + $serviceAssociations = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType( + $service['id_product'], + RoomTypeServiceProduct::WK_ELEMENT_TYPE_HOTEL, + $service['id_hotel'] + ); + if (!isset($serviceAssociations['hotel']) + || !in_array($service['id_hotel'], $serviceAssociations['hotel']) + ) { + $toRemoveService = 1; + } + } else { + $toRemoveService = 1; + } + } elseif ($product->selling_preference_type == Product::SELLING_PREFERENCE_STANDALONE) { + // Standalone product must not have any association with hotel or hotel cart booking + if ($service['id_hotel'] || $service['id_hotel_cart_booking']) { + $toRemoveService = 1; + } + } elseif ($product->selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE) { + // service with hotel or room type must have association with hotel or hotel cart booking + if (!$service['id_hotel'] && !$service['id_hotel_cart_booking']) { + $toRemoveService = 1; + } + } + } } } } + + if ($toRemoveService) { + $objServiceProductCartDetail->removeCartServiceProduct( + $context->cart->id, + null, + false, + null, + null, + null, + $service['id_service_product_cart_detail'] + ); + } } } diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php index 2099cddd8..37e30f444 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php @@ -100,10 +100,10 @@ class RoomTypeServiceProduct extends ObjectModel return Db::getInstance()->insert($this->def['table'], $rowData); } - public function getAssociatedHotelsAndRoomType($idProduct, $elementType = 0, $formated = true) { + public function getAssociatedHotelsAndRoomType($idProduct, $elementType = 0, $idElement = 0, $formated = true) { $rows = Db::getInstance()->executeS( 'SELECT * FROM `'._DB_PREFIX_.'htl_room_type_service_product` AS rsp - WHERE `id_product` = '.(int)$idProduct . ($elementType ? ' AND rsp.`element_type` = ' . (int)$elementType : "") + WHERE `id_product` = '.(int)$idProduct . ($elementType ? ' AND rsp.`element_type` = ' . (int)$elementType : "" . ($idElement ? ' AND rsp.`id_element` = ' . (int)$idElement : "")) ); if ($formated) { @@ -114,6 +114,7 @@ class RoomTypeServiceProduct extends ObjectModel } return $response; } + return $rows; } diff --git a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php index 7e7368dd4..f1c012593 100644 --- a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php @@ -42,15 +42,19 @@ class ServiceProductCartDetail extends ObjectModel public function alreadyExists( $idCart, - $idProduct, + $idProduct = false, $idHtlCartData = false, $idHotel = false, - $idProductOption = false + $idProductOption = false, + $idServiceProductCartDetail = false ) { $sql = 'SELECT `id_service_product_cart_detail` FROM `'._DB_PREFIX_.'service_product_cart_detail` - WHERE `id_product` = '.(int)$idProduct.' AND `id_cart` = '.(int)$idCart; + WHERE `id_cart` = '.(int)$idCart; + if ($idProduct) { + $sql .= ' AND `id_product` = '.(int)$idProduct; + } if ($idHotel) { $sql .= ' AND `id_hotel` = '.(int)$idHotel; } @@ -60,6 +64,9 @@ class ServiceProductCartDetail extends ObjectModel if ($idProductOption) { $sql .= ' AND `id_product_option` = '.(int)$idProductOption; } + if ($idServiceProductCartDetail) { + $sql .= ' AND `id_service_product_cart_detail` = '.(int)$idServiceProductCartDetail; + } return Db::getInstance()->getValue($sql); } @@ -146,7 +153,8 @@ class ServiceProductCartDetail extends ObjectModel $priceAdditionType = null, $groupByProductId = 0, $detailedInfo = 0, - $idLang = 0 + $idLang = 0, + $idServiceProductCartDetail = 0 ) { if ($useTax === null) { $useTax = Product::$_taxCalculationMethod == PS_TAX_EXC ? false : true; @@ -158,16 +166,15 @@ class ServiceProductCartDetail extends ObjectModel $language = new Language($idLang); } - $sql = 'SELECT spc.*, p.`selling_preference_type`, p.`price_calculation_method`'; + $sql = 'SELECT spc.*, p.`selling_preference_type`, p.`price_calculation_method`, hcbd.`id_product` as `id_product_room_type`'; if (!$getTotalPrice) { $sql .= ', hbil.`hotel_name` '; } $sql .= ' FROM `'._DB_PREFIX_.'service_product_cart_detail` spc'; $sql .= ' LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = spc.`id_product`)'; - if (!is_null($idProductRoomType)) { - $sql .= ' LEFT JOIN `'._DB_PREFIX_.'htl_cart_booking_data` hcbd ON (hcbd.`id` = spc.`htl_cart_booking_id`)'; - } + $sql .= ' LEFT JOIN `'._DB_PREFIX_.'htl_cart_booking_data` hcbd ON (hcbd.`id` = spc.`htl_cart_booking_id`)'; + if (!$getTotalPrice) { $sql .= ' LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil ON (hbil.`id` = spc.`id_hotel` AND hbil.`id_lang` = '. $language->id.')'; } @@ -201,6 +208,10 @@ class ServiceProductCartDetail extends ObjectModel $sql .= ' AND spc.`id_product_option`='.(int) $idProductOption; } + if ($idServiceProductCartDetail) { + $sql .= ' AND spc.`id_service_product_cart_detail`='.(int) $idServiceProductCartDetail; + } + if ($getTotalPrice) { $totalPrice = 0; } @@ -217,7 +228,7 @@ class ServiceProductCartDetail extends ObjectModel $objProduct->id, $product['id_product_option'], $product['id_hotel'], - false, + $product['id_product_room_type'], $useTax, $qty, null, @@ -230,7 +241,7 @@ class ServiceProductCartDetail extends ObjectModel $objProduct->id, $product['id_product_option'], $product['id_hotel'], - false, + $product['id_product_room_type'], true, 1, null, @@ -241,7 +252,7 @@ class ServiceProductCartDetail extends ObjectModel $objProduct->id, $product['id_product_option'], $product['id_hotel'], - false, + $product['id_product_room_type'], false, 1, null, @@ -413,19 +424,34 @@ class ServiceProductCartDetail extends ObjectModel public function removeCartServiceProduct( $idCart, - $idProduct, + $idProduct = null, $quantity = false, - $idHotel = false, - $idHtlCartData = false, - $idProductOption = null + $idHotel = null, + $idHtlCartData = null, + $idProductOption = null, + $idServiceProductCartDetail = 0 ) { - $updateQunatity = false; - $res = true; - - if ($idHtlCartData) { - $id_service_product_cart_detail = $this->alreadyExists($idCart, $idProduct, $idHtlCartData); - if ($id_service_product_cart_detail) { - $objServiceProductCartDetail = new ServiceProductCartDetail($id_service_product_cart_detail); + if ($serviceProducts = $this->getServiceProductsInCart( + $idCart, + [], + $idHotel, + $idHtlCartData, + null, + $idProduct, + $idProductOption, + null, + 0, + null, + null, + 0, + 0, + 0, + $idServiceProductCartDetail + )) { + $updateQunatity = false; + $res = true; + foreach ($serviceProducts as $product) { + $objServiceProductCartDetail = new ServiceProductCartDetail($product['id_service_product_cart_detail']); if ($quantity) { $removedQuantity = $quantity; $objServiceProductCartDetail->quantity -= $quantity; @@ -446,100 +472,34 @@ class ServiceProductCartDetail extends ObjectModel $controllerType = 'front'; } if ($controllerType == 'admin' || $controllerType == 'moduleadmin') { - if ($cartQty = Cart::getProductQtyInCart($idCart, $idProduct)) { + if ($cartQty = Cart::getProductQtyInCart($idCart, $product['id_product '])) { if ($removedQuantity < $cartQty) { - $res = $res && Db::getInstance()->update( + $res &= Db::getInstance()->update( 'cart_product', array('quantity' => (int)($cartQty - $removedQuantity)), - '`id_product` = '.(int)$idProduct.' AND `id_cart` = '.(int)$idCart + '`id_product` = '.(int)$product['id_product'].' AND `id_cart` = '.(int)$idCart ); } else { //if room type has no qty remaining in cart then delete row - $res = $res && Db::getInstance()->delete( + $res &= Db::getInstance()->delete( 'cart_product', - '`id_product` = '.(int)$idProduct.' AND `id_cart` = '.(int)$idCart + '`id_product` = '.(int)$product['id_product'].' AND `id_cart` = '.(int)$idCart ); } } } else { - $res = $res && $objCart->updateQty((int)$removedQuantity, $idProduct, null, false, 'down'); + $res &= $objCart->updateQty((int)$removedQuantity, $product['id_product'], null, false, 'down'); } } - return $res; - } else { - return true; + if ($quantity) { + break; + } } - } else { - if ($products = $this->getServiceProductsInCart( - $idCart, - [], - $idHotel, - $idHtlCartData, - null, - $idProduct, - $idProductOption - )) { - foreach ($products as $product) { - $objServiceProductCartDetail = new ServiceProductCartDetail($product['id_service_product_cart_detail']); - if ($quantity) { - $removedQuantity = $quantity; - $objServiceProductCartDetail->quantity -= $quantity; - if ($objServiceProductCartDetail->quantity) { - $updateQunatity = $objServiceProductCartDetail->save(); - } else { - $updateQunatity = $objServiceProductCartDetail->delete(); - } - } else { - $removedQuantity = $objServiceProductCartDetail->quantity; - $updateQunatity = $objServiceProductCartDetail->delete(); - } - if ($updateQunatity) { - $objCart = new Cart($idCart); - if (isset(Context::getContext()->controller->controller_type)) { - $controllerType = Context::getContext()->controller->controller_type; - } else { - $controllerType = 'front'; - } - if ($controllerType == 'admin' || $controllerType == 'moduleadmin') { - if ($cartQty = Cart::getProductQtyInCart($idCart, $idProduct)) { - if ($removedQuantity < $cartQty) { - $res = $res && Db::getInstance()->update( - 'cart_product', - array('quantity' => (int)($cartQty - $removedQuantity)), - '`id_product` = '.(int)$idProduct.' AND `id_cart` = '.(int)$idCart - ); - } else { - //if room type has no qty remaining in cart then delete row - $res = $res && Db::getInstance()->delete( - 'cart_product', - '`id_product` = '.(int)$idProduct.' AND `id_cart` = '.(int)$idCart - ); - } - } - } else { - $res = $res && $objCart->updateQty((int)$removedQuantity, $idProduct, null, false, 'down'); - } - } - if ($quantity) { - break; - } - } - return $res; - } else { - return true; - } + return $res; } - } - public function getAllServiceProduct($idCart) - { - return Db::getInstance()->executeS( - 'SELECT spcd.*, cbd.`id_product` as `id_product_room_type`, cbd.`id_room`, cbd.`id_hotel`, cbd.`date_from`, cbd.`date_to` FROM `' . _DB_PREFIX_ . 'service_product_cart_detail` spcd - INNER JOIN `'._DB_PREFIX_.'htl_cart_booking_data` cbd - ON(spcd.`htl_cart_booking_id` = cbd.`id`) - WHERE spcd.`id_cart` = ' . (int)$idCart - ); + return true; } public static function validateServiceProductsInCart() diff --git a/themes/hotel-reservation-theme/css/order-confirmation.css b/themes/hotel-reservation-theme/css/order-confirmation.css index 7fb64a74c..66f47a7ef 100644 --- a/themes/hotel-reservation-theme/css/order-confirmation.css +++ b/themes/hotel-reservation-theme/css/order-confirmation.css @@ -140,6 +140,11 @@ margin: 7px 0; font-weight: 400; } +.product-detail .hotel-location { + font-size: 14px; + padding: 10px 0px 0px 0px; + color: #777777; +} .product-detail dd { margin: 7px 0; font-weight: 700; diff --git a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js index 20db0a57b..7cfb95b56 100644 --- a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js +++ b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js @@ -805,7 +805,6 @@ var ajaxCart = { } $('.vouchers').show(); } - }, // Update product quantity @@ -844,7 +843,7 @@ var ajaxCart = { if (parseInt(this.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE || parseInt(this.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE ) { - if (typeof value.hotel_wise_data != 'undefined' && value.hotel_wise_data.length) { + if (typeof value.hotel_wise_data != 'undefined') { $(value.hotel_wise_data).each(function(i, val) { ajaxCart.addProductRow(value, val); }); @@ -887,11 +886,12 @@ var ajaxCart = { content += '
'; content += 'Price:'; content += ' '; + if (product.booking_product) { content += formatCurrency(parseFloat(product.bookingData.total_room_type_amount), currency_format, currency_sign, currency_blank); }else if ((parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE || parseInt(product.selling_preference_type) == SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE) - && (typeof(hotel_wise_data) != 'undefined' && hotel_wise_data.length) + && (typeof(hotel_wise_data) != 'undefined') ) { content += formatCurrency(parseFloat(hotel_wise_data.amount), currency_format, currency_sign, currency_blank); } else { diff --git a/themes/hotel-reservation-theme/order-confirmation.tpl b/themes/hotel-reservation-theme/order-confirmation.tpl index 696fe35b9..d23fbf032 100644 --- a/themes/hotel-reservation-theme/order-confirmation.tpl +++ b/themes/hotel-reservation-theme/order-confirmation.tpl @@ -231,6 +231,11 @@ {$product.product_name|escape:'html':'UTF-8'}{if isset($product.option_name) && $product.option_name} : {$product.option_name|escape:'html':'UTF-8'}{/if}

+ {if isset($product['hotel_location'])} +

+  {$product['hotel_location']} +

+ {/if}
diff --git a/themes/hotel-reservation-theme/order-detail.tpl b/themes/hotel-reservation-theme/order-detail.tpl index 2af8dda97..19e0053ad 100644 --- a/themes/hotel-reservation-theme/order-detail.tpl +++ b/themes/hotel-reservation-theme/order-detail.tpl @@ -217,12 +217,7 @@ {block name='order_detail_refund_requests'} {if (isset($refundReqBookings) && $refundReqBookings) || (isset($refundReqProducts) && $refundReqProducts)} {/if} {/block}