diff --git a/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl b/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl index 088c112e8..f4df39166 100644 --- a/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl +++ b/admin/themes/default/template/controllers/orders/_current_cart_details_data.tpl @@ -115,22 +115,14 @@ {/if} - {if $data.feature_price_diff != 0} - {assign var=shown_room_type_price value=$data.feature_price_tax_excl} - {else} - {assign var=shown_room_type_price value=$data.product_price_tax_excl} - {/if} + {assign var=shown_room_type_price value=$data.feature_price_tax_excl}
{$currency->prefix}{$currency->suffix}
- {if (isset($data.extra_demands) && $data.extra_demands) || (isset($data.additional_service) && $data.additional_service)} - {displayPrice price=($data.demand_price + $data.additional_service_price + $data.additional_services_auto_add_price)|escape:'html':'UTF-8'} - {else} - {displayPrice price=0} - {/if} + {displayPrice price=($data.demand_price + $data.additional_service_price + $data.additional_services_auto_add_price)|escape:'html':'UTF-8'} {* {displayPrice price=$data.amt_with_qty} *} @@ -145,12 +137,10 @@ - {if (isset($data.extra_demands) && $data.extra_demands) || isset($data.additional_service) && $data.additional_service} -
- -  {l s='Services'} - - {/if} +
+ +  {l s='Services'} + {/foreach} diff --git a/admin/themes/default/template/controllers/orders/modals/_add_order_extra_services_tab_content.tpl b/admin/themes/default/template/controllers/orders/modals/_add_order_extra_services_tab_content.tpl index 768510abc..12147b3d6 100644 --- a/admin/themes/default/template/controllers/orders/modals/_add_order_extra_services_tab_content.tpl +++ b/admin/themes/default/template/controllers/orders/modals/_add_order_extra_services_tab_content.tpl @@ -147,6 +147,7 @@
diff --git a/admin/themes/default/template/controllers/orders/modals/_extra_services_service_products_tab_content.tpl b/admin/themes/default/template/controllers/orders/modals/_extra_services_service_products_tab_content.tpl index d241a40ad..d75ddd7c9 100644 --- a/admin/themes/default/template/controllers/orders/modals/_extra_services_service_products_tab_content.tpl +++ b/admin/themes/default/template/controllers/orders/modals/_extra_services_service_products_tab_content.tpl @@ -211,6 +211,7 @@
diff --git a/admin/themes/default/template/controllers/products/lengthofstay.tpl b/admin/themes/default/template/controllers/products/lengthofstay.tpl index 3e0541b04..78befdab3 100644 --- a/admin/themes/default/template/controllers/products/lengthofstay.tpl +++ b/admin/themes/default/template/controllers/products/lengthofstay.tpl @@ -19,24 +19,42 @@ -
-
- - {l s='Day(s)'} -
-
+
+
+
+
+ + {l s='Day(s)'} +
+
+
+
+
+

{l s='Set 1 for no limit'}

+
+
+
-
-
- - {l s='Day(s)'} -
-
+
+
+
+
+ + {l s='Day(s)'} +
+
+
+
+
+

{l s='Set 0 for no limit'}

