Skip to content

Commit

Permalink
added max allowd quantity for service products
Browse files Browse the repository at this point in the history
  • Loading branch information
shreesh-webkul committed Mar 5, 2023
1 parent 7f7122d commit 3645f2d
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,17 @@
</span>
</div>
</div>
<div id="max_quantity_container" class="form-group" {if (!$product->available_for_order && $product->isAssociatedToShop()) || $product->auto_add_to_cart || !$product->allow_multiple_quantity}style="display:none;"{/if}>
<label class="control-label col-lg-3" for="max_quantity">
<span class="label-tooltip" data-toggle="tooltip"
title="{l s='Enter max allowed quantity per room, enter 0 for unlimited.'}">
{l s='Max quantity allow'}
</span>
</label>
<div class="col-lg-3">
<input type="text" id="max_quantity" name="max_quantity" value="{$product->max_quantity|escape:'html':'UTF-8'}" />
</div>
</div>
<div class="form-group">
<div class="col-lg-6 col-lg-offset-3">
<div class="alert alert-info">
Expand Down
4 changes: 4 additions & 0 deletions classes/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'),
Expand Down
2 changes: 2 additions & 0 deletions controllers/admin/AdminOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5264,6 +5264,8 @@ public function ajaxProcessUpdateServiceProduct()
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;
Expand Down
2 changes: 2 additions & 0 deletions controllers/front/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ protected function processUpdateServiceProduct()
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;
Expand Down
2 changes: 2 additions & 0 deletions install/data/db_structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions js/admin/normal_products.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<p>{$product['name']|escape:'html':'UTF-8'}</p>
{if $product.allow_multiple_quantity}
<div class="qty_container">
<input type="text" class="form-control qty" id="qty_{$product.id_product}" name="service_product_qty_{$product.id_product}" data-id-product="{$product.id_product}" value="{if isset($cartRoom['selected_products']) && $cartRoom['selected_products'] && ($product['id_product']|in_array:$cartRoom['selected_products'])}{$cartRoom['selected_products_info'][$product['id_product']]['quantity']}{else}1{/if}">
<input type="text" class="form-control qty" id="qty_{$product.id_product}" name="service_product_qty_{$product.id_product}" data-id-product="{$product.id_product}" data-max_quantity="{$product.max_quantity}" value="{if isset($cartRoom['selected_products']) && $cartRoom['selected_products'] && ($product['id_product']|in_array:$cartRoom['selected_products'])}{$cartRoom['selected_products_info'][$product['id_product']]['quantity']}{else}1{/if}">
<div class="qty_controls">
<a href="#" class="qty_up"><span><i class="icon-plus"></i></span></a>
<a href="#" class="qty_down"><span><i class="icon-minus"></i></span></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
{/if}
{if $product.allow_multiple_quantity && $product.available_for_order}
<div class="qty_container pull-right">
<input type="hidden" class="service_product_qty" id="service_product_qty_{$product.id_product}" name="service_product_qty_{$product.id_product}" data-id-product="{$product.id_product}" value="{if isset($product.quantity_added) && $product.quantity_added}{$product.quantity_added|escape:'html':'UTF-8'}{else}1{/if}">
<input type="hidden" class="service_product_qty" id="service_product_qty_{$product.id_product}" name="service_product_qty_{$product.id_product}" data-id-product="{$product.id_product}" data-max_quantity="{$product.max_quantity}" value="{if isset($product.quantity_added) && $product.quantity_added}{$product.quantity_added|escape:'html':'UTF-8'}{else}1{/if}">
<div class="qty_count pull-left">
<span>{if isset($product.quantity_added) && $product.quantity_added}{$product.quantity_added|escape:'html':'UTF-8'}{else}1{/if}</span>
</div>
Expand Down
10 changes: 8 additions & 2 deletions themes/hotel-reservation-theme/js/order-opc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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'));
Expand Down
9 changes: 6 additions & 3 deletions themes/hotel-reservation-theme/js/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3645f2d

Please sign in to comment.