diff --git a/admin/themes/default/template/controllers/normal_products/quantities.tpl b/admin/themes/default/template/controllers/normal_products/quantities.tpl index e88e0d44a..59ae50ed7 100644 --- a/admin/themes/default/template/controllers/normal_products/quantities.tpl +++ b/admin/themes/default/template/controllers/normal_products/quantities.tpl @@ -213,7 +213,7 @@ {/if} {/if} diff --git a/classes/Product.php b/classes/Product.php index 5e5f56417..07ab39229 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -3248,7 +3248,7 @@ class ProductCore extends ObjectModel (int)$context->country->id, $id_group, $quantity, - $id_product_attribute, + $id_product_option, $id_customer, $id_cart, $real_quantity @@ -3335,7 +3335,10 @@ class ProductCore extends ObjectModel $price = (float)$specific_price['price']; } - if (isset($result['option_impact_price'])) { + // add option impact only if specific price is not set for this option + if ((!$specific_price || !$specific_price['id_product_attribute'] || $specific_price['price'] < 0) + && isset($result['option_impact_price']) + ) { $price += (float)$result['option_impact_price']; } @@ -3356,9 +3359,6 @@ class ProductCore extends ObjectModel } } - // find and add if any auto_add services are attached - - Hook::exec( 'actionProductPriceModifier', array( diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 365c9b1f9..1c932886b 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -5056,6 +5056,7 @@ class AdminOrdersControllerCore extends AdminController $idOrder = (int) Tools::getValue('id_order'); $idProduct = $productInformations['product_id']; $objOrder = new Order($idOrder); + $idProductOption = null; $addressTax = new Address($objOrder->id_address_tax, $this->context->language->id); if (!$this->tabAccess['edit'] == 1) { $response['status'] = false; @@ -5075,12 +5076,17 @@ class AdminOrdersControllerCore extends AdminController } elseif (!Validate::isLoadedObject($objProduct = new Product($idProduct, false, $objOrder->id_lang))) { $response['status'] = false; $response['error'] = Tools::displayError('The product object cannot be loaded.'); - } elseif ($objProduct->selling_preference_type != Product::SELLING_PREFERENCE_STANDALONE) { - if (!$addressTax->id_hotel - || !Validate::isLoadedObject($objHotel = new HotelBranchInformation($addressTax->id_hotel)) - ) { - $response['status'] = false; - $response['error'] = Tools::displayError('The hotel object cannot be loaded.'); + } elseif ($objProduct->selling_preference_type != Product::SELLING_PREFERENCE_STANDALONE + && (!$addressTax->id_hotel + || !Validate::isLoadedObject($objHotel = new HotelBranchInformation($addressTax->id_hotel))) + ) { + $response['status'] = false; + $response['error'] = Tools::displayError('The hotel object cannot be loaded.'); + } elseif (ServiceProductOption::productHasOptions($idProduct)) { + if (!$productInformations['product_option']) { + $this->errors[] = Tools::displayError('Cannot add service without a option.'); + } else { + $idProductOption = $productInformations['product_option']; } } @@ -5111,7 +5117,7 @@ class AdminOrdersControllerCore extends AdminController $initialProductPriceTI = Product::getPriceStatic( $idProduct, $useTaxes, - null, + $idProductOption, 2, null, false, @@ -5131,9 +5137,10 @@ class AdminOrdersControllerCore extends AdminController $objSpecificPrice->id_currency = 0; $objSpecificPrice->id_country = 0; $objSpecificPrice->id_group = 0; + $objSpecificPrice->id_cart = $objCart->id; $objSpecificPrice->id_customer = $objOrder->id_customer; $objSpecificPrice->id_product = $idProduct; - $objSpecificPrice->id_product_attribute = 0; + $objSpecificPrice->id_product_attribute = $idProductOption; $objSpecificPrice->price = $productInformations['product_price_tax_excl']; $objSpecificPrice->from_quantity = 1; $objSpecificPrice->reduction = 0; @@ -6213,7 +6220,7 @@ class AdminOrdersControllerCore extends AdminController $idOrder = Tools::getValue('id_order'); $idOrderDetail = Tools::getValue('id_order_detail'); - $idProductOrderDetail = Tools::getValue('id_service_product_order_detail'); + $idServiceProdOrderDetail = Tools::getValue('id_service_product_order_detail'); $objOrder = new Order($idOrder); $objOrderDetail = new OrderDetail($idOrderDetail); @@ -6227,7 +6234,7 @@ class AdminOrdersControllerCore extends AdminController $response['status'] = false; $response['error'] = Tools::displayError('Product information not found.'); } elseif (!Validate::isLoadedObject( - $objServiceProductOrderDetail = new ServiceProductOrderDetail($idProductOrderDetail) + $objServiceProductOrderDetail = new ServiceProductOrderDetail($idServiceProdOrderDetail) )) { $response['status'] = false; $response['error'] = Tools::displayError('Product information not found.'); @@ -6255,26 +6262,26 @@ class AdminOrdersControllerCore extends AdminController $objOrderDetail->reinjectQuantity($objOrderDetail, $qty, true); } else { $objOrderDetail->reinjectQuantity($objOrderDetail, $qty); - $objOrderDetail->total_paid_tax_excl -= $total_price_tax_excl; - $objOrderDetail->total_paid_tax_incl -= $total_price_tax_incl; + $objOrderDetail->total_price_tax_incl -= (float)$total_price_tax_incl; + $objOrderDetail->total_price_tax_excl -= (float)$total_price_tax_excl; $objOrderDetail->product_quantity -= $qty; $objOrderDetail->update(); } - $result &= $objServiceProductOrderDetail->delete(); + if ($result &= $objServiceProductOrderDetail->delete()) { + // Update Order + $objOrder->total_paid = Tools::ps_round($objOrder->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_); + $objOrder->total_paid_tax_incl = Tools::ps_round($objOrder->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_); + $objOrder->total_paid_tax_excl = Tools::ps_round($objOrder->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_); - // Update Order - $objOrder->total_paid = Tools::ps_round($objOrder->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_); - $objOrder->total_paid_tax_incl = Tools::ps_round($objOrder->getOrderTotal(), _PS_PRICE_COMPUTE_PRECISION_); - $objOrder->total_paid_tax_excl = Tools::ps_round($objOrder->getOrderTotal(false), _PS_PRICE_COMPUTE_PRECISION_); + $objOrder->total_products -= $total_price_tax_excl; + $objOrder->total_products = $objOrder->total_products > 0 ? $objOrder->total_products : 0; - $objOrder->total_products -= $total_price_tax_excl; - $objOrder->total_products = $objOrder->total_products > 0 ? $objOrder->total_products : 0; + $objOrder->total_products_wt -= $total_price_tax_incl; + $objOrder->total_products_wt = $objOrder->total_products_wt > 0 ? $objOrder->total_products_wt : 0; - $objOrder->total_products_wt -= $total_price_tax_incl; - $objOrder->total_products_wt = $objOrder->total_products_wt > 0 ? $objOrder->total_products_wt : 0; - - $result &= $objOrder->update(); + $result &= $objOrder->update(); + } if (!$result) { $response['status'] = false; diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index 7afb49a7e..bd34ca09b 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('cannot add more than %d quantity.', $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)); } } 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('cannot add more than %d quantity.', $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)); } } elseif ($productCartDetail) { $this->errors[] = Tools::displayError('You can only order one quantity for this product.'); @@ -536,7 +536,7 @@ class CartControllerCore extends FrontController } } } else { - $this->errors[] = Tools::displayError('cannot add product without room in cart'); + $this->errors[] = Tools::displayError('Can not add product without room in cart'); } } diff --git a/js/admin/orders.js b/js/admin/orders.js index a23fce478..a0778bee1 100644 --- a/js/admin/orders.js +++ b/js/admin/orders.js @@ -425,8 +425,6 @@ function initProductEvents() var tax_rate = current_product.tax_rate / 100 + 1; - console.log(current_product); - $('#add_product_product_price_tax_incl').val(ps_round(price_tax_excl * tax_rate, 2)); }); diff --git a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php index 67a77ad66..7e7368dd4 100644 --- a/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php +++ b/modules/hotelreservationsystem/classes/ServiceProductCartDetail.php @@ -219,7 +219,10 @@ class ServiceProductCartDetail extends ObjectModel $product['id_hotel'], false, $useTax, - $qty + $qty, + null, + null, + $idCart ); } else { $context = Context::getContext(); @@ -228,15 +231,24 @@ class ServiceProductCartDetail extends ObjectModel $product['id_product_option'], $product['id_hotel'], false, - true + true, + 1, + null, + null, + $idCart ); $priceTaxExcl = Product::getServiceProductPrice( $objProduct->id, $product['id_product_option'], $product['id_hotel'], false, - false + false, + 1, + null, + null, + $idCart ); + $optionDetails = false; if (ServiceProductOption::productHasOptions($product['id_product'])) { $optionDetails = $objServiceProductOption->getProductOptions( diff --git a/themes/hotel-reservation-theme/js/product.js b/themes/hotel-reservation-theme/js/product.js index a6d4c7fdf..dbf43667e 100644 --- a/themes/hotel-reservation-theme/js/product.js +++ b/themes/hotel-reservation-theme/js/product.js @@ -1207,7 +1207,10 @@ $(document).ready(function() { 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')); } $(this).closest('.qty_container').find('.qty_count span').text(newQuantity); qtyfield.val(newQuantity); diff --git a/themes/hotel-reservation-theme/product.tpl b/themes/hotel-reservation-theme/product.tpl index 07a09073f..431fffb75 100644 --- a/themes/hotel-reservation-theme/product.tpl +++ b/themes/hotel-reservation-theme/product.tpl @@ -860,6 +860,7 @@ {addJsDefL name=service_added_txt}{l s='Service added' js=1}{/addJsDefL} {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} {/strip} {/block} {/if}