+
+
+
@@ -62,8 +80,16 @@ {l s='Date From'} {l s='Date To'} - {l s='Minimum length of stay'} - {l s='Maximum length of stay'} + + + + + + diff --git a/classes/Cart.php b/classes/Cart.php index b1e132d31..b5d1eb461 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1816,15 +1816,15 @@ class CartCore extends ObjectModel if ($servicePorducts) { foreach ($servicePorducts as $servicePorduct) { if ($with_taxes) { - $priceAdd = $servicePorduct['unit_price_tax_incl']; + $priceAdd = $servicePorduct['total_price_tax_incl']; } else { - $priceAdd = $servicePorduct['unit_price_tax_excl']; + $priceAdd = $servicePorduct['total_price_tax_excl']; } if ($ps_round_type == Order::ROUND_TOTAL) { - $products_total[$id_tax_rules_group.'_'.$id_address] += Tools::processPriceRounding($priceAdd, (int)$servicePorduct['quantity']); + $products_total[$id_tax_rules_group.'_'.$id_address] += $priceAdd; } else { - $products_total[$id_tax_rules_group] += Tools::processPriceRounding($priceAdd, (int)$servicePorduct['quantity']); + $products_total[$id_tax_rules_group] += $priceAdd; } } } diff --git a/classes/ConfigurationTest.php b/classes/ConfigurationTest.php index 25c5599fb..fe733a161 100644 --- a/classes/ConfigurationTest.php +++ b/classes/ConfigurationTest.php @@ -188,7 +188,7 @@ class ConfigurationTestCore public static function test_upload_max_filesize() { $upload_max_filesize = preg_replace('/[^0-9\.-]/', '', ini_get('upload_max_filesize')); - if ($upload_max_filesize >= 2) { + if ($upload_max_filesize >= 16) { return true; } return false; diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index f1eba0008..dde838155 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -1571,8 +1571,12 @@ abstract class PaymentModuleCore extends Module } } } - - $order->updateOrderDetailTax(); + /** + * This function is not being called because taxes are already saved correctly. + * The issue lies only in displaying the tax breakdown. + * + * $order->updateOrderDetailTax(); + */ } else { $error = Tools::displayError('Order creation failed'); PrestaShopLogger::addLog($error, 4, '0000002', 'Cart', intval($order->id_cart)); diff --git a/classes/SpecificPriceRule.php b/classes/SpecificPriceRule.php index f58edd76c..4b9f2fadc 100644 --- a/classes/SpecificPriceRule.php +++ b/classes/SpecificPriceRule.php @@ -266,6 +266,8 @@ class SpecificPriceRuleCore extends ObjectModel $result = array_merge($result, Db::getInstance()->executeS($query)); } + // Remove duplicate after the array_merge + $result = array_unique($result, SORT_REGULAR); } else { // All products without conditions if ($products && count($products)) { diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index 1ecc82811..01970232d 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -876,20 +876,35 @@ class AdminControllerCore extends Controller $filters = array(); if (isset($this->list_id)) { foreach ($_POST as $key => $value) { + if (is_array($value)) { + if ($value[0] === '' && $value[1] === '') { + $value = ''; + } else { + $value = json_encode($value); + } + } + if ($value === '') { unset($this->context->cookie->{$prefix.$key}); } elseif (stripos($key, $this->list_id.'Filter_') === 0) { - $filters[$prefix.$key] = !is_array($value) ? $value : json_encode($value); + $filters[$prefix.$key] = $value; } elseif (stripos($key, 'submitFilter') === 0) { - $this->context->cookie->$key = !is_array($value) ? $value : json_encode($value); + $this->context->cookie->$key = $value; } } foreach ($_GET as $key => $value) { + if (is_array($value)) { + if ($value[0] === '' && $value[1] === '') { + $value = ''; + } else { + $value = json_encode($value); + } + } if (stripos($key, $this->list_id.'Filter_') === 0) { - $filters[$prefix.$key] = !is_array($value) ? $value : json_encode($value); + $filters[$prefix.$key] = $value; } elseif (stripos($key, 'submitFilter') === 0) { - $this->context->cookie->$key = !is_array($value) ? $value : json_encode($value); + $this->context->cookie->$key = $value; } if (stripos($key, $this->list_id.'Orderby') === 0 && Validate::isOrderBy($value)) { if ($value === '' || $value == $this->_defaultOrderBy) { diff --git a/classes/order/Order.php b/classes/order/Order.php index abcd65007..3268193c2 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2520,78 +2520,174 @@ class OrderCore extends ObjectModel $order_ecotax_tax = 0; - $tax_rates = array(); - foreach ($order_details as $order_detail) { + $tax_rates = array(); $id_order_detail = $order_detail['id_order_detail']; + + $taxesList = OrderDetail::getTaxListStatic($id_order_detail); + if (!$taxesList) { + continue; + } + $tax_calculator = OrderDetail::getTaxCalculatorStatic($id_order_detail); - - // TODO: probably need to make an ecotax tax breakdown here instead, - // but it seems unlikely there will be different tax rates applied to the - // ecotax in the same order in the real world - $unit_ecotax_tax = $order_detail['ecotax'] * $order_detail['ecotax_tax_rate'] / 100.0; - $order_ecotax_tax += $order_detail['product_quantity'] * $unit_ecotax_tax; - - $discount_ratio = 0; - - if ($this->total_products > 0) { - $discount_ratio = ($order_detail['unit_price_tax_excl'] + $order_detail['ecotax']) / $this->total_products; - } - - // share of global discount - $discounted_price_tax_excl = $order_detail['unit_price_tax_excl'] - $discount_ratio * $order_discount_tax_excl; - // specific discount - if (!empty($product_specific_discounts[$order_detail['product_id']])) { - $discounted_price_tax_excl -= $product_specific_discounts[$order_detail['product_id']]; - } - $quantity = $order_detail['product_quantity']; + $unit_price_tax_excl = $order_detail['total_price_tax_excl'] / $quantity; + + /* + * Discounted taxes are intentionally not calculated here, as we do not want to display them. + * + * TODO: Consider implementing a proper ecotax breakdown if needed in future. + * However, it is unlikely that different tax rates would apply to ecotax within the same order. + * + * + * $unit_ecotax_tax = $order_detail['ecotax'] * $order_detail['ecotax_tax_rate'] / 100.0; + * $order_ecotax_tax += $order_detail['product_quantity'] * $unit_ecotax_tax; + * + * $discount_ratio = 0; + * if ($this->total_products > 0) { + * $discount_ratio = ($order_detail['unit_price_tax_excl'] + $order_detail['ecotax']) / $this->total_products; + * } + * + * // Apply share of global discount + * $discounted_price_tax_excl = $order_detail['unit_price_tax_excl'] - $discount_ratio * $order_discount_tax_excl; + * + * // Apply specific product-level discount + * if (!empty($product_specific_discounts[$order_detail['product_id']])) { + * $discounted_price_tax_excl -= $product_specific_discounts[$order_detail['product_id']]; + * } + */ foreach ($tax_calculator->taxes as $tax) { $tax_rates[$tax->id] = $tax->rate; } - foreach ($tax_calculator->getTaxesAmount($discounted_price_tax_excl) as $id_tax => $unit_amount) { - $total_tax_base = 0; - $total_tax_base = Tools::processPriceRounding($discounted_price_tax_excl, $quantity); - $total_amount = Tools::processPriceRounding($unit_amount, $quantity); - if (!isset($breakdown[$id_tax])) { - $breakdown[$id_tax] = array('tax_base' => 0, 'tax_amount' => 0); + $totalTaxBase = Tools::processPriceRounding($unit_price_tax_excl, $quantity); + if (!$order_detail['is_booking_product']) { + $objServiceProductOrderDetail = new ServiceProductOrderDetail(); + if ($serviceProductDetail = $objServiceProductOrderDetail->getServiceProductsInOrder( + $order_detail['id_order'], + $id_order_detail + )) { + $totals = array_reduce($serviceProductDetail, function ($carry, $item) { + if (!empty($item['id_tax_rules_group'])) { + $qty = isset($item['quantity']) ? $item['quantity'] : 0; + $price = isset($item['total_price_tax_excl']) ? $item['total_price_tax_excl'] : 0; + + $carry['quantity'] += $qty; + $carry['total_price_tax_excl'] += $price; + } + return $carry; + }, ['quantity' => 0, 'total_price_tax_excl' => 0]); + $quantity = $totals['quantity']; + $totalTaxBase = $totals['total_price_tax_excl']; } - - $breakdown[$id_tax]['tax_base'] += $total_tax_base; - $breakdown[$id_tax]['tax_amount'] += $total_amount; - - $order_detail_tax_rows[] = array( - 'id_order_detail' => $id_order_detail, - 'id_tax' => $id_tax, - 'tax_rate' => $tax_rates[$id_tax], - 'unit_tax_base' => $discounted_price_tax_excl, - 'total_tax_base' => $total_tax_base, - 'unit_amount' => $unit_amount, - 'total_amount' => $total_amount - ); - } - } - if (!empty($order_detail_tax_rows)) { - foreach ($breakdown as $data) { - $actual_total_tax += Tools::ps_round($data['tax_amount'], _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode); - $actual_total_base += Tools::ps_round($data['tax_base'], _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode); } - $order_ecotax_tax = Tools::ps_round($order_ecotax_tax, _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode); + $objServiceProductOrderDetail = new ServiceProductOrderDetail(); + $groupedTaxDetails = array(); + $additionalTaxAmounts = array(); - $tax_rounding_error = $expected_total_tax - $actual_total_tax - $order_ecotax_tax; - if ($tax_rounding_error != 0) { - Tools::spreadAmount($tax_rounding_error, _PS_PRICE_COMPUTE_PRECISION_, $order_detail_tax_rows, 'total_amount'); + if ( + $order_detail['is_booking_product'] && + $autoAddedPriceExcl = $objServiceProductOrderDetail->getRoomTypeServiceProducts( + $order_detail['id_order'], + 0, 0, + $order_detail['product_id'], + 0, 0, 0, + true, false, true, + Product::PRICE_ADDITION_TYPE_WITH_ROOM + ) + ) { + $additionalTaxAmounts = $tax_calculator->getTaxesAmount($autoAddedPriceExcl); + $totalTaxBase += $autoAddedPriceExcl; } - $base_rounding_error = $expected_total_base - $actual_total_base; - if ($base_rounding_error != 0) { - Tools::spreadAmount($base_rounding_error, _PS_PRICE_COMPUTE_PRECISION_, $order_detail_tax_rows, 'total_tax_base'); + $taxBaseShare = $totalTaxBase; + + foreach ($taxesList as $detailTax) { + $taxId = $detailTax['id_tax']; + + $unitAmount = $detailTax['unit_amount'] + ($additionalTaxAmounts[$taxId] ?? 0); + $totalAmount = $detailTax['total_amount'] + ($additionalTaxAmounts[$taxId] ?? 0); + + if (!isset($groupedTaxDetails[$taxId])) { + $groupedTaxDetails[$taxId] = array( + 'id_order_detail' => $id_order_detail, + 'id_tax' => $taxId, + 'tax_rate' => $tax_rates[$taxId], + 'unit_tax_base' => $unit_price_tax_excl, + 'total_tax_base' => $taxBaseShare, + 'unit_amount' => $unitAmount, + 'total_amount' => $totalAmount, + ); + } else { + $groupedTaxDetails[$taxId]['total_amount'] += $totalAmount; + } } + + if (!empty($groupedTaxDetails)) { + foreach ($groupedTaxDetails as $item) { + $order_detail_tax_rows[] = $item; + } + } + + /* + * This tax recalculation logic is intentionally disabled. + * + * Taxes have already been calculated and stored in the `order_detail_tax` table, + * so there is no need to recompute them here. + * + * foreach ($tax_calculator->getTaxesAmount($discounted_price_tax_excl) as $id_tax => $unit_amount) { + * $total_tax_base = 0; + * $total_tax_base = Tools::processPriceRounding($discounted_price_tax_excl, $quantity); + * $total_amount = Tools::processPriceRounding($unit_amount, $quantity); + * + * if (!isset($breakdown[$id_tax])) { + * $breakdown[$id_tax] = array('tax_base' => 0, 'tax_amount' => 0); + * } + * + * $breakdown[$id_tax]['tax_base'] += $total_tax_base; + * $breakdown[$id_tax]['tax_amount'] += $total_amount; + * + * $order_detail_tax_rows[] = array( + * 'id_order_detail' => $id_order_detail, + * 'id_tax' => $id_tax, + * 'tax_rate' => $tax_rates[$id_tax], + * 'unit_tax_base' => $discounted_price_tax_excl, + * 'total_tax_base' => $total_tax_base, + * 'unit_amount' => $unit_amount, + * 'total_amount' => $total_amount + * ); + * } + */ + } + /* + * The following tax adjustment logic was disabled as it is not currently in use. + * It was intended to handle rounding errors in tax and base amounts by spreading + * the discrepancy across order detail tax rows. However, this logic is not required + * due to updated tax calculation and breakdown handling. + */ + + // if (!empty($order_detail_tax_rows)) { + // foreach ($breakdown as $data) { + // $actual_total_tax += Tools::ps_round($data['tax_amount'], _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode); + // $actual_total_base += Tools::ps_round($data['tax_base'], _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode); + // } + + // $order_ecotax_tax = Tools::ps_round($order_ecotax_tax, _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode); + + // $tax_rounding_error = $expected_total_tax - $actual_total_tax - $order_ecotax_tax; + // if ($tax_rounding_error != 0) { + // Tools::spreadAmount($tax_rounding_error, _PS_PRICE_COMPUTE_PRECISION_, $order_detail_tax_rows, 'total_amount'); + // } + + // $base_rounding_error = $expected_total_base - $actual_total_base; + // if ($base_rounding_error != 0) { + // Tools::spreadAmount($base_rounding_error, _PS_PRICE_COMPUTE_PRECISION_, $order_detail_tax_rows, 'total_tax_base'); + // } + // } return $order_detail_tax_rows; } diff --git a/classes/order/OrderDetail.php b/classes/order/OrderDetail.php index 17b1a420e..c13878059 100644 --- a/classes/order/OrderDetail.php +++ b/classes/order/OrderDetail.php @@ -372,23 +372,6 @@ class OrderDetailCore extends ObjectModel */ public function saveTaxCalculator(Order $order, $replace = false) { - // Nothing to save - if ($this->tax_calculator == null) { - return true; - } - - if (!($this->tax_calculator instanceof TaxCalculator)) { - return false; - } - - if (count($this->tax_calculator->taxes) == 0) { - return true; - } - - if ($order->total_products <= 0) { - return true; - } - $shipping_tax_amount = 0; foreach ($order->getCartRules() as $cart_rule) { @@ -398,27 +381,171 @@ class OrderDetailCore extends ObjectModel } } - $ratio = $this->unit_price_tax_excl / $order->total_products; - $order_reduction_amount = ($order->total_discounts_tax_excl - $shipping_tax_amount) * $ratio; - $discounted_price_tax_excl = $this->unit_price_tax_excl - $order_reduction_amount; - $values = ''; - foreach ($this->tax_calculator->getTaxesAmount($discounted_price_tax_excl) as $id_tax => $amount) { - - $total_amount = Tools::processPriceRounding($amount, $this->product_quantity, $order->round_type, $order->round_mode); - - $values .= '('.(int)$this->id.','.(int)$id_tax.','.(float)$amount.','.(float)$total_amount.'),'; + $idCart = $this->context->cart->id ?? $order->id_cart; + if (empty($this->vat_address)) { + $this->vat_address = new Address((int)$order->id_address_tax); } - if ($replace) { - Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'order_detail_tax` WHERE id_order_detail='.(int)$this->id); + /** + * Calculate tax rule groups for the service product based on each associated room type. + */ + if (!$this->is_booking_product && $this->selling_preference_type == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE) { + if ($this->product_auto_add && $this->product_price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM) { + return true; + } + // Get all associated room type IDs for this service product and cart + $associatedRoomTypes = Db::getInstance()->executeS( + 'SELECT hcbd.`id_product` + FROM `'._DB_PREFIX_.'htl_cart_booking_data` hcbd + INNER JOIN `'._DB_PREFIX_.'service_product_cart_detail` spcd + ON spcd.`htl_cart_booking_id` = hcbd.`id` + WHERE spcd.`id_product` = '.(int)$this->product_id.' + AND spcd.`id_cart` = '.(int)$idCart + ); + + if (!empty($associatedRoomTypes)) { + $associatedRoomTypeIds = array_column($associatedRoomTypes, 'id_product'); + $taxGroupInfoList = array(); + $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); + foreach ($associatedRoomTypeIds as $idRoomType) { + $key = $this->product_id.'_'.$idRoomType; + if ($serviceProductPriceRoomInfo = $objRoomTypeServiceProductPrice->getProductRoomTypeLinkPriceInfo( + $this->product_id, + $idRoomType, + RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE + )) { + //Special tax rule group for the Service product accroding to Room type + $taxGroupInfoList[$key] = array( + 'id_room_type' => $idRoomType, + 'id_tax_rules_group' => $serviceProductPriceRoomInfo['id_tax_rules_group'] + ); + } else { + // Use default tax rule group for the service product + $taxGroupInfoList[$key] = array( + 'id_room_type' => $idRoomType, + 'id_tax_rules_group' => $this->id_tax_rules_group + ); + } + } + } + } + + /** + * Calculate service product tax separately for each room type because + * a service product can be attached to multiple room types with different tax rules. + */ + if (!$this->is_booking_product && isset($taxGroupInfoList) && $taxGroupInfoList) { + $objServiceProductCartDetail = new ServiceProductCartDetail(); + $objServiceProductOrderDetail = new ServiceProductOrderDetail(); + // Saving tax details according to the service product tax groups for different rooms + foreach ($taxGroupInfoList as $taxGroupInfo) { + $tax_manager = TaxManagerFactory::getManager($this->vat_address, (int)$taxGroupInfo['id_tax_rules_group']); + $this->tax_calculator = $tax_manager->getTaxCalculator(); + + if ($this->tax_calculator == null) { + continue; + } + + if (!($this->tax_calculator instanceof TaxCalculator)) { + continue; + } + + if (count($this->tax_calculator->taxes) == 0) { + continue; + } + + if ($serviceProductData = $objServiceProductOrderDetail->getRoomTypeServiceProducts( + $this->id_order, + $this->product_id, + 0, + $taxGroupInfo['id_room_type'], + )) { + $total_price_tax_excl = array_reduce($serviceProductData, function ($totalPriceTaxExcl, $item) { + return $totalPriceTaxExcl + (isset($item['total_price_tax_excl']) ? $item['total_price_tax_excl'] : 0); + }, 0); + + $serviceProductData = array_shift($serviceProductData); + + $quantity = array_reduce($serviceProductData['additional_services'], function ($totalQty, $item) { + return $totalQty + (isset($item['quantity']) ? $item['quantity'] : 0); + }, 0); + } elseif ($serviceProductData = $objServiceProductCartDetail->getServiceProductsInCart( + $idCart, + array(), + null, + null, + $taxGroupInfo['id_room_type'], + $this->product_id + )) { + $total_price_tax_excl = array_reduce($serviceProductData, function ($totalPriceTaxExcl, $item) { + return $totalPriceTaxExcl + (isset($item['total_price_tax_excl']) ? $item['total_price_tax_excl'] : 0); + }, 0); + + $quantity = array_reduce($serviceProductData, function ($totalQty, $item) { + return $totalQty + (isset($item['quantity']) ? $item['quantity'] : 0); + }, 0); + } + + if (isset($quantity) && isset($total_price_tax_excl)) { + $unit_price_tax_excl = $total_price_tax_excl / $quantity; + foreach ($this->tax_calculator->getTaxesAmount($unit_price_tax_excl) as $id_tax => $amount) { + + $total_amount = Tools::processPriceRounding($amount, $quantity, $order->round_type, $order->round_mode); + + $values .= '('.(int)$this->id.','.(int)$id_tax.','.(float)$amount.','.(float)$total_amount.'),'; + } + } + } + } else { + if ($this->tax_calculator == null) { + return true; + } + + if (!($this->tax_calculator instanceof TaxCalculator)) { + return false; + } + + if (count($this->tax_calculator->taxes) == 0) { + return true; + } + + if ($order->total_products <= 0) { + return true; + } + + $unit_price_tax_excl = $this->total_price_tax_excl / $this->product_quantity; + /* + * The logic for distributing discount proportionally across products is intentionally skipped, + * as we do not want to save taxes on discounted amounts. + * + * $ratio = $unit_price_tax_excl / $order->total_products; + * $order_reduction_amount = ($order->total_discounts_tax_excl - $shipping_tax_amount) * $ratio; + * $discounted_price_tax_excl = $unit_price_tax_excl - $order_reduction_amount; + */ + + foreach ($this->tax_calculator->getTaxesAmount($unit_price_tax_excl) as $id_tax => $amount) { + + $total_amount = Tools::processPriceRounding($amount, $this->product_quantity, $order->round_type, $order->round_mode); + + $values .= '('.(int)$this->id.','.(int)$id_tax.','.(float)$amount.','.(float)$total_amount.'),'; + } } $values = rtrim($values, ','); - $sql = 'INSERT INTO `'._DB_PREFIX_.'order_detail_tax` (id_order_detail, id_tax, unit_amount, total_amount) - VALUES '.$values; - return Db::getInstance()->execute($sql); + if ($values) { + if ($replace) { + Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'order_detail_tax` WHERE id_order_detail='.(int)$this->id); + } + + $sql = 'INSERT INTO `'._DB_PREFIX_.'order_detail_tax` (id_order_detail, id_tax, unit_amount, total_amount) + VALUES '.$values; + + return Db::getInstance()->execute($sql); + } + + return true; } public function updateTaxAmount($order) @@ -550,7 +677,7 @@ class OrderDetailCore extends ObjectModel if ($product !== null) { $this->setContext((int)$product['id_shop']); } - $id_tax_rules = (int)Product::getIdTaxRulesGroupByIdProduct((int)$this->specificPrice['id_product'], $this->context); + $id_tax_rules = (int)Product::getIdTaxRulesGroupByIdProduct((int)$this->product_id, $this->context); $tax_manager = TaxManagerFactory::getManager($this->vat_address, $id_tax_rules); $this->tax_calculator = $tax_manager->getTaxCalculator(); diff --git a/classes/order/OrderInvoice.php b/classes/order/OrderInvoice.php index 6319dc68d..3531e04ac 100644 --- a/classes/order/OrderInvoice.php +++ b/classes/order/OrderInvoice.php @@ -365,14 +365,13 @@ class OrderInvoiceCore extends ObjectModel if (!isset($grouped_details[$row['id_order_detail']])) { $grouped_details[$row['id_order_detail']] = array( 'tax_rate' => 0, - 'total_tax_base' => 0, + 'total_tax_base' => $row['total_tax_base'], 'total_amount' => 0, 'id_tax' => $row['id_tax'], ); } $grouped_details[$row['id_order_detail']]['tax_rate'] += $row['tax_rate']; - $grouped_details[$row['id_order_detail']]['total_tax_base'] += $row['total_tax_base']; $grouped_details[$row['id_order_detail']]['total_amount'] += $row['total_amount']; } $details = $grouped_details; @@ -430,14 +429,13 @@ class OrderInvoiceCore extends ObjectModel if (!isset($grouped_details[$row['id_order_detail']])) { $grouped_details[$row['id_order_detail']] = array( 'tax_rate' => 0, - 'total_tax_base' => 0, + 'total_tax_base' => $row['total_tax_base'], 'total_amount' => 0, 'id_tax' => $row['id_tax'], ); } $grouped_details[$row['id_order_detail']]['tax_rate'] += $row['tax_rate']; - $grouped_details[$row['id_order_detail']]['total_tax_base'] += $row['total_tax_base']; $grouped_details[$row['id_order_detail']]['total_amount'] += $row['total_amount']; } $details = $grouped_details; @@ -494,14 +492,13 @@ class OrderInvoiceCore extends ObjectModel if (!isset($grouped_details[$row['id_order_detail']])) { $grouped_details[$row['id_order_detail']] = array( 'tax_rate' => 0, - 'total_tax_base' => 0, + 'total_tax_base' => $row['total_tax_base'], 'total_amount' => 0, 'id_tax' => $row['id_tax'], ); } $grouped_details[$row['id_order_detail']]['tax_rate'] += $row['tax_rate']; - $grouped_details[$row['id_order_detail']]['total_tax_base'] += $row['total_tax_base']; $grouped_details[$row['id_order_detail']]['total_amount'] += $row['total_amount']; } $details = $grouped_details; @@ -563,14 +560,13 @@ class OrderInvoiceCore extends ObjectModel if (!isset($grouped_details[$row['id_order_detail']])) { $grouped_details[$row['id_order_detail']] = array( 'tax_rate' => 0, - 'total_tax_base' => 0, + 'total_tax_base' => $row['total_tax_base'], 'total_amount' => 0, 'id_tax' => $row['id_tax'], ); } $grouped_details[$row['id_order_detail']]['tax_rate'] += $row['tax_rate']; - $grouped_details[$row['id_order_detail']]['total_tax_base'] += $row['total_tax_base']; $grouped_details[$row['id_order_detail']]['total_amount'] += $row['total_amount']; } $details = $grouped_details; @@ -632,14 +628,13 @@ class OrderInvoiceCore extends ObjectModel if (!isset($grouped_details[$row['id_order_detail']])) { $grouped_details[$row['id_order_detail']] = array( 'tax_rate' => 0, - 'total_tax_base' => 0, + 'total_tax_base' => $row['total_tax_base'], 'total_amount' => 0, 'id_tax' => $row['id_tax'], ); } $grouped_details[$row['id_order_detail']]['tax_rate'] += $row['tax_rate']; - $grouped_details[$row['id_order_detail']]['total_tax_base'] += $row['total_tax_base']; $grouped_details[$row['id_order_detail']]['total_amount'] += $row['total_amount']; } $details = $grouped_details; diff --git a/classes/pdf/HTMLTemplateOrderSlip.php b/classes/pdf/HTMLTemplateOrderSlip.php index 9c1dc2579..c520fe521 100644 --- a/classes/pdf/HTMLTemplateOrderSlip.php +++ b/classes/pdf/HTMLTemplateOrderSlip.php @@ -298,14 +298,13 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice if (!isset($grouped_details[$row['id_order_detail']])) { $grouped_details[$row['id_order_detail']] = array( 'tax_rate' => 0, - 'total_tax_base' => 0, + 'total_tax_base' => $row['total_tax_base'], 'total_amount' => 0, 'id_tax' => $row['id_tax'], ); } $grouped_details[$row['id_order_detail']]['tax_rate'] += $row['tax_rate']; - $grouped_details[$row['id_order_detail']]['total_tax_base'] += $row['total_tax_base']; $grouped_details[$row['id_order_detail']]['total_amount'] += $row['total_amount']; } $details = $grouped_details; diff --git a/classes/shop/ShopUrl.php b/classes/shop/ShopUrl.php index 5e43b1aee..94d62f51f 100644 --- a/classes/shop/ShopUrl.php +++ b/classes/shop/ShopUrl.php @@ -49,8 +49,8 @@ class ShopUrlCore extends ObjectModel 'domain' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 255, 'validate' => 'isCleanHtml'), 'domain_ssl' => array('type' => self::TYPE_STRING, 'size' => 255, 'validate' => 'isCleanHtml'), 'id_shop' => array('type' => self::TYPE_INT, 'required' => true), - 'physical_uri' => array('type' => self::TYPE_STRING, 'size' => 64), - 'virtual_uri' => array('type' => self::TYPE_STRING, 'size' => 64), + 'physical_uri' => array('type' => self::TYPE_STRING, 'size' => 256), + 'virtual_uri' => array('type' => self::TYPE_STRING, 'size' => 256), ), ); diff --git a/classes/tax/TaxRulesGroup.php b/classes/tax/TaxRulesGroup.php index fda98ba26..c37d6367a 100644 --- a/classes/tax/TaxRulesGroup.php +++ b/classes/tax/TaxRulesGroup.php @@ -101,6 +101,10 @@ class TaxRulesGroupCore extends ObjectModel UPDATE '._DB_PREFIX_.'product SET id_tax_rules_group='.(int)$tax_rules_group->id.' WHERE id_tax_rules_group='.(int)$this->id) && + Db::getInstance()->execute(' + UPDATE '._DB_PREFIX_.'htl_room_type_service_product_price + SET id_tax_rules_group='.(int)$tax_rules_group->id.' + WHERE id_tax_rules_group='.(int)$this->id) && Db::getInstance()->execute(' UPDATE '._DB_PREFIX_.'product_shop SET id_tax_rules_group='.(int)$tax_rules_group->id.' diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 1bdbbf6e5..6f0019822 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -1396,7 +1396,7 @@ class AdminCartsControllerCore extends AdminController $response['errors'][] = Tools::displayError('Invalid service name'); } - if (empty($price)) { + if (!isset($price)) { $response['hasError'] = true; $response['errors'][] = Tools::displayError('Service price is required'); } elseif (!Validate::isPrice($price)) { diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php index ea35a45ff..2b99d990c 100644 --- a/controllers/admin/AdminCustomerThreadsController.php +++ b/controllers/admin/AdminCustomerThreadsController.php @@ -175,7 +175,7 @@ class AdminCustomerThreadsControllerCore extends AdminController 'id_order' => array( 'title' => $this->l('ID Order'), 'filter_key' => 'a!id_order', - 'optional' => true, + 'optional' => false, 'visible_default' => false, 'displayed' => false, ), diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 41070e81b..a97598697 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -397,12 +397,7 @@ class AdminOrdersControllerCore extends AdminController $cart_detail_data = array(); $cart_detail_data_obj = new HotelCartBookingData(); $objServiceProductCartDetail = new ServiceProductCartDetail(); - if ($cart_detail_data = $cart_detail_data_obj->getCartFormatedBookinInfoByIdCart( - (int) $id_cart, - [], - null, - 0 - )) { + if ($cart_detail_data = $cart_detail_data_obj->getCartFormatedBookinInfoByIdCart((int) $id_cart)) { $objRoomType = new HotelRoomType(); foreach ($cart_detail_data as $key => $cart_data) { $cart_detail_data[$key]['room_type_info'] = $objRoomType->getRoomTypeInfoByIdProduct($cart_data['id_product']); @@ -540,12 +535,12 @@ class AdminOrdersControllerCore extends AdminController public function initToolbarTitle() { parent::initToolbarTitle(); - switch ($this->display) { - case '': - case 'list': - array_pop($this->toolbar_title); - $this->toolbar_title[] = $this->l('Orders'); - break; + if ($this->display == 'add') { + array_pop($this->toolbar_title); + $this->toolbar_title[] = $this->l('Add new'); + } elseif ($this->display != 'view') { + array_pop($this->toolbar_title); + $this->toolbar_title[] = $this->l('Orders'); } } @@ -553,7 +548,12 @@ class AdminOrdersControllerCore extends AdminController { $response['hasError'] = 1; if (Validate::isLoadedObject($objOrder = new Order(Tools::getValue('id_order')))) { - $this->context->smarty->assign('can_edit', $this->tabAccess['edit']); + $this->context->smarty->assign( + array( + 'can_edit' => $this->tabAccess['edit'], + 'current_id_lang' => $this->context->language->id, + ) + ); // set modal details $modal = array( 'modal_id' => 'booking-documents-modal', @@ -626,6 +626,7 @@ class AdminOrdersControllerCore extends AdminController 'order' => $objOrder, 'currency' => new Currency($objOrder->id_currency), 'invoices_collection' => $objOrder->getInvoicesCollection(), + 'current_id_lang' => $this->context->language->id ) ); @@ -684,6 +685,7 @@ class AdminOrdersControllerCore extends AdminController 'payment_methods' => $payment_methods, 'payment_types' => $this->getPaymentsTypes(), 'invoices_collection' => $objOrder->getInvoicesCollection(), + 'current_id_lang' => $this->context->language->id, ) ); $modal = array( @@ -1177,6 +1179,7 @@ class AdminOrdersControllerCore extends AdminController 'order' => $objOrder, 'currency' => new Currency($objOrder->id_currency), 'invoices_collection' => $objOrder->getInvoicesCollection(), + 'current_id_lang' => $this->context->language->id, ) ); $modal = array( @@ -1238,6 +1241,7 @@ class AdminOrdersControllerCore extends AdminController $smartyVars['currencySign'] = $objCurrency->sign; $smartyVars['link'] = $this->context->link; $smartyVars['invoices_collection'] = $objOrder->getInvoicesCollection(); + $smartyVars['current_id_lang'] = $this->context->language->id; // set context currency So that we can get prices in the order currency $this->context->currency = $objCurrency; @@ -2865,7 +2869,7 @@ class AdminOrdersControllerCore extends AdminController $helper->color = 'color1'; $helper->title = $this->l('Total Rooms'); $helper->tooltip = $this->l('Total rooms is the number of rooms booked in this order.'); - $helper->href = '#start_rooms'; + $helper->href = '#start_products'; $helper->value = $numRooms; $this->kpis[] = $helper; @@ -6135,7 +6139,7 @@ class AdminOrdersControllerCore extends AdminController $product_quantity = $editProductInfo['product_quantity']; if ($updateQty = (int)($product_quantity - $objServiceProductOrderDetail->quantity)) { - $this->checkStockAvailable($objOrderDetail, ($product_quantity - $objOrderDetail->product_quantity)); + $this->checkStockAvailable($objOrderDetail, $updateQty); } $taxRate = $objServiceProductOrderDetail->unit_price_tax_incl / $objServiceProductOrderDetail->unit_price_tax_excl; @@ -6203,7 +6207,7 @@ class AdminOrdersControllerCore extends AdminController // Update product available quantity if ($updateQty) { - $result &= StockAvailable::updateQuantity($objOrderDetail->product_id, $objOrderDetail->product_attribute_id, $updateQty, $objOrder->id_shop); + $result &= StockAvailable::updateQuantity($objOrderDetail->product_id, $objOrderDetail->product_attribute_id, -(int)$updateQty, $objOrder->id_shop); } if (!$result) { @@ -7776,7 +7780,7 @@ class AdminOrdersControllerCore extends AdminController $response['errors'][] = Tools::displayError('Invalid service name'); } - if (empty($price)) { + if (!isset($price)) { $response['hasError'] = true; $response['errors'][] = Tools::displayError('Service price is required'); } elseif (!Validate::isPrice($price)) { diff --git a/controllers/admin/AdminPPreferencesController.php b/controllers/admin/AdminPPreferencesController.php index c5bd1dfbb..4794c1f9a 100644 --- a/controllers/admin/AdminPPreferencesController.php +++ b/controllers/admin/AdminPPreferencesController.php @@ -331,80 +331,80 @@ class AdminPPreferencesControllerCore extends AdminController ), 'submit' => array('title' => $this->l('Save')) ), - 'stock' => array( - 'title' => $this->l('Products stock'), - 'fields' => array( - 'PS_ORDER_OUT_OF_STOCK' => array( - 'title' => $this->l('Allow ordering of out-of-stock products'), - 'hint' => $this->l('By default, the Add to Cart button is hidden when a product is unavailable. You can choose to have it displayed in all cases.'), - 'validation' => 'isBool', - 'cast' => 'intval', - 'required' => false, - 'type' => 'bool' - ), - 'PS_STOCK_MANAGEMENT' => array( - 'title' => $this->l('Enable stock management'), - 'validation' => 'isBool', - 'cast' => 'intval', - 'required' => false, - 'type' => 'bool', - 'js' => array( - 'on' => 'onchange="stockManagementActivationAuthorization()"', - 'off' => 'onchange="stockManagementActivationAuthorization()"' - ) - ), - // 'PS_ADVANCED_STOCK_MANAGEMENT' => array( - // 'title' => $this->l('Enable advanced stock management'), - // 'hint' => $this->l('Allows you to manage physical stock, warehouses and supply orders in a new Stock menu.'), - // 'validation' => 'isBool', - // 'cast' => 'intval', - // 'required' => false, - // 'type' => 'bool', - // 'visibility' => Shop::CONTEXT_ALL, - // 'js' => array( - // 'on' => 'onchange="advancedStockManagementActivationAuthorization()"', - // 'off' => 'onchange="advancedStockManagementActivationAuthorization()"' - // ) - // ), - // 'PS_FORCE_ASM_NEW_PRODUCT' => array( - // 'title' => $this->l('New products use advanced stock management'), - // 'hint' => $this->l('New products will automatically use advanced stock management and depends on stock, but no warehouse will be selected'), - // 'validation' => 'isBool', - // 'cast' => 'intval', - // 'required' => false, - // 'type' => 'bool', - // 'visibility' => Shop::CONTEXT_ALL, - // ), - // 'PS_DEFAULT_WAREHOUSE_NEW_PRODUCT' => array( - // 'title' => $this->l('Default warehouse on new products'), - // 'hint' => $this->l('Automatically set a default warehouse when new product is created'), - // 'type' => 'select', - // 'list' => $warehouse_list, - // 'identifier' => 'id_warehouse' - // ), - // 'PS_PACK_STOCK_TYPE' => array( - // 'title' => $this->l('Default pack stock management'), - // 'type' => 'select', - // 'list' =>array( - // array( - // 'pack_stock' => 0, - // 'name' => $this->l('Decrement pack only.') - // ), - // array( - // 'pack_stock' => 1, - // 'name' => $this->l('Decrement products in pack only.') - // ), - // array( - // 'pack_stock' => 2, - // 'name' => $this->l('Decrement both.') - // ), - // ), - // 'identifier' => 'pack_stock', - // ), - ), - // 'bottom' => '', - 'submit' => array('title' => $this->l('Save')) - ), + // 'stock' => array( + // 'title' => $this->l('Products stock'), + // 'fields' => array( + // 'PS_ORDER_OUT_OF_STOCK' => array( + // 'title' => $this->l('Allow ordering of out-of-stock products'), + // 'hint' => $this->l('By default, the Add to Cart button is hidden when a product is unavailable. You can choose to have it displayed in all cases.'), + // 'validation' => 'isBool', + // 'cast' => 'intval', + // 'required' => false, + // 'type' => 'bool' + // ), + // 'PS_STOCK_MANAGEMENT' => array( + // 'title' => $this->l('Enable stock management'), + // 'validation' => 'isBool', + // 'cast' => 'intval', + // 'required' => false, + // 'type' => 'bool', + // 'js' => array( + // 'on' => 'onchange="stockManagementActivationAuthorization()"', + // 'off' => 'onchange="stockManagementActivationAuthorization()"' + // ) + // ), + // // 'PS_ADVANCED_STOCK_MANAGEMENT' => array( + // // 'title' => $this->l('Enable advanced stock management'), + // // 'hint' => $this->l('Allows you to manage physical stock, warehouses and supply orders in a new Stock menu.'), + // // 'validation' => 'isBool', + // // 'cast' => 'intval', + // // 'required' => false, + // // 'type' => 'bool', + // // 'visibility' => Shop::CONTEXT_ALL, + // // 'js' => array( + // // 'on' => 'onchange="advancedStockManagementActivationAuthorization()"', + // // 'off' => 'onchange="advancedStockManagementActivationAuthorization()"' + // // ) + // // ), + // // 'PS_FORCE_ASM_NEW_PRODUCT' => array( + // // 'title' => $this->l('New products use advanced stock management'), + // // 'hint' => $this->l('New products will automatically use advanced stock management and depends on stock, but no warehouse will be selected'), + // // 'validation' => 'isBool', + // // 'cast' => 'intval', + // // 'required' => false, + // // 'type' => 'bool', + // // 'visibility' => Shop::CONTEXT_ALL, + // // ), + // // 'PS_DEFAULT_WAREHOUSE_NEW_PRODUCT' => array( + // // 'title' => $this->l('Default warehouse on new products'), + // // 'hint' => $this->l('Automatically set a default warehouse when new product is created'), + // // 'type' => 'select', + // // 'list' => $warehouse_list, + // // 'identifier' => 'id_warehouse' + // // ), + // // 'PS_PACK_STOCK_TYPE' => array( + // // 'title' => $this->l('Default pack stock management'), + // // 'type' => 'select', + // // 'list' =>array( + // // array( + // // 'pack_stock' => 0, + // // 'name' => $this->l('Decrement pack only.') + // // ), + // // array( + // // 'pack_stock' => 1, + // // 'name' => $this->l('Decrement products in pack only.') + // // ), + // // array( + // // 'pack_stock' => 2, + // // 'name' => $this->l('Decrement both.') + // // ), + // // ), + // // 'identifier' => 'pack_stock', + // // ), + // ), + // // 'bottom' => '', + // 'submit' => array('title' => $this->l('Save')) + // ), ); } diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index b1e02b73b..bf4321607 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -944,6 +944,12 @@ class AdminProductsControllerCore extends AdminController $id_hotel_new = $room_type_info['id_hotel']; } + $objHotelRoomTypeBedType = new HotelRoomTypeBedType(); + if ($roomTypeBedTypes = $objHotelRoomTypeBedType->getRoomTypeBedTypes($id_product_old)) { + $roomTypeBedTypes = array_column($roomTypeBedTypes, 'id_bed_type'); + $objHotelRoomTypeBedType->updateRoomTypeBedTypes($roomTypeBedTypes, $product->id); + } + if ($product->hasAttributes()) { Product::updateDefaultAttribute($product->id); } else { @@ -1918,7 +1924,8 @@ class AdminProductsControllerCore extends AdminController $this->copyFromPost($this->object, $this->table); $this->object->booking_product = true; if ($this->object->add()) { - + $objHotelRoomTypeBedType = new HotelRoomTypeBedType(); + $objHotelRoomTypeBedType->updateRoomTypeBedTypes(Tools::getValue('id_bed_types'), $this->object->id); // associateroom type to hotel // if ($this->object->is_virtual) { diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index b11c0e54a..2859869ae 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -474,7 +474,7 @@ class CartControllerCore extends FrontController $finalQuantity += $quantityInCart; } if ($product->max_quantity && $finalQuantity > $product->max_quantity) { - $this->errors[] = Tools::displayError(sprintf('You can now add more than %d quantity for this product in the cart.', $product->max_quantity)); + $this->errors[] = Tools::displayError(sprintf('You cannot add more than %d quantity for this product in the cart.', $product->max_quantity)); } } else { if ($id_cart) { @@ -517,7 +517,7 @@ class CartControllerCore extends FrontController $finalQuantity += $productCartDetail['quantity']; } if ($product->max_quantity && $finalQuantity > $product->max_quantity) { - $this->errors[] = Tools::displayError(sprintf('You can not add more than %d quantity for this product in the cart.', $product->max_quantity)); + $this->errors[] = Tools::displayError(sprintf('You cannot add more than %d quantity for this product in the cart.', $product->max_quantity)); } } elseif ($productCartDetail) { $this->errors[] = Tools::displayError('You can only order one quantity for this product.'); diff --git a/controllers/front/CategoryController.php b/controllers/front/CategoryController.php index 5513488fa..582344f7d 100644 --- a/controllers/front/CategoryController.php +++ b/controllers/front/CategoryController.php @@ -169,8 +169,23 @@ class CategoryControllerCore extends FrontController } } - $id_cart = $this->context->cart->id; - $id_guest = $this->context->cookie->id_guest; + $sort_by = Tools::getValue('sort_by'); + $sort_value = Tools::getValue('sort_value'); + $filter_data = Tools::getValue('filter_data'); + $amenities = []; + $price = []; + if (!empty($filter_data)) { + foreach ($filter_data as $key => $value) { + if ($key == 'amenities') { + foreach ($value as $a_k => $a_v) { + $amenities[] = $a_v; + } + } elseif ($key == 'price') { + $price['from'] = $value[0]; + $price['to'] = $value[1]; + } + } + } $objBookingDetail = new HotelBookingDetail(); $bookingParams = array( @@ -179,20 +194,36 @@ class CategoryControllerCore extends FrontController 'occupancy' => $occupancy, 'hotel_id' => $id_hotel, 'get_total_rooms' => 0, - 'id_cart' => $id_cart, - 'id_guest' => $id_guest, + 'id_cart' => $this->context->cart->id, + 'id_guest' => $this->context->cookie->id_guest, + 'amenities' => $amenities, + 'price' => $price, ); if ($displayAllRoomsTypes) { $bookingParams['get_all_room_types'] = 1; } - $booking_data = $objBookingDetail->dataForFrontSearch($bookingParams); + if ($booking_data = $objBookingDetail->dataForFrontSearch($bookingParams)) { + $booking_data['rm_data'] = array_values($booking_data['rm_data']); + if ($sort_by && $sort_value) { + $indi_arr = array(); + + if ($sort_value == 1) { + $direction = SORT_ASC; + } elseif ($sort_value == 2) { + $direction = SORT_DESC; + } + foreach ($booking_data['rm_data'] as $s_k => $s_v) { + $indi_arr[$s_k] = $s_v['price']; + } + + array_multisort($indi_arr, $direction, $booking_data['rm_data']); + } + } $num_days = HotelHelper::getNumberOfDays($date_from, $date_to); - $warning_num = Configuration::get('WK_ROOM_LEFT_WARNING_NUMBER'); - /*Max date of ordering for order restrict*/ $order_date_restrict = false; $max_order_date = HotelOrderRestrictDate::getMaxOrderDate($id_hotel); @@ -204,8 +235,9 @@ class CategoryControllerCore extends FrontController $order_date_restrict = true; } } - /*End*/ + $feat_img_dir = _PS_IMG_.'rf/'; + $ratting_img = _MODULE_DIR_.'hotelreservationsystem/views/img/Slices/icons-sprite.png'; $this->context->smarty->assign(array( 'warning_num' => $warning_num, 'num_days' => $num_days, @@ -214,23 +246,25 @@ class CategoryControllerCore extends FrontController 'booking_data' => $booking_data, 'max_order_date' => $max_order_date, 'order_date_restrict' => $order_date_restrict, - 'display_all_room_types' => $displayAllRoomsTypes + 'display_all_room_types' => $displayAllRoomsTypes, + 'id_hotel' => $id_hotel, + 'currency' => $currency, + 'feat_img_dir' => $feat_img_dir, + 'ratting_img' => $ratting_img, )); + + $action = Tools::toCamelCase(Tools::getValue('action'), true); + if ($this->ajax && $action == 'Filterresults') { + $response = array( + 'status' => true, + 'html_room_type_list' => $this->context->smarty->fetch('_partials/room_type_list.tpl') + ); + $this->ajaxDie(json_encode($response)); + } } else { Tools::redirect($this->context->link->getPageLink('pagenotfound')); } - - $feat_img_dir = _PS_IMG_.'rf/'; - $ratting_img = _MODULE_DIR_.'hotelreservationsystem/views/img/Slices/icons-sprite.png'; - - $this->context->smarty->assign(array( - 'id_hotel' => $id_hotel, - 'currency' => $currency, - 'feat_img_dir' => $feat_img_dir, - 'ratting_img' => $ratting_img, - )); - - + /*End*/ /*if (isset($this->context->cookie->id_compare)) $this->context->smarty->assign('compareProducts', CompareProduct::getCompareProducts((int)$this->context->cookie->id_compare)); @@ -262,109 +296,6 @@ class CategoryControllerCore extends FrontController ));*/ } - public function displayAjaxFilterResults() - { - $response = array('status' => false); - - $this->display_header = false; - $this->display_footer = false; - - $displayAllRoomsTypes = false; - if (!($date_from = Tools::getValue('date_from'))) { - $date_from = date('Y-m-d H:i:s'); - $date_to = date('Y-m-d H:i:s', strtotime($date_from) + 86400); - $displayAllRoomsTypes = true; - } - - if (!($date_to = Tools::getValue('date_to'))) { - $date_to = date('Y-m-d H:i:s', strtotime($date_from) + 86400); - $displayAllRoomsTypes = true; - } - - $htl_id_category = Tools::getValue('id_category'); - - // occupancy of the search - $occupancy = Tools::getValue('occupancy'); - if (!Validate::isOccupancy($occupancy)) { - $occupancy = array(); - } - $sort_by = Tools::getValue('sort_by'); - $sort_value = Tools::getValue('sort_value'); - $filter_data = Tools::getValue('filter_data'); - - $adults = 0; - $children = 0; - $amenities = 0; - $price = 0; - - if (!empty($filter_data)) { - foreach ($filter_data as $key => $value) { - if ($key == 'adults') { - $adults = min($value); - } elseif ($key == 'children') { - $children = min($value); - } elseif ($key == 'amenities') { - $amenities = array(); - foreach ($value as $a_k => $a_v) { - $amenities[] = $a_v; - } - } elseif ($key == 'price') { - $price = array(); - $price['from'] = $value[0]; - $price['to'] = $value[1]; - } - } - } - - if (Module::isInstalled('hotelreservationsystem')) { - require_once _PS_MODULE_DIR_.'hotelreservationsystem/define.php'; - - $id_hotel = HotelBranchInformation::getHotelIdByIdCategory($htl_id_category); - - $objBookingDetail = new HotelBookingDetail(); - - $bookingParams = array( - 'date_from' => $date_from, - 'date_to' => $date_to, - 'hotel_id' => $id_hotel, - 'occupancy' => $occupancy, - 'amenities' => $amenities, - 'price' => $price, - 'get_total_rooms' => 0, - 'id_cart' => $this->context->cart->id, - 'id_guest' => $this->context->cookie->id_guest, - ); - - if ($displayAllRoomsTypes) { - $bookingParams['get_all_room_types'] = 1; - } - - $booking_data = $objBookingDetail->dataForFrontSearch($bookingParams); - // reset array keys from 0 - $booking_data['rm_data'] = array_values($booking_data['rm_data']); - if ($sort_by && $sort_value) { - $indi_arr = array(); - - if ($sort_value == 1) { - $direction = SORT_ASC; - } elseif ($sort_value == 2) { - $direction = SORT_DESC; - } - foreach ($booking_data['rm_data'] as $s_k => $s_v) { - $indi_arr[$s_k] = $s_v['price']; - } - - array_multisort($indi_arr, $direction, $booking_data['rm_data']); - } - - $this->context->smarty->assign(array('booking_data' => $booking_data)); - $html = $this->context->smarty->fetch('_partials/room_type_list.tpl'); - $response['status'] = true; - $response['html_room_type_list'] = $html; - } - $this->ajaxDie(json_encode($response)); - } - /** * Assigns scenes template variables */ diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php index 06e8b0759..1014a8b5f 100644 --- a/controllers/front/ContactController.php +++ b/controllers/front/ContactController.php @@ -237,15 +237,16 @@ class ContactControllerCore extends FrontController $this->addJS(_PS_JS_DIR_.'validate.js'); // GOOGLE MAP - if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { + if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { Media::addJsDef( array( 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), + 'PS_MAP_ID' => $PS_MAP_ID, ) ); $this->addJS( 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY. - '&libraries=places&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code + '&libraries=places,marker&loading=async&callback=initMap&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); } } diff --git a/controllers/front/GuestTrackingController.php b/controllers/front/GuestTrackingController.php index 9a9df2490..596d54185 100644 --- a/controllers/front/GuestTrackingController.php +++ b/controllers/front/GuestTrackingController.php @@ -639,6 +639,7 @@ class GuestTrackingControllerCore extends FrontController if (Validate::isLoadedObject($objHotelBranchInformation)) { if (($apiKey = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP') + && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) ) { if (floatval($objHotelBranchInformation->latitude) != 0 && floatval($objHotelBranchInformation->longitude) != 0 @@ -646,10 +647,11 @@ class GuestTrackingControllerCore extends FrontController Media::addJsDef(array( 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), 'initiateMap' => 1, + 'PS_MAP_ID' => $PS_MAP_ID, )); $this->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places&language='. + 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places,marker&loading=async&callback=initMap&language='. $this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 6be63643b..40f3edaf6 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -871,6 +871,7 @@ class OrderDetailControllerCore extends FrontController if (Validate::isLoadedObject($objHotelBranchInformation)) { if (($apiKey = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP') + && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) ) { if (floatval($objHotelBranchInformation->latitude) != 0 && floatval($objHotelBranchInformation->longitude) != 0 @@ -878,10 +879,10 @@ class OrderDetailControllerCore extends FrontController Media::addJsDef(array( 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), 'initiateMap' => 1, + 'PS_MAP_ID' => $PS_MAP_ID, )); - $this->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places&language='. + 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places,marker&loading=async&callback=initMap&language='. $this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); } diff --git a/controllers/front/OurPropertiesController.php b/controllers/front/OurPropertiesController.php index cb651ba1b..52fd94a86 100644 --- a/controllers/front/OurPropertiesController.php +++ b/controllers/front/OurPropertiesController.php @@ -111,7 +111,7 @@ class OurPropertiesControllerCore extends FrontController $hotelsInfo = array_slice($hotelsInfo, $page * 10, 10); } - if ($displayHotelMap && Configuration::get('PS_API_KEY') && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { + if ($displayHotelMap && Configuration::get('PS_API_KEY') && Configuration::get('WK_GOOGLE_ACTIVE_MAP') && Configuration::get('PS_MAP_ID')) { if ($hotelLocations = $objHotelInfo->getMapFormatHotelsInfo(Configuration::get('WK_MAP_HOTEL_ACTIVE_ONLY'))) { $hotelLocationArray = str_replace(array('\n', '\r'), '', json_encode($hotelLocations)); } @@ -144,16 +144,17 @@ class OurPropertiesControllerCore extends FrontController $this->addJS(_THEME_JS_DIR_.'our-properties.js'); $this->addCSS(_THEME_CSS_DIR_.'our-properties.css'); // GOOGLE MAP - if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { + if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { Media::addJsDef( array( 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), + 'PS_MAP_ID' => $PS_MAP_ID ) ); $this->addJS( 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY. - '&libraries=places&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code + '&libraries=places,marker&loading=async&callback=initMap&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); } } diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 24cc682af..8eccd295c 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -66,10 +66,11 @@ class ProductControllerCore extends FrontController $this->addJqueryPlugin('jqzoom'); } - if (($PS_API_KEY = Configuration::get('PS_API_KEY'))) { + if (($PS_API_KEY = Configuration::get('PS_API_KEY')) + && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) + ) { $objHotelRoomType = new HotelRoomType(); - $roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->product->id); - if ($roomTypeInfo) { + if ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->product->id)) { $objHotelBranchInformation = new HotelBranchInformation($roomTypeInfo['id_hotel']); if (floatval($objHotelBranchInformation->latitude) != 0 && floatval($objHotelBranchInformation->longitude) != 0 @@ -79,12 +80,13 @@ class ProductControllerCore extends FrontController 'latitude' => $objHotelBranchInformation->latitude, 'longitude' => $objHotelBranchInformation->longitude, ), - 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')) + 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), + 'PS_MAP_ID' => $PS_MAP_ID )); $this->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY.'&libraries=places&language='. - $this->context->language->iso_code.'®ion='.$this->context->country->iso_code + 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY. + '&libraries=places,marker&loading=async&callback=initMap&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); } } @@ -129,6 +131,20 @@ class ProductControllerCore extends FrontController } } + // if product is a service product then check type of selling preference + if (!$this->product->booking_product) { + if ($this->product->selling_preference_type == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE) { + Tools::redirect($this->context->link->getPageLink('pagenotfound')); + } elseif ($this->product->selling_preference_type == Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE) { + // if selling preference is hotel standalone and with room type then check if product is associated to any hotel + $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); + $associatedHotels = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType($this->product->id); + if (!isset($associatedHotels['hotel']) || !$associatedHotels['hotel']) { + Tools::redirect($this->context->link->getPageLink('pagenotfound')); + } + } + } + if (!Validate::isLoadedObject($this->product)) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); @@ -496,6 +512,19 @@ class ProductControllerCore extends FrontController $this->context->smarty->assign('error', Tools::getValue('error')); } } else { + if ($this->product->allow_multiple_quantity) { + $this->product->cart_quantity = 0; + if ($products = $this->context->cart->getProducts()) { + $products = array_column($products, 'cart_quantity', 'id_product'); + if (isset($products[$this->product->id])) { + $this->product->cart_quantity = $products[$this->product->id]; + $this->product->max_quantity -= $products[$this->product->id]; + if (!$this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock)) { + $this->product->quantity -= $products[$this->product->id]; + } + } + } + } $this->assignServiceProductVars(); } diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index 0afb0273e..079d3e928 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -2175,8 +2175,8 @@ CREATE TABLE IF NOT EXISTS `PREFIX_shop_url` ( `id_shop` int(11) unsigned NOT NULL, `domain` varchar(150) NOT NULL, `domain_ssl` varchar(150) NOT NULL, - `physical_uri` varchar(64) NOT NULL, - `virtual_uri` varchar(64) NOT NULL, + `physical_uri` varchar(256) NOT NULL, + `virtual_uri` varchar(256) NOT NULL, `main` TINYINT(1) NOT NULL, `active` TINYINT(1) NOT NULL, PRIMARY KEY (`id_shop_url`), diff --git a/modules/bankwire/bankwire.php b/modules/bankwire/bankwire.php index b395b10a0..f90c68feb 100644 --- a/modules/bankwire/bankwire.php +++ b/modules/bankwire/bankwire.php @@ -83,7 +83,8 @@ class Bankwire extends PaymentModule 'bankwire_owner' => Configuration::get('BANK_WIRE_OWNER'), 'bankwire_details' => nl2br(Configuration::get('BANK_WIRE_DETAILS')), 'bankwire_address' => nl2br(Configuration::get('BANK_WIRE_ADDRESS')), - 'lang' => new Language($order->id_lang) + 'lang' => new Language($order->id_lang), + 'total_paid' => Tools::displayPrice($order->total_paid, $this->context->currency, false) )); return array( diff --git a/modules/bankwire/views/templates/mail/mail_template_html.tpl b/modules/bankwire/views/templates/mail/mail_template_html.tpl index ac5f35d46..71d7217ea 100644 --- a/modules/bankwire/views/templates/mail/mail_template_html.tpl +++ b/modules/bankwire/views/templates/mail/mail_template_html.tpl @@ -27,7 +27,7 @@ {l s='Here are the bank details for your transfer:' mod='bankwire' lang=$lang}

