diff --git a/admin/themes/default/template/controllers/normal_products/informations.tpl b/admin/themes/default/template/controllers/normal_products/informations.tpl index f95d974eb..acc85a424 100644 --- a/admin/themes/default/template/controllers/normal_products/informations.tpl +++ b/admin/themes/default/template/controllers/normal_products/informations.tpl @@ -412,6 +412,17 @@ +
available_for_order && $product->isAssociatedToShop()) || $product->auto_add_to_cart || !$product->allow_multiple_quantity}style="display:none;"{/if}> + +
+ +
+
diff --git a/classes/Product.php b/classes/Product.php index 33d169e23..911610672 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -77,6 +77,9 @@ class ProductCore extends ObjectModel /** @var bool allow order for multiple quantities */ public $allow_multiple_quantity; + /** @var bool max allowed quantities */ + public $max_quantity; + /** @var string available_now */ public $available_now; @@ -308,6 +311,7 @@ class ProductCore extends ObjectModel 'ecotax' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice'), 'minimal_quantity' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isUnsignedInt'), 'allow_multiple_quantity' => array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'), + 'max_quantity' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isUnsignedInt'), 'price' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'required' => true), 'wholesale_price' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice'), 'unity' => array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isString'), diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index df4af2e8d..d6dc4524d 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -5264,6 +5264,8 @@ class AdminOrdersControllerCore extends AdminController if ($objProduct->allow_multiple_quantity) { if (!Validate::isUnsignedInt($qty)) { $this->errors[] = Tools::displayError('The quantity code you\'ve entered is invalid.'); + // } elseif ($objProduct->max_quantity && $qty > $objProduct->max_quantity) { + // $this->errors[] = Tools::displayError(sprintf('cannot add more than %d quantity.', $objProduct->max_quantity)); } } else { $qty = 1; diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index a2444c921..7736cc76f 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -621,6 +621,8 @@ class CartControllerCore extends FrontController if ($objProduct->allow_multiple_quantity) { if (!Validate::isUnsignedInt($qty)) { $this->errors[] = Tools::displayError('The quantity you\'ve entered is invalid.'); + } elseif ($objProduct->max_quantity && $qty > $objProduct->max_quantity) { + $this->errors[] = Tools::displayError(sprintf('cannot add more than %d quantity.', $objProduct->max_quantity)); } } else { $qty = 1; diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index 5bc961640..07a2b4097 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -1519,6 +1519,7 @@ CREATE TABLE `PREFIX_product` ( `quantity` int(10) NOT NULL DEFAULT '0', `minimal_quantity` int(10) unsigned NOT NULL DEFAULT '1', `allow_multiple_quantity` tinyint(1) unsigned NOT NULL DEFAULT '1', + `max_quantity` int(10) unsigned NOT NULL DEFAULT '1', `price` decimal(20,6) NOT NULL DEFAULT '0.000000', `wholesale_price` decimal(20,6) NOT NULL DEFAULT '0.000000', `unity` varchar(255) DEFAULT NULL, @@ -1578,6 +1579,7 @@ CREATE TABLE IF NOT EXISTS `PREFIX_product_shop` ( `ecotax` decimal(17,6) NOT NULL DEFAULT '0.000000', `minimal_quantity` int(10) unsigned NOT NULL DEFAULT '1', `allow_multiple_quantity` tinyint(1) unsigned NOT NULL DEFAULT '1', + `max_quantity` int(10) unsigned NOT NULL DEFAULT '1', `price` decimal(20,6) NOT NULL DEFAULT '0.000000', `wholesale_price` decimal(20,6) NOT NULL DEFAULT '0.000000', `unity` varchar(255) DEFAULT NULL, diff --git a/js/admin/normal_products.js b/js/admin/normal_products.js index abe3db07a..e15945f8b 100644 --- a/js/admin/normal_products.js +++ b/js/admin/normal_products.js @@ -449,6 +449,14 @@ product_tabs['Informations'] = new function(){ } }); + $('input[name=allow_multiple_quantity]').on('change', function(e) { + if ($(this).val() == 1) { + $('#max_quantity_container').show('fast'); + } else { + $('#max_quantity_container').hide('fast'); + } + }); + $('#related_product_autocomplete_input') .autocomplete('ajax_products_list.php?exclude_packs=0&excludeVirtuals=0&excludeIds='+id_product, { minChars: 1, diff --git a/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl b/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl index 788ef2cb0..077c3f9fb 100644 --- a/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl +++ b/themes/hotel-reservation-theme/_partials/cart_booking_demands.tpl @@ -118,7 +118,7 @@

{$product['name']|escape:'html':'UTF-8'}

{if $product.allow_multiple_quantity}
- +
diff --git a/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl b/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl index f700c7720..e2474c0d6 100644 --- a/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl +++ b/themes/hotel-reservation-theme/_partials/service-products-list-row.tpl @@ -50,7 +50,7 @@ {/if} {if $product.allow_multiple_quantity && $product.available_for_order}
- +
{if isset($product.quantity_added) && $product.quantity_added}{$product.quantity_added|escape:'html':'UTF-8'}{else}1{/if}
diff --git a/themes/hotel-reservation-theme/js/order-opc.js b/themes/hotel-reservation-theme/js/order-opc.js index 7456edabe..7f59c444e 100644 --- a/themes/hotel-reservation-theme/js/order-opc.js +++ b/themes/hotel-reservation-theme/js/order-opc.js @@ -468,8 +468,11 @@ $(document).ready(function() $(document).on('click', '#rooms_extra_services .qty_up', function(e) { e.preventDefault(); qtyfield = $(this).closest('.qty_container').find('input.qty'); - var currentVal = parseInt(qtyfield.val()); - qtyfield.val(currentVal + 1).trigger('focusout'); + var newQuantity = parseInt(qtyfield.val()) + 1; + if (qtyfield.data('max_quantity') < newQuantity) { + newQuantity = qtyfield.data('max_quantity'); + } + qtyfield.val(newQuantity).trigger('focusout'); }); $(document).on('click', '#rooms_extra_services .qty_down', function(e) { @@ -487,6 +490,9 @@ $(document).ready(function() var qty_wntd = $(this).val(); if (qty_wntd == '' || !$.isNumeric(qty_wntd)) { $(this).val(1); + } + if ($(this).data('max_quantity') < qty_wntd) { + $(this).val(qtyfield.data('max_quantity')); } if ($(this).closest('.room_demand_block').find('.change_room_type_service_product').is(':checked')) { updateServiceProducts($(this).closest('.room_demand_block').find('.change_room_type_service_product')); diff --git a/themes/hotel-reservation-theme/js/product.js b/themes/hotel-reservation-theme/js/product.js index 96ae9a806..57a92afa3 100644 --- a/themes/hotel-reservation-theme/js/product.js +++ b/themes/hotel-reservation-theme/js/product.js @@ -1106,9 +1106,12 @@ $(document).ready(function() { $(document).on('click', '.service_product_qty_up', function(e) { e.preventDefault(); qtyfield = $(this).closest('.qty_container').find('input.service_product_qty'); - var currentVal = parseInt(qtyfield.val()); - $(this).closest('.qty_container').find('.qty_count span').text(currentVal + 1); - qtyfield.val(currentVal + 1); + var newQuantity = parseInt(qtyfield.val()) + 1; + if (qtyfield.data('max_quantity') < newQuantity) { + newQuantity = qtyfield.data('max_quantity'); + } + $(this).closest('.qty_container').find('.qty_count span').text(newQuantity); + qtyfield.val(newQuantity); }); // The button to decrement the product value