Merge pull request #613 from shreesh-webkul/gli-1274

Added: Feature limit quantity of service products per room
This commit is contained in:
Rohit Jain
2023-03-10 19:08:20 +05:30
committed by GitHub
11 changed files with 99 additions and 23 deletions

View File

@@ -5268,6 +5268,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;

View File

@@ -395,16 +395,26 @@ class CartControllerCore extends FrontController
if (Tools::getValue('op', 'up') == 'up') {
if ($total_available_rooms < $req_rm) {
die(json_encode(array('status' => 'unavailable_quantity', 'avail_rooms' => $total_available_rooms)));
} else {
// validate normal products if available
if ($serviceProducts) {
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
foreach ($serviceProducts as $key => $standartProduct) {
if (!$objRoomTypeServiceProduct->isRoomTypeLinkedWithProduct($this->id_product, $standartProduct['id_product'])) {
unset($serviceProducts[$key]);
} else {
// validate service products if available
if ($serviceProducts) {
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
foreach ($serviceProducts as $key => $serviceProduct) {
if (!$objRoomTypeServiceProduct->isRoomTypeLinkedWithProduct($this->id_product, $serviceProduct['id_product'])) {
unset($serviceProducts[$key]);
} else {
if (Validate::isLoadedObject($objServiceProduct = new Product($serviceProduct['id_product']))) {
if (!$objServiceProduct->allow_multiple_quantity && $serviceProduct['quantity'] > 1) {
$serviceProducts[$key]['quantity'] = 1;
} else if ($objServiceProduct->max_quantity && $objServiceProduct->max_quantity < $serviceProduct['quantity'] ) {
$serviceProducts[$key]['quantity'] = $objServiceProduct->max_quantity;
}
} else {
$response['error'] = Tools::displayError('Service not Found');
}
}
}
}
}
}
} else {
@@ -621,6 +631,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;

View File

@@ -689,10 +689,22 @@ class ProductControllerCore extends FrontController
$serviceProductsPrice = 0;
if ($roomServiceProducts = json_decode($roomServiceProducts, true)) {
$objRoomTypeServiceProductPrice = new RoomTypeServiceProductPrice();
$objRoomTypeServiceProduct = new RoomTypeServiceProduct();
foreach ($roomServiceProducts as &$product) {
$objProduct = new ProductCore($product['id_product'], false, $this->context->language->id);
$product['name'] = $objProduct->name;
$product['allow_multiple_quantity'] = $objProduct->allow_multiple_quantity;
if (!$objRoomTypeServiceProduct->isRoomTypeLinkedWithProduct($idProduct, $product['id_product'])) {
unset($product);
continue;
} else {
$objServiceProduct = new ProductCore($product['id_product'], false, $this->context->language->id);
if (!$objServiceProduct->allow_multiple_quantity && $product['quantity'] > 1) {
$product['quantity'] = 1;
} else if ($objServiceProduct->max_quantity && $objServiceProduct->max_quantity < $product['quantity'] ) {
$product['quantity'] = $objServiceProduct->max_quantity;
}
}
$product['name'] = $objServiceProduct->name;
$product['allow_multiple_quantity'] = $objServiceProduct->allow_multiple_quantity;
$productPrice = $objRoomTypeServiceProductPrice->getProductPrice($product['id_product'], $idProduct, $product['quantity'], $useTax);
$product['price'] = $productPrice;
$serviceProductsPrice += $productPrice;
@@ -1326,6 +1338,7 @@ class ProductControllerCore extends FrontController
$idProduct = Tools::getValue('id_product');
$idServiceProduct = Tools::getValue('service_product');
$addedServiceProduct = Tools::getValue('added_service_product');
$qty = Tools::getValue('qty');
if (Validate::isLoadedObject($objProduct = new Product($idProduct))) {
if (!Product::isBookingProduct($idProduct)) {
$response['error'] = Tools::displayError('Room Type info not Found');
@@ -1338,16 +1351,31 @@ class ProductControllerCore extends FrontController
} else {
if (Validate::isLoadedObject($objServiceProduct = new Product($idServiceProduct))) {
$response['success'] = true;
if (!$objServiceProduct->allow_multiple_quantity && !empty($addedServiceProduct)) {
if (!in_array($idServiceProduct, array_column($addedServiceProduct, 'id_product'))) {
if (!$objServiceProduct->allow_multiple_quantity) {
if (!empty($addedServiceProduct)) {
if (!in_array($idServiceProduct, array_column($addedServiceProduct, 'id_product'))) {
$response['add'] = true;
$response['msg'] = 'Service is added to cart.';
} else {
$response['msg'] = 'Service already added.';
}
} else {
$response['add'] = true;
$response['msg'] = 'Service is added to cart.';
} else {
$response['msg'] = 'Service already added.';
}
} else {
$response['add'] = true;
$response['msg'] = 'Service is added to cart.';
$totalQty = $qty;
if (!empty($addedServiceProduct)) {
if (($key = array_search($idServiceProduct, array_column($addedServiceProduct, 'id_product')))!== false) {
$totalQty += $addedServiceProduct[$key]['quantity'];
}
}
if ($objServiceProduct->max_quantity && $objServiceProduct->max_quantity < $totalQty ) {
$response['msg'] = Tools::displayError(sprintf('Cannot add more than %d quantity.', $objServiceProduct->max_quantity));
} else {
$response['add'] = true;
$response['msg'] = Tools::displayError('Service is added to cart.');
}
}
} else {
$response['error'] = Tools::displayError('Service not Found');