- {l s='Amount:' mod='bankwire' lang=$lang} {literal}{total_paid}{/literal}
+ {l s='Amount:' mod='bankwire' lang=$lang} {$total_paid}
{l s='Account owner:' mod='bankwire' lang=$lang} {$bankwire_owner}
{l s='Account details:' mod='bankwire' lang=$lang} {$bankwire_details}
{l s='Bank address:' mod='bankwire' lang=$lang} {$bankwire_address} diff --git a/modules/bankwire/views/templates/mail/mail_template_text.tpl b/modules/bankwire/views/templates/mail/mail_template_text.tpl index c15a111f6..f187d745d 100644 --- a/modules/bankwire/views/templates/mail/mail_template_text.tpl +++ b/modules/bankwire/views/templates/mail/mail_template_text.tpl @@ -18,7 +18,7 @@ *} {l s='Here are the bank details for your transfer:' mod='bankwire'} -{l s='Amount:' mod='bankwire'} {literal}{total_paid}{/literal} +{l s='Amount:' mod='bankwire'} {$total_paid} {l s='Account owner:' mod='bankwire'} {$bankwire_owner} {l s='Account details:' mod='bankwire'} {$bankwire_details} {l s='Bank address:' mod='bankwire'} {$bankwire_address} diff --git a/modules/blockcart/ajax-cart.js b/modules/blockcart/ajax-cart.js index 47836bee8..e3e4ac26f 100644 --- a/modules/blockcart/ajax-cart.js +++ b/modules/blockcart/ajax-cart.js @@ -432,6 +432,10 @@ var ajaxCart = { resetRoomtypeServices(); + if (parseInt($('#product_page_booking_product').val()) == 0) { + $('#service_product_qty').val(1); + } + BookingForm.refresh(true); } @@ -874,7 +878,7 @@ var ajaxCart = { content += ''; 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' && typeof(hotel_wise_data.hotel_name) != 'undefined') ) { content += '
' + hotel_wise_data.hotel_name + '
'; } diff --git a/modules/cheque/cheque.php b/modules/cheque/cheque.php index fc888108d..4cdcadcd7 100644 --- a/modules/cheque/cheque.php +++ b/modules/cheque/cheque.php @@ -78,7 +78,8 @@ class Cheque extends PaymentModule 'cheque_name' => Configuration::get('CHEQUE_NAME'), 'cheque_address' => Configuration::get('CHEQUE_ADDRESS'), 'cheque_address_html' => str_replace("\n", '
', Configuration::get('CHEQUE_ADDRESS')), - 'lang' => new Language($order->id_lang) + 'lang' => new Language($order->id_lang), + 'total_paid' => Tools::displayPrice($order->total_paid, $this->context->currency, false) )); return array( diff --git a/modules/cheque/views/templates/mail/mail_template_html.tpl b/modules/cheque/views/templates/mail/mail_template_html.tpl index d6ade1dac..59e845fc6 100644 --- a/modules/cheque/views/templates/mail/mail_template_html.tpl +++ b/modules/cheque/views/templates/mail/mail_template_html.tpl @@ -27,7 +27,7 @@ {l s='Here are the bank details for your check:' mod='cheque' lang=$lang}

- {l s='Amount:' mod='cheque' lang=$lang} {literal}{total_paid}{/literal}
+ {l s='Amount:' mod='cheque' lang=$lang} {$total_paid}
{l s='Payable to the order of:' mod='cheque' lang=$lang} {$cheque_name}
{l s='Please mail your check to:' mod='cheque' lang=$lang} {$cheque_address_html}
diff --git a/modules/cheque/views/templates/mail/mail_template_text.tpl b/modules/cheque/views/templates/mail/mail_template_text.tpl index adc2c0ac6..ecf5044ec 100644 --- a/modules/cheque/views/templates/mail/mail_template_text.tpl +++ b/modules/cheque/views/templates/mail/mail_template_text.tpl @@ -18,6 +18,6 @@ *} {l s='Here are the bank details for your check:' mod='cheque' lang=$lang} -{l s='Amount:' mod='cheque' lang=$lang} {literal}{total_paid}{/literal} +{l s='Amount:' mod='cheque' lang=$lang} {$total_paid} {l s='Payable to the order of:' mod='cheque' lang=$lang} {$cheque_name} {l s='Please mail your check to:' mod='cheque' lang=$lang} {$cheque_address} diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index 81d23c6c4..f25b204fb 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -2175,7 +2175,11 @@ class HotelBookingDetail extends ObjectModel // delete cart feature prices after room addition success HotelRoomTypeFeaturePricing::deleteFeaturePrices($context->cart->id); - + // since only one room is added in the cart on reallocation process. + $idNewCartBookingData = false; + if (isset($objCartBookingData->id)) { + $idNewCartBookingData = $objCartBookingData->id; + } // =============================================================== // END: Add Process of the old booking // =============================================================== @@ -2286,6 +2290,21 @@ class HotelBookingDetail extends ObjectModel AND id_room = '.(int) $objOldHotelBooking->id_room.' AND `id_order` = '.(int) $objOldHotelBooking->id_order ); $objCartBookingData = new HotelCartBookingData($idHotelCartBookingData); + if ($idNewCartBookingData) { + $objServiceProductCartDetail = new ServiceProductCartDetail(); + if ($oldCartAdditonalServices = $objServiceProductCartDetail->getServiceProductsInCart( + 0, // if reallocated twice the id cart will not be used as it was not changed in first reallocation. + [], + null, + $objCartBookingData->id + )) { + foreach ($oldCartAdditonalServices as $service) { + $objServiceProductCartDetail = new ServiceProductCartDetail($service['id_service_product_cart_detail']); + $objServiceProductCartDetail->htl_cart_booking_id = (int) $idNewCartBookingData; + $objServiceProductCartDetail->save(); + } + } + } $objCartBookingData->delete(); // delete the booking detail diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index bcb120674..59cc39146 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -951,7 +951,8 @@ class HotelCartBookingData extends ObjectModel if (!Validate::isLoadedObject($product = new Product($service['id_product']))) { $toRemoveService = 1; } else { - if (!$product->active) { + // check if product is active and (available for order for front office) + if (!$product->active || (!$forAdminCart && !$product->available_for_order)) { $toRemoveService = 1; } else if ($checkServiceRoomLink) { if ($product->selling_preference_type == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE) { @@ -1579,7 +1580,13 @@ class HotelCartBookingData extends ObjectModel if ($detailed) { // extra demands $cartHotelData[$prodKey]['extra_demands'] = $objRoomDemands->getRoomTypeDemands($product['id_product']); - $cartHotelData[$prodKey]['service_products'] = $objRoomTypeServiceProduct->getServiceProductsData($product['id_product'], 1, 0, true); + $cartHotelData[$prodKey]['service_products'] = $objRoomTypeServiceProduct->getServiceProductsData( + $product['id_product'], + 1, + 0, + true, + isset($context->employee->id) ? 2 : 1 + ); // add hotel info of the room if ($hotelInfo = $objHotelBranch->hotelBranchesInfo( false, diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index d103e1576..a91163edb 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -430,6 +430,8 @@ class HotelReservationSystemDb `id_hotel` int(11) NOT NULL, `id_htl_booking_detail` int(11) NOT NULL, `id_product_option` int(11) NOT NULL, + `tax_computation_method` tinyint(1) unsigned NOT NULL DEFAULT '0', + `id_tax_rules_group` int(11) unsigned NOT NULL DEFAULT '0', `unit_price_tax_excl` decimal(20,6) NOT NULL, `unit_price_tax_incl` decimal(20,6) NOT NULL, `total_price_tax_excl` decimal(20,6) NOT NULL, diff --git a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php index ca621a1fd..0e668ccbd 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php +++ b/modules/hotelreservationsystem/classes/HotelRoomTypeFeaturePricing.php @@ -389,9 +389,10 @@ class HotelRoomTypeFeaturePricing extends ObjectModel 1, Product::PRICE_ADDITION_TYPE_WITH_ROOM )) { - $selectedServices = array_shift($roomServicesServices); - $totalPrice['total_price_tax_incl'] += $selectedServices['total_price_tax_incl']; - $totalPrice['total_price_tax_excl'] += $selectedServices['total_price_tax_excl']; + foreach($roomServicesServices as $selectedService) { + $totalPrice['total_price_tax_incl'] += $selectedService['total_price_tax_incl']; + $totalPrice['total_price_tax_excl'] += $selectedService['total_price_tax_excl']; + } } } diff --git a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php index 2b7eb6aa0..7c033fe24 100644 --- a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php @@ -140,7 +140,7 @@ class ServiceProductCartDetail extends ObjectModel */ // public function getProducts( public function getServiceProductsInCart( - $idCart, + $idCart = 0, $sellingPreferenceTypes = [], $idHotel = null, $idHotelCartBooking = null, @@ -179,7 +179,10 @@ class ServiceProductCartDetail extends ObjectModel $sql .= ' LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbil ON (hbil.`id` = spc.`id_hotel` AND hbil.`id_lang` = '. $language->id.')'; } - $sql .= ' WHERE spc.`id_product`!=0 AND spc.`id_cart`='.(int) $idCart; + $sql .= ' WHERE spc.`id_product`!=0 '; + if ($idCart) { + $sql .= ' AND spc.`id_cart`='.(int) $idCart; + } if (!is_null($idProductRoomType)) { $sql .= ' AND hcbd.`id_product`='.(int) $idProductRoomType; diff --git a/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php b/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php index 173e2fe3f..33202537b 100644 --- a/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php +++ b/modules/hotelreservationsystem/classes/ServiceProductOrderDetail.php @@ -28,6 +28,8 @@ class ServiceProductOrderDetail extends ObjectModel public $id_hotel; public $id_htl_booking_detail; public $id_product_option; + public $tax_computation_method; + public $id_tax_rules_group; public $unit_price_tax_excl; public $unit_price_tax_incl; public $total_price_tax_excl; @@ -53,6 +55,8 @@ class ServiceProductOrderDetail extends ObjectModel 'id_hotel' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_htl_booking_detail' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_product_option' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'tax_computation_method' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_tax_rules_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'unit_price_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true), 'unit_price_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true), 'total_price_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true), @@ -69,6 +73,52 @@ class ServiceProductOrderDetail extends ObjectModel ) ); + public function add($autodate = true, $null_values = true) + { + if (Validate::isLoadedObject($objOrder = new Order((int)$this->id_order)) + && Validate::isLoadedObject($objServiceProduct = new Product((int)$this->id_product)) + && Validate::isLoadedObject($objOrderDetail = new OrderDetail((int)$this->id_order_detail)) + ) { + if ($objOrderDetail->selling_preference_type == Product::SELLING_PREFERENCE_WITH_ROOM_TYPE) { + if ($this->id_htl_booking_detail + && Validate::isLoadedObject($objHotelBookingDetail = new HotelBookingDetail((int)$this->id_htl_booking_detail)) + ) { + $idRoomType = $objHotelBookingDetail->id_product; + $objAddress = new Address((int)$objOrder->id_address_tax); + if ($objServiceProduct->auto_add_to_cart && $objServiceProduct->price_addition_type == Product::PRICE_ADDITION_TYPE_WITH_ROOM) { + if (Validate::isLoadedObject($objRoomTypeProduct = new Product((int)$idRoomType))) { + $this->id_tax_rules_group = $objRoomTypeProduct->id_tax_rules_group; + } + } else { + $objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice(); + if ($serviceProductPriceRoomInfo = $objRoomTypeServiceProductPrice->getProductRoomTypeLinkPriceInfo( + $this->id_product, + $idRoomType, + RoomTypeServiceProduct::WK_ELEMENT_TYPE_ROOM_TYPE + )) { + //Special tax rule group for the Service product accroding to Room type + $this->id_tax_rules_group = $serviceProductPriceRoomInfo['id_tax_rules_group']; + } else { + // Use default tax rule group for the service product + $this->id_tax_rules_group = $objOrderDetail->id_tax_rules_group; + } + } + + $taxCalculator = TaxManagerFactory::getManager($objAddress, $this->id_tax_rules_group)->getTaxCalculator(); + $this->tax_computation_method = (int)$taxCalculator->computation_method; + } + } else { + // Use default tax rule group for the service product + $this->id_tax_rules_group = $objOrderDetail->id_tax_rules_group; + $this->tax_computation_method = $objOrderDetail->tax_computation_method; + } + + return parent::add($autodate, $null_values); + } + + return false; + } + public function getServiceProductsInOrder( $idOrder, $idOrderDetail = 0, diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 08813efcb..75feb0dd4 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -214,7 +214,7 @@ class AdminAddHotelController extends ModuleAdminController } $smartyVars['state_var'] = $stateOptions; - $smartyVars['enabledDisplayMap'] = Configuration::get('PS_API_KEY') && Configuration::get('WK_GOOGLE_ACTIVE_MAP'); + $smartyVars['enabledDisplayMap'] = Configuration::get('PS_API_KEY') && Configuration::get('PS_MAP_ID') && Configuration::get('WK_GOOGLE_ACTIVE_MAP'); $smartyVars['ps_img_dir'] = _PS_IMG_.'l/'; $smartyVars['PS_MAX_CHECKOUT_OFFSET'] = (int) Configuration::get('PS_MAX_CHECKOUT_OFFSET'); $smartyVars['PS_MIN_BOOKING_OFFSET'] = (int) Configuration::get('PS_MIN_BOOKING_OFFSET'); @@ -605,8 +605,8 @@ class AdminAddHotelController extends ModuleAdminController $objHotelBranch->check_in = $check_in; $objHotelBranch->check_out = $check_out; $objHotelBranch->rating = $rating; - $objHotelBranch->latitude = $latitude; - $objHotelBranch->longitude = $longitude; + $objHotelBranch->latitude = Tools::ps_round($latitude, 8); + $objHotelBranch->longitude = Tools::ps_round($longitude, 8); $objHotelBranch->map_formated_address = $map_formated_address; $objHotelBranch->map_input_text = $map_input_text; $objHotelBranch->save(); @@ -984,15 +984,16 @@ class AdminAddHotelController extends ModuleAdminController 'primaryHotelId' => Configuration::get('WK_PRIMARY_HOTEL'), 'disableHotelMsg' => $this->l('Primary hotel for website will be updated to first available active hotel.', null, true), 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), + 'PS_MAP_ID' => ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) ) ); // GOOGLE MAP $language = $this->context->language; $country = $this->context->country; - if ($PS_API_KEY = Configuration::get('PS_API_KEY')) { + if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && $PS_MAP_ID) { $this->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY.'&libraries=places&language='. - $language->iso_code.'®ion='.$country->iso_code + 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY.'&libraries=places,marker&loading=async&language='. + $language->iso_code.'®ion='.$country->iso_code.'&callback=initGoogleMaps' ); } //tinymce diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php index 6bfbd4ee7..6ce0733cd 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelFeaturePricesSettings.php @@ -70,6 +70,24 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController ); $priorities = Configuration::get('HTL_FEATURE_PRICING_PRIORITY'); + $hotelsArray = array(); + $roomTypesArray = array(); + $objHotelRoomType = new HotelRoomType(); + if ($accsHlts = HotelBranchInformation::getProfileAccessedHotels($this->context->employee->id_profile, 1)) { + foreach ($accsHlts as $hotel) { + $addressInfo = HotelBranchInformation::getAddress($hotel['id_hotel']); + $hotelsArray[$hotel['id_hotel']] = $hotel['hotel_name'].', '.$addressInfo['city']; + } + + foreach ($accsHlts as $hotel) { + if ($hotelRoomTypes = $objHotelRoomType->getRoomTypeByHotelId($hotel['id_hotel'], $this->context->language->id)) { + foreach ($hotelRoomTypes as $room_type) { + $roomTypesArray[$room_type['id_product']] = $room_type['room_type'].', '.$hotel['hotel_name']; + } + } + } + } + $this->context->smarty->assign('featurePricePriority', explode(';', $priorities)); $this->fields_options = array('feature_price_priority' => array()); $this->fields_list = array( @@ -85,12 +103,19 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController 'product_name' => array( 'title' => $this->l('Room Type'), 'align' => 'center', - 'havingFilter' => true, + 'type' => 'select', 'callback' => 'getRoomTypeLink', + 'filter_key' => 'a!id_product', + 'list' => $roomTypesArray, + 'class' => 'chosen', ), 'hotel_name' => array( 'title' => $this->l('Hotel'), 'align' => 'center', + 'type' => 'select', + 'filter_key' => 'hrt!id_hotel', + 'list' => $hotelsArray, + 'class' => 'chosen' ), 'impact_way' => array( 'title' => $this->l('Impact Way'), @@ -663,4 +688,50 @@ class AdminHotelFeaturePricesSettingsController extends ModuleAdminController $this->addCSS(_MODULE_DIR_.'hotelreservationsystem/views/css/HotelReservationAdmin.css'); $this->addJs(_MODULE_DIR_.'hotelreservationsystem/views/js/HotelReservationAdmin.js'); } + + public function ajaxProcessGetHotelRoomTypes() + { + $response = array('status' => false); + + $idHotel = (int) Tools::getValue('id_hotel'); + $objHotelRoomType = new HotelRoomType(); + $hotelRoomTypes = array(); + + if ($idHotel > 0) { + if ($hotelRoomTypes = $objHotelRoomType->getRoomTypeByHotelId($idHotel, $this->context->language->id)) { + $objHotelBranchInformation = new HotelBranchInformation($idHotel, $this->context->language->id); + foreach ($hotelRoomTypes as &$hotelRoomType) { + $hotelRoomType['hotel_name'] = $objHotelBranchInformation->hotel_name; + } + } + } else if ($allHotelRoomTypes = $objHotelRoomType->getAllRoomTypes()) { + $hotels = array(); + foreach ($allHotelRoomTypes as $hotelRoomType) { + if (!array_key_exists($hotelRoomType['id_hotel'], $hotels)) { + $hotels[$hotelRoomType['id_hotel']] = new HotelBranchInformation( + $hotelRoomType['id_hotel'], + $this->context->language->id + ); + } + + $objProduct = new Product($hotelRoomType['id_product'], false, $this->context->language->id); + $hotelRoomTypes[] = array( + 'id_product' => $hotelRoomType['id_product'], + 'room_type' => $objProduct->name, + 'hotel_name' => $hotels[$hotelRoomType['id_hotel']]->hotel_name, + ); + } + } + + if ($hotelRoomTypes) { + $response['status'] = true; + $response['has_room_types'] = true; + $response['room_types_info'] = $hotelRoomTypes; + } else { + $response['has_room_types'] = false; + $response['status'] = true; + } + + $this->ajaxDie(json_encode($response)); + } } diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php index ca6e55912..286459efd 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php @@ -397,6 +397,12 @@ class AdminHotelGeneralSettingsController extends ModuleAdminController 'hint' => $this->l('Unique API key for Google Maps.'), 'type' => 'text', ), + 'PS_MAP_ID' => array( + 'title' => $this->l('Google Map ID'), + 'hint' => $this->l('Map Id for Google Maps.'), + 'type' => 'text', + 'desc' => $this->l('Google Maps API Key and Google Map ID is required to display Google Maps.') + ), 'WK_GOOGLE_ACTIVE_MAP' => array( 'title' => $this->l('Display Google Maps For Hotel Location'), 'cast' => 'intval', @@ -600,6 +606,9 @@ class AdminHotelGeneralSettingsController extends ModuleAdminController if (!Tools::getValue('PS_API_KEY')) { $this->errors[] = $this->l('Please enter Google API key.'); } + if (!Tools::getValue('PS_MAP_ID')) { + $this->errors[] = $this->l('Please enter Google Map Id.'); + } } if (!trim(Tools::getValue('PS_SHOP_NAME'))) { $this->errors[] = $this->l('Website name field is required'); diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelfeaturesController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelfeaturesController.php index 8d7611c62..e2bd87471 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelfeaturesController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelfeaturesController.php @@ -97,8 +97,16 @@ class AdminHotelFeaturesController extends ModuleAdminController public function postProcess() { + if (!$this->loadObject(true)) { + return; + } + if (Tools::isSubmit('submitHtlFeatures') || Tools::isSubmit('submitHtlFeaturesAndStay')) { - $parentFeatureId = Tools::getValue('id'); + $conf = 3; + if ($parentFeatureId = Tools::getValue('id')) { + $conf = 4; + } + $pos = Tools::getValue('position'); $defaultLangId = Configuration::get('PS_LANG_DEFAULT'); @@ -142,9 +150,6 @@ class AdminHotelFeaturesController extends ModuleAdminController } } } - - if (!count($this->errors)) { - } } else { $this->errors[] = $this->l('Please add atleast one Child features.'); } @@ -217,10 +222,10 @@ class AdminHotelFeaturesController extends ModuleAdminController if (Tools::isSubmit('submitHtlFeaturesAndStay')) { Tools::redirectAdmin( self::$currentIndex.'&id='.(int) $parentFeatureId.'&update'.$this->table. - '&conf=4&token='.$this->token + '&conf='.$conf.'&token='.$this->token ); } else { - Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); + Tools::redirectAdmin(self::$currentIndex.'&conf='.$conf.'&token='.$this->token); } } else { $this->errors[] = $this->l('Some error has been occurred while saving features.'); @@ -262,10 +267,10 @@ class AdminHotelFeaturesController extends ModuleAdminController if (Tools::isSubmit('submitHtlFeaturesAndStay')) { Tools::redirectAdmin( self::$currentIndex.'&id='.(int) $parentFeatureId.'&update'.$this->table. - '&conf=4&token='.$this->token + '&conf='.$conf.'&token='.$this->token ); } else { - Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); + Tools::redirectAdmin(self::$currentIndex.'&conf='.$conf.'&token='.$this->token); } } } else { @@ -279,7 +284,10 @@ class AdminHotelFeaturesController extends ModuleAdminController $this->display = 'add'; } } - parent::postProcess(); + + if (empty($this->errors) || $this->ajax) { + parent::postProcess(); + } } public function ajaxProcessDeleteFeature() diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index 8da3931ea..41b38b695 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -285,6 +285,7 @@ class HotelReservationSystem extends Module if (Tools::getValue('controller') == 'category') { if (($apiKey = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP') + && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) ) { $idCategory = Tools::getValue('id_category'); $idHotel = HotelBranchInformation::getHotelIdByIdCategory($idCategory); @@ -299,13 +300,14 @@ class HotelReservationSystem extends Module 'longitude' => $objHotel->longitude, 'map_input_text' => $objHotel->map_input_text, ), + 'PS_MAP_ID' => $PS_MAP_ID, 'hotel_name' => $objHotel->hotel_name, 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), )); $this->context->controller->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places&language='. - $this->context->language->iso_code.'®ion='.$this->context->country->iso_code + 'https://maps.googleapis.com/maps/api/js?key='.$apiKey. + '&libraries=places,marker&loading=async&callback=initMap&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); $this->context->controller->addJS($this->getPathUri().'views/js/searchResultsMap.js'); $this->context->controller->addCSS($this->getPathUri().'views/css/searchResultsMap.css'); diff --git a/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css b/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css index 5dd54412f..b27f73368 100644 --- a/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css +++ b/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css @@ -472,10 +472,7 @@ p.room_cat_data } #pac-input { - background-color: #fff; - height: 38px; width: 300px; - font-size: 14px; text-overflow: ellipsis; } diff --git a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js index c6e6a80a2..24d0ea886 100644 --- a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js +++ b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js @@ -22,17 +22,12 @@ var GoogleMapsManager = { defaultZoom: 10, map: null, markers: [], - placesService: null, + placeService: null, init: function(jQDiv) { this.mapDiv = jQDiv; this.geocoder = new google.maps.Geocoder(); }, - setPlacesService: function() { - if (!this.placesService && this.map) { - this.placesService = new google.maps.places.PlacesService(this.map); - } - }, setDefaultLatLng: function(cb) { if (!this.defaultLatLng) { var latitude = Number($("#loclatitude").val()); @@ -64,6 +59,24 @@ var GoogleMapsManager = { } } }, + fetchFields: async function(request) { + if (!request.placeId) return; + const place = new google.maps.places.Place({ + id: request.placeId + }); + + const fieldsRequest = { + fields: ["displayName", "formattedAddress", "location"] + }; + + try { + await place.fetchFields(fieldsRequest); + this.placeService = place; + return place; + } catch (error) { + console.log(error); + } + }, initMap: function(cb) { if (!this.map) { var that = this; @@ -71,85 +84,26 @@ var GoogleMapsManager = { that.map = new google.maps.Map($(that.mapDiv).get(0), { zoom: that.defaultZoom, clickableIcons: true, + mapId: PS_MAP_ID }); that.map.setCenter(that.defaultLatLng); if (that.defaultLatLng && that.formattedAddress) { that.addMarker(that.defaultLatLng, null, that.formattedAddress); } - that.setPlacesService(); - // register marker events that.map.addListener('click', function (e) { var latLng = e.latLng; - - var isInfoWindowNeeded = true; // if it is a Place Of Interest (POI), event contains the property 'placeId' if (Object.hasOwn(e, 'placeId')) { - isInfoWindowNeeded = false; - - that.geocoder.geocode({ location: latLng }, function (results, status) { - if (status == google.maps.GeocoderStatus.OK && results[0]) { - var request = { - placeId: e.placeId, - fields: ['name'], - }; - - that.placesService.getDetails(request, function(place, status) { - if (status === google.maps.places.PlacesServiceStatus.OK) { - var content = '
' + place.name + '

' + - results[0].formatted_address + '

'; - - var callback = function (latLng) { - that.setFormVars({ - lat: latLng.lat(), - lng: latLng.lng(), - formattedAddress: content, - inputText: $('#pac-input').val(), - }); - } - - that.addMarker( - latLng, - results[0], - null, - isInfoWindowNeeded, - callback(latLng) - ); - } - }); + that.fetchFields({ placeId: e.placeId }).then(place => { + if (place && place.location) { + that.addMarker(place.location, null, place.formattedAddress); } }); } else { - that.geocoder.geocode({ location: latLng }, function (results, status) { - if (status == google.maps.GeocoderStatus.OK && results[0]) { - var request = { - placeId: results[0].place_id, - fields: ['name'], - }; - - that.placesService.getDetails(request, function(place, status) { - if (status === google.maps.places.PlacesServiceStatus.OK) { - var content = '
' + place.name + '

' + - results[0].formatted_address + '

'; - - var callback = function (latLng) { - that.setFormVars({ - lat: latLng.lat(), - lng: latLng.lng(), - formattedAddress: content, - inputText: $('#pac-input').val(), - }); - } - - that.addMarker( - latLng, - results[0], - null, - isInfoWindowNeeded, - callback(latLng) - ); - } - }); + that.geocoder.geocode({ location: latLng }, function(results, status) { + if (status === 'OK' && results[0]) { + that.addMarker(latLng, null, results[0].formatted_address); } }); } @@ -163,42 +117,37 @@ var GoogleMapsManager = { cb(); } } - }, initAutocomplete: function(jQInput, cb) { var that = this; that.initMap(function() { that.autocompleteInput = jQInput; var input = $(that.autocompleteInput).get(0); - that.map.controls[google.maps.ControlPosition.TOP_CENTER].push(input); - that.autocomplete = new google.maps.places.Autocomplete(input); - that.autocomplete.bindTo('bounds', that.map); - - that.autocomplete.addListener('place_changed', function() { - that.clearAllMarkers(); - var place = that.autocomplete.getPlace(); - - if (place.geometry.viewport) { - that.map.fitBounds(place.geometry.viewport); - } else { - that.map.setCenter(place.geometry.location); - that.map.setZoom(18); - } - var latLng = { - lat: place.geometry.location.lat(), - lng: place.geometry.location.lng(), - }; - that.addMarker(latLng, place); - - var content = '
' + place.name + '

' + place.formatted_address + '

'; - that.setFormVars({ - lat: latLng.lat, - lng: latLng.lng, - formattedAddress: content, - inputText: $('#pac-input').val(), - }); + that.autocomplete = new google.maps.places.PlaceAutocompleteElement({ + locationRestriction: that.map.getBounds() }); + that.autocomplete.id = "place-autocomplete-input"; + input.appendChild(that.autocomplete); + + that.map.controls[google.maps.ControlPosition.TOP_LEFT].push(input); + that.infoWindow = new google.maps.InfoWindow({}); + that.autocomplete.addEventListener("gmp-select", async (event) => { + const place = event.placePrediction.toPlace(); + + await place.fetchFields({ + fields: ["displayName", "formattedAddress", "location", "viewport"] + }); + // Fit the map to the place + if (place.viewport) { + that.map.fitBounds(place.viewport); + } else { + that.map.setCenter(place.location); + that.map.setZoom(18); + } + + that.addMarker(place.location, null, place.formattedAddress); + }); google.maps.event.addDomListener(input, 'keydown', function (e) { if (e.keyCode === 13) { e.preventDefault(); @@ -213,11 +162,17 @@ var GoogleMapsManager = { addMarker: function(latLng, address = null, fa = null, addInfoWindow = true, cb = null) { var that = this; that.clearAllMarkers(); - var marker = new google.maps.Marker({ + + let icon = document.createElement('img'); + icon.src = PS_STORES_ICON; + icon.style.width = '24px'; + icon.style.height = '24px'; + + var marker = new google.maps.marker.AdvancedMarkerElement({ position: latLng, map: that.map, + content: icon, draggable: true, - icon: PS_STORES_ICON }); that.markers.push(marker); marker.addListener('dragend', function(e) { @@ -237,22 +192,11 @@ var GoogleMapsManager = { // open info window that.addInfoWindow(marker, fa); } else { - var request = { - placeId: address.place_id, - fields: ['name'], - }; - - that.placesService.getDetails(request, function(place, status) { - if (status === google.maps.places.PlacesServiceStatus.OK) { - // open info window - var content = '
' + place.name + '

' + address.formatted_address + '

'; - that.addInfoWindow(marker, content); - - if(cb && typeof cb === 'function') { - cb(); - } - } - }); + var content = '
' + this.placeService.displayName + '

' + address.formatted_address + '

'; + that.addInfoWindow(marker, content); + if(cb && typeof cb === 'function') { + cb(); + } } } else { if(cb && typeof cb === 'function') { @@ -287,10 +231,10 @@ var GoogleMapsManager = { that.clearAllMarkers(); }); - var latLng = marker.getPosition(); + var latLng = marker.position; that.setFormVars({ - lat: latLng.lat(), - lng: latLng.lng(), + lat: latLng.lat, + lng: latLng.lng, formattedAddress: content, inputText: $('#pac-input').val(), }); @@ -988,8 +932,6 @@ $(document).ready(function() { $('input[name="min_booking_offset"]').closest('.form-group').show(200); } }); - - initGoogleMaps(); }); function toggleGoogleMapsFields() diff --git a/modules/hotelreservationsystem/views/js/searchResultsMap.js b/modules/hotelreservationsystem/views/js/searchResultsMap.js index f24c762c4..39fc4faf7 100644 --- a/modules/hotelreservationsystem/views/js/searchResultsMap.js +++ b/modules/hotelreservationsystem/views/js/searchResultsMap.js @@ -28,33 +28,36 @@ function initMap() { center: hotelLocation, disableDefaultUI: true, fullscreenControl: true, + mapId: PS_MAP_ID }); - const marker = new google.maps.Marker({ - position: hotelLocation, + let icon = document.createElement('img'); + icon.src = PS_STORES_ICON; + icon.style.width = '24px'; + icon.style.height = '24px'; + + const marker = new google.maps.marker.AdvancedMarkerElement({ map: map, - title: hotel_name, - icon: PS_STORES_ICON + position: hotelLocation, + title: location.hotel_name, + content: icon, }); + marker.query = location.query || null; + marker.latitude = hotelLocation.lat; + marker.longitude = hotelLocation.lng; + marker.addListener('click', function() { let query = ''; - if (hotel_location.map_input_text != '') { - query = hotel_location.map_input_text; - } else { - query = hotel_location.latitude + ',' + hotel_location.longitude; + if (this.query) { + query = this.query; + } else if (this.latitude && this.longitude) { + query = `${this.latitude},${this.longitude}`; } - window.open('https://www.google.com/maps/search/?api=1&query='+encodeURIComponent(query), '_blank'); + if (query) { + window.open(`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(query)}`, '_blank'); + } }); } -$(document).ready(function() { - if (typeof hotel_location == 'object' - && $('#search-results-wrap .map-wrap').length - && typeof google == 'object' - && typeof google.maps == 'object' - ) { - initMap(); - } -}); diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl index db7b2070a..1fd9dd071 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl @@ -303,7 +303,7 @@ - +
diff --git a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl index 30a613ea2..d799be9da 100644 --- a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/form/form.tpl @@ -124,7 +124,7 @@ {/if} {if isset($restrictions) && $restrictions} {foreach $restrictions as $key => $restriction} - {include file="../../../_partials/feature_price_rules.tpl" key=$key advancePriceRule=$rule} + {include file="../../../_partials/feature_price_rules.tpl" key=$key} {/foreach} {else} {include file="../../../_partials/feature_price_rules.tpl" key=0 collapse=true} diff --git a/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/list/index.php b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/list/index.php new file mode 100644 index 000000000..409280877 --- /dev/null +++ b/modules/hotelreservationsystem/views/templates/admin/hotel_feature_prices_settings/helpers/list/index.php @@ -0,0 +1,32 @@ + + $(document).ready(function(){ + updateRoomTypeFilter(); + function updateRoomTypeFilter() { + let filterInputHotelName = $('#filter_input_hotel_name'); + let filterInputRoomTypeName = $('#filter_input_product_name'); + + let idHotel = parseInt($(filterInputHotelName).val() || '0'); + + $.ajax({ + url: currentIndex + '&token=' + token, + data: { + ajax: true, + action: 'GetHotelRoomTypes', + id_hotel: idHotel, + }, + type: 'POST', + dataType: 'JSON', + success: function(response) { + if (response.status) { + let selectedIdRoomType = parseInt($(filterInputRoomTypeName).val() || '0'); + let hasSelectedRoomType = false; + if (response.has_room_types) { + let selectElem = $(' + +
{if isset($quantity)}{$quantity|intval}{else}{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if}{/if}
@@ -266,7 +275,7 @@ - {if $product->available_for_order} + {if !$is_out_of_stock && !$max_qty_reached}
{/if} {else} @@ -301,7 +310,14 @@ {/block}
- {if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || (isset($restricted_country_mode) && $restricted_country_mode) || $PS_CATALOG_MODE} + {if $is_out_of_stock} +
+ {l s='Product is out of stock!'} +
+ {else if $max_qty_reached} +
+ {l s='Max. quantity reached for cart!'} +
{else} {block name='booking_form_book_now_button'}

diff --git a/themes/hotel-reservation-theme/js/contact-form.js b/themes/hotel-reservation-theme/js/contact-form.js index 4f8f51dc2..9b16260d5 100644 --- a/themes/hotel-reservation-theme/js/contact-form.js +++ b/themes/hotel-reservation-theme/js/contact-form.js @@ -48,15 +48,6 @@ $(document).ready(function() { }); showProductSelect($('select[name=id_order]').attr('value')); - - //By Webkul JS for Map locations of the hotels on google Map - if (typeof hotelLocationArray != 'undefined' - && $('#map').length - && typeof google == 'object' - && typeof google.maps == 'object' - ) { - initMap(); - } }); function showProductSelect(id_order) { @@ -75,7 +66,7 @@ function initMap() { hotelLocationArray = JSON.parse(hotelLocationArray); // Display a map on the page - map = new google.maps.Map(document.getElementById("map")); + map = new google.maps.Map(document.getElementById("map"), {mapId: PS_MAP_ID}); google.maps.event.trigger(map, 'resize'); map.setTilt(45); @@ -88,14 +79,17 @@ function initMap() { $.each(hotelLocationArray, function(i, location) { var position = new google.maps.LatLng(location.latitude, location.longitude); bounds.extend(position); - marker = new google.maps.Marker({ - position: position, - map: map, - title: location.hotel_name, - animation: google.maps.Animation.DROP, - icon: PS_STORES_ICON - }); + let icon = document.createElement('img'); + icon.src = PS_STORES_ICON; + icon.style.width = '24px'; + icon.style.height = '24px'; + marker = new google.maps.marker.AdvancedMarkerElement({ + map: map, + position: position, + title: location.hotel_name, + content: icon, + }); // Allow each marker to have an info window google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { 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 47836bee8..e3e4ac26f 100644 --- a/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js +++ b/themes/hotel-reservation-theme/js/modules/blockcart/ajax-cart.js @@ -432,6 +432,10 @@ var ajaxCart = { resetRoomtypeServices(); + if (parseInt($('#product_page_booking_product').val()) == 0) { + $('#service_product_qty').val(1); + } + BookingForm.refresh(true); } @@ -874,7 +878,7 @@ var ajaxCart = { content += '

'; 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' && typeof(hotel_wise_data.hotel_name) != 'undefined') ) { content += '
' + hotel_wise_data.hotel_name + '
'; } diff --git a/themes/hotel-reservation-theme/js/order-detail.js b/themes/hotel-reservation-theme/js/order-detail.js index b60101ccf..800440304 100644 --- a/themes/hotel-reservation-theme/js/order-detail.js +++ b/themes/hotel-reservation-theme/js/order-detail.js @@ -144,24 +144,36 @@ function initMap() { center: hotelLocation, disableDefaultUI: true, fullscreenControl: true, + mapId: PS_MAP_ID }); - const marker = new google.maps.Marker({ + let icon = document.createElement('img'); + icon.src = PS_STORES_ICON; + icon.style.width = '24px'; + icon.style.height = '24px'; + + const marker = new google.maps.marker.AdvancedMarkerElement({ position: hotelLocation, map: map, - title: $(this).attr('title'), - icon: PS_STORES_ICON + title: location.hotel_name, + content: icon, }); + marker.query = location.query || null; + marker.latitude = hotelLocation.lat; + marker.longitude = hotelLocation.lng; + marker.addListener('click', function() { let query = ''; - if ($(this).attr('query') != '') { - query = $(this).attr('query'); - } else { - query = $(this).attr('latitude') + ',' + $(this).attr('longitude'); + if (this.query) { + query = this.query; + } else if (this.latitude && this.longitude) { + query = `${this.latitude},${this.longitude}`; } - window.open('https://www.google.com/maps/search/?api=1&query='+encodeURIComponent(query), '_blank'); + if (query) { + window.open(`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(query)}`, '_blank'); + } }); }); } @@ -376,14 +388,5 @@ $(document).ready(function () { }); initPriceTooltip(); - - if (typeof google === 'object' - && typeof google.maps === 'object' - && typeof initiateMap !== 'undefined' - && initiateMap === 1 - ) { - initMap(); - } - initRefundDeniedTooltip(); }); diff --git a/themes/hotel-reservation-theme/js/our-properties.js b/themes/hotel-reservation-theme/js/our-properties.js index ba9408875..81a0d0be9 100644 --- a/themes/hotel-reservation-theme/js/our-properties.js +++ b/themes/hotel-reservation-theme/js/our-properties.js @@ -21,15 +21,6 @@ */ $(document).ready(function() { - //By Webkul JS for Map locations of the hotels on google Map - if (typeof hotelLocationArray != 'undefined' - && $('#map').length - && typeof google == 'object' - && typeof google.maps == 'object' - ) { - initMap(); - } - $(document).on('click', 'ul.pagination li a', function(e){ e.preventDefault(); $('#pagination').val($(this).data('pagination')); @@ -43,7 +34,7 @@ function initMap() { hotelLocationArray = JSON.parse(hotelLocationArray); // Display a map on the page - map = new google.maps.Map(document.getElementById("map")); + map = new google.maps.Map(document.getElementById("map"), {mapId: PS_MAP_ID}); google.maps.event.trigger(map, 'resize'); map.setTilt(45); @@ -56,12 +47,16 @@ function initMap() { $.each(hotelLocationArray, function(i, location) { var position = new google.maps.LatLng(location.latitude, location.longitude); bounds.extend(position); - marker = new google.maps.Marker({ - position: position, + let icon = document.createElement('img'); + icon.src = PS_STORES_ICON; + icon.style.width = '24px'; + icon.style.height = '24px'; + + marker = new google.maps.marker.AdvancedMarkerElement({ map: map, + position: position, title: location.hotel_name, - animation: google.maps.Animation.DROP, - icon: PS_STORES_ICON + content: icon, }); // Allow each marker to have an info window diff --git a/themes/hotel-reservation-theme/js/product.js b/themes/hotel-reservation-theme/js/product.js index 22e483de5..b0771177c 100644 --- a/themes/hotel-reservation-theme/js/product.js +++ b/themes/hotel-reservation-theme/js/product.js @@ -1089,15 +1089,6 @@ $(document).ready(function() { } e.preventDefault(); }); - - if (typeof hotel_location == 'object' - && $('#room_type_map_tab .map-wrap').length - && typeof google == 'object' - && typeof google.maps == 'object' - ) { - initMap(); - } - // normal product $(document).on('click', '.add_roomtype_product', function(e){ e.preventDefault(); @@ -1206,13 +1197,29 @@ $(document).ready(function() { e.preventDefault(); qtyfield = $(this).closest('.qty_container').find('input.service_product_qty'); var newQuantity = parseInt(qtyfield.val()) + 1; - if (qtyfield.data('max_quantity') && qtyfield.data('max_quantity') < newQuantity) { - // if max quantity is reached - newQuantity = qtyfield.data('max_quantity'); - - showErrorMessage(max_service_product_qty_txt+' '+qtyfield.data('max_quantity')); + let hasStockError = false; + if (parseInt($('#product_page_booking_product').val()) == 0) { + let stockQty = parseInt($(this).closest('.qty_container').find('.stock_qty').data('stock_quantity')); + let allow_oosp = parseInt($(this).closest('.qty_container').find('.stock_qty').data('allow_oosp')); + if (!allow_oosp && (stockQty < newQuantity)) { + showErrorMessage(out_of_stock_text); + newQuantity = stockQty; + hasStockError = true; + } + } + if (!hasStockError) { + if (qtyfield.data('max_quantity') && qtyfield.data('max_quantity') < newQuantity) { + // if max quantity is reached + newQuantity = qtyfield.data('max_quantity'); + let cartQty = parseInt(qtyfield.data('cart_quantity')); + if (isNaN(cartQty)) { + cartQty = 0; + } + + showErrorMessage(max_service_product_qty_txt+' '+ (parseInt(qtyfield.data('max_quantity')) + cartQty)); + } + $(this).closest('.qty_container').find('.qty_count span').text(newQuantity); } - $(this).closest('.qty_container').find('.qty_count span').text(newQuantity); qtyfield.val(newQuantity); clearTimeout(timer); timer = setTimeout(function() { @@ -1306,6 +1313,7 @@ function initMap() { const map = new google.maps.Map($('#room_type_map_tab .map-wrap').get(0), { zoom: 10, streetViewControl: false, + mapId: PS_MAP_ID }); const hotelLatLng = { @@ -1314,11 +1322,14 @@ function initMap() { }; map.setCenter(hotelLatLng); - - const marker = new google.maps.Marker({ + let icon = document.createElement('img'); + icon.src = PS_STORES_ICON; + icon.style.width = '24px'; + icon.style.height = '24px'; + let marker = new google.maps.marker.AdvancedMarkerElement({ position: hotelLatLng, map: map, - icon: PS_STORES_ICON + content: icon, }); const uiContent = $('#room-info-map-ui-content .hotel-info-wrap').get(0); diff --git a/themes/hotel-reservation-theme/product.tpl b/themes/hotel-reservation-theme/product.tpl index 351edf8f8..9492fbc86 100644 --- a/themes/hotel-reservation-theme/product.tpl +++ b/themes/hotel-reservation-theme/product.tpl @@ -877,6 +877,7 @@ {addJsDefL name=service_removed_txt}{l s='Service removed' js=1}{/addJsDefL} {addJsDefL name=service_updated_txt}{l s='Service updated' js=1}{/addJsDefL} {addJsDefL name=max_service_product_qty_txt}{l s='Maximum allowed quantity in the cart is' js=1}{/addJsDefL} + {addJsDefL name=out_of_stock_text}{l s='Requested quantitity is out of stock' js=1}{/addJsDefL} {/strip} {/block} {/if}