@@ -270,64 +270,7 @@ protected function processChangeProductInCart()
270
270
$ id_cart = $ this ->context ->cart ->id ;
271
271
$ id_guest = $ this ->context ->cart ->id_guest ;
272
272
273
- // By Webkul : This code is to check available quantity of Room before adding it to cart.
274
- if (Module::isInstalled ('hotelreservationsystem ' ) && Module::isEnabled ('hotelreservationsystem ' )) {
275
- require_once _PS_MODULE_DIR_ .'hotelreservationsystem/define.php ' ;
276
- $ objRoomType = new HotelRoomType ();
277
- if ($ roomTypeInfo = $ objRoomType ->getRoomTypeInfoByIdProduct ($ this ->id_product )) {
278
- if ($ id_hotel = $ roomTypeInfo ['id_hotel ' ]) {
279
- if (strtotime ($ date_from ) < strtotime (date ('Y-m-d ' ))) {
280
- $ this ->errors [] = Tools::displayError ('You can \'t book room before current date ' );
281
- } elseif (strtotime ($ date_from ) >= strtotime ($ date_to )) {
282
- $ this ->errors [] = Tools::displayError ('Check-out date must be after check-in date ' );
283
- } elseif ($ maxOrdDate = HotelOrderRestrictDate::getMaxOrderDate ($ id_hotel )) {
284
- // Check Order restrict condition before adding in to cart
285
- if (strtotime ('-1 day ' , strtotime ($ maxOrdDate )) < strtotime ($ date_from )
286
- || strtotime ($ maxOrdDate ) < strtotime ($ date_to )
287
- ) {
288
- $ maxOrdDate = date ('d-m-Y ' , strtotime ($ maxOrdDate ));
289
- $ this ->errors [] = Tools::displayError ('You can \'t book room after date ' .$ maxOrdDate );
290
- }
291
- }
292
- if (!$ this ->errors ) {
293
- $ objBookingDtl = new HotelBookingDetail ();
294
- $ num_days = $ objBookingDtl ->getNumberOfDays ($ date_from , $ date_to );
295
- $ req_rm = $ this ->qty ;
296
- $ this ->qty = $ this ->qty * (int ) $ num_days ;
297
- $ obj_booking_dtl = new HotelBookingDetail ();
298
- if ($ hotel_room_data = $ obj_booking_dtl ->DataForFrontSearch (
299
- $ date_from ,
300
- $ date_to ,
301
- $ id_hotel ,
302
- $ this ->id_product ,
303
- 1 ,
304
- 0 ,
305
- 0 ,
306
- -1 ,
307
- 0 ,
308
- 0 ,
309
- $ id_cart ,
310
- $ id_guest
311
- )) {
312
- if (isset ($ hotel_room_data ['stats ' ]['num_avail ' ])) {
313
- $ total_available_rooms = $ hotel_room_data ['stats ' ]['num_avail ' ];
314
- if ($ total_available_rooms < $ req_rm ) {
315
- die (json_encode (array ('status ' => 'unavailable_quantity ' , 'avail_rooms ' => $ total_available_rooms )));
316
- }
317
- } else {
318
- $ this ->errors [] = Tools::displayError ('Rooms are unavailable. Please try with different dates ' );
319
- }
320
- } else {
321
- $ this ->errors [] = Tools::displayError ('Rooms are unavailable. Please try with different dates ' );
322
- }
323
- }
324
- } else {
325
- die (json_encode (array ('status ' => 'failed3 ' )));
326
- }
327
- } else {
328
- die (json_encode (array ('status ' => 'failed4 ' )));
329
- }
330
- }
273
+
331
274
332
275
if ($ this ->qty == 0 ) {
333
276
$ this ->errors [] = Tools::displayError ('Null quantity. ' , !Tools::getValue ('ajax ' ));
@@ -344,6 +287,68 @@ protected function processChangeProductInCart()
344
287
$ qty_to_check = $ this ->qty ;
345
288
$ cart_products = $ this ->context ->cart ->getProducts ();
346
289
290
+ // By Webkul : This code is to check available quantity of Room before adding it to cart.
291
+ // only check availability if qty is increasing
292
+ if (Module::isInstalled ('hotelreservationsystem ' ) && Module::isEnabled ('hotelreservationsystem ' )) {
293
+ require_once _PS_MODULE_DIR_ .'hotelreservationsystem/define.php ' ;
294
+ $ objRoomType = new HotelRoomType ();
295
+ if ($ roomTypeInfo = $ objRoomType ->getRoomTypeInfoByIdProduct ($ this ->id_product )) {
296
+ if ($ id_hotel = $ roomTypeInfo ['id_hotel ' ]) {
297
+ if (strtotime ($ date_from ) < strtotime (date ('Y-m-d ' ))) {
298
+ $ this ->errors [] = Tools::displayError ('You can \'t book room before current date ' );
299
+ } elseif (strtotime ($ date_from ) >= strtotime ($ date_to )) {
300
+ $ this ->errors [] = Tools::displayError ('Check-out date must be after check-in date ' );
301
+ } elseif ($ maxOrdDate = HotelOrderRestrictDate::getMaxOrderDate ($ id_hotel )) {
302
+ // Check Order restrict condition before adding in to cart
303
+ if (strtotime ('-1 day ' , strtotime ($ maxOrdDate )) < strtotime ($ date_from )
304
+ || strtotime ($ maxOrdDate ) < strtotime ($ date_to )
305
+ ) {
306
+ $ maxOrdDate = date ('d-m-Y ' , strtotime ($ maxOrdDate ));
307
+ $ this ->errors [] = Tools::displayError ('You can \'t book room after date ' .$ maxOrdDate );
308
+ }
309
+ }
310
+ if (!$ this ->errors ) {
311
+ $ objBookingDtl = new HotelBookingDetail ();
312
+ $ num_days = $ objBookingDtl ->getNumberOfDays ($ date_from , $ date_to );
313
+ $ req_rm = $ this ->qty ;
314
+ $ this ->qty = $ this ->qty * (int ) $ num_days ;
315
+ $ obj_booking_dtl = new HotelBookingDetail ();
316
+ if ($ hotel_room_data = $ obj_booking_dtl ->DataForFrontSearch (
317
+ $ date_from ,
318
+ $ date_to ,
319
+ $ id_hotel ,
320
+ $ this ->id_product ,
321
+ 1 ,
322
+ 0 ,
323
+ 0 ,
324
+ -1 ,
325
+ 0 ,
326
+ 0 ,
327
+ $ id_cart ,
328
+ $ id_guest
329
+ )) {
330
+ if (isset ($ hotel_room_data ['stats ' ]['num_avail ' ])) {
331
+ $ total_available_rooms = $ hotel_room_data ['stats ' ]['num_avail ' ];
332
+ if (Tools::getValue ('op ' , 'up ' ) == 'up ' ) {
333
+ if ($ total_available_rooms < $ req_rm ) {
334
+ die (json_encode (array ('status ' => 'unavailable_quantity ' , 'avail_rooms ' => $ total_available_rooms )));
335
+ }
336
+ }
337
+ } else {
338
+ $ this ->errors [] = Tools::displayError ('Rooms are unavailable. Please try with different dates ' );
339
+ }
340
+ } else {
341
+ $ this ->errors [] = Tools::displayError ('Rooms are unavailable. Please try with different dates ' );
342
+ }
343
+ }
344
+ } else {
345
+ die (json_encode (array ('status ' => 'failed3 ' )));
346
+ }
347
+ } else {
348
+ die (json_encode (array ('status ' => 'failed4 ' )));
349
+ }
350
+ }
351
+
347
352
if (is_array ($ cart_products )) {
348
353
foreach ($ cart_products as $ cart_product ) {
349
354
if ((!isset ($ this ->id_product_attribute ) || $ cart_product ['id_product_attribute ' ] == $ this ->id_product_attribute ) &&
@@ -401,44 +406,59 @@ protected function processChangeProductInCart()
401
406
if (!$ this ->errors ) {
402
407
$ cart_rules = $ this ->context ->cart ->getCartRules ();
403
408
$ available_cart_rules = CartRule::getCustomerCartRules ($ this ->context ->language ->id , (isset ($ this ->context ->customer ->id ) ? $ this ->context ->customer ->id : 0 ), true , true , true , $ this ->context ->cart , false , true );
404
- $ update_quantity = $ this ->context ->cart ->updateQty ($ this ->qty , $ this ->id_product , $ this ->id_product_attribute , $ this ->customization_id , Tools::getValue ('op ' , 'up ' ), $ this ->id_address_delivery );
405
409
406
410
/*------ BY Webkul ------*/
407
411
/*
408
412
* To add Rooms in hotel cart
409
413
*/
410
- $ this ->availQty = false ;
411
- $ id_customer = $ this ->context ->cart ->id_customer ;
412
- $ id_currency = $ this ->context ->cart ->id_currency ;
413
-
414
- $ hotel_room_info_arr = $ hotel_room_data ['rm_data ' ][0 ]['data ' ]['available ' ];
415
- $ chkQty = 0 ;
416
- foreach ($ hotel_room_info_arr as $ key_hotel_room_info => $ val_hotel_room_info ) {
417
- if ($ chkQty < $ req_rm ) {
418
- $ roomDemand = Tools::getValue ('roomDemands ' );
419
- $ roomDemand = json_decode ($ roomDemand , true );
420
- $ roomDemand = json_encode ($ roomDemand );
421
- $ obj_htl_cart_booking_data = new HotelCartBookingData ();
422
- $ obj_htl_cart_booking_data ->id_cart = $ this ->context ->cart ->id ;
423
- $ obj_htl_cart_booking_data ->id_guest = $ this ->context ->cart ->id_guest ;
424
- $ obj_htl_cart_booking_data ->id_customer = $ id_customer ;
425
- $ obj_htl_cart_booking_data ->id_currency = $ id_currency ;
426
- $ obj_htl_cart_booking_data ->id_product = $ val_hotel_room_info ['id_product ' ];
427
- $ obj_htl_cart_booking_data ->id_room = $ val_hotel_room_info ['id_room ' ];
428
- $ obj_htl_cart_booking_data ->id_hotel = $ val_hotel_room_info ['id_hotel ' ];
429
- $ obj_htl_cart_booking_data ->booking_type = 1 ;
430
- $ obj_htl_cart_booking_data ->quantity = $ num_days ;
431
- $ obj_htl_cart_booking_data ->extra_demands = $ roomDemand ;
432
- $ obj_htl_cart_booking_data ->date_from = $ date_from ;
433
- $ obj_htl_cart_booking_data ->date_to = $ date_to ;
434
- $ obj_htl_cart_booking_data ->save ();
435
- ++$ chkQty ;
414
+ if (Module::isInstalled ('hotelreservationsystem ' ) && Module::isEnabled ('hotelreservationsystem ' )) {
415
+ if (Tools::getValue ('op ' , 'up ' ) == 'up ' ) {
416
+ $ update_quantity = $ this ->context ->cart ->updateQty ($ this ->qty , $ this ->id_product , $ this ->id_product_attribute , $ this ->customization_id , Tools::getValue ('op ' , 'up ' ), $ this ->id_address_delivery );
417
+ $ this ->availQty = false ;
418
+ $ id_customer = $ this ->context ->cart ->id_customer ;
419
+ $ id_currency = $ this ->context ->cart ->id_currency ;
420
+
421
+ $ hotel_room_info_arr = $ hotel_room_data ['rm_data ' ][0 ]['data ' ]['available ' ];
422
+ $ chkQty = 0 ;
423
+ foreach ($ hotel_room_info_arr as $ key_hotel_room_info => $ val_hotel_room_info ) {
424
+ if ($ chkQty < $ req_rm ) {
425
+ $ roomDemand = Tools::getValue ('roomDemands ' );
426
+ $ roomDemand = json_decode ($ roomDemand , true );
427
+ $ roomDemand = json_encode ($ roomDemand );
428
+ $ obj_htl_cart_booking_data = new HotelCartBookingData ();
429
+ $ obj_htl_cart_booking_data ->id_cart = $ this ->context ->cart ->id ;
430
+ $ obj_htl_cart_booking_data ->id_guest = $ this ->context ->cart ->id_guest ;
431
+ $ obj_htl_cart_booking_data ->id_customer = $ id_customer ;
432
+ $ obj_htl_cart_booking_data ->id_currency = $ id_currency ;
433
+ $ obj_htl_cart_booking_data ->id_product = $ val_hotel_room_info ['id_product ' ];
434
+ $ obj_htl_cart_booking_data ->id_room = $ val_hotel_room_info ['id_room ' ];
435
+ $ obj_htl_cart_booking_data ->id_hotel = $ val_hotel_room_info ['id_hotel ' ];
436
+ $ obj_htl_cart_booking_data ->booking_type = 1 ;
437
+ $ obj_htl_cart_booking_data ->quantity = $ num_days ;
438
+ $ obj_htl_cart_booking_data ->extra_demands = $ roomDemand ;
439
+ $ obj_htl_cart_booking_data ->date_from = $ date_from ;
440
+ $ obj_htl_cart_booking_data ->date_to = $ date_to ;
441
+ $ obj_htl_cart_booking_data ->save ();
442
+ ++$ chkQty ;
443
+ } else {
444
+ break ;
445
+ }
446
+ }
447
+ $ this ->availQty = $ total_available_rooms - $ req_rm ;
436
448
} else {
437
- break ;
449
+ $ objCartBooking = new HotelCartBookingData ();
450
+ $ update_quantity = $ objCartBooking ->deleteCartBookingData (
451
+ $ id_cart ,
452
+ $ this ->id_product ,
453
+ 0 ,
454
+ $ date_from ,
455
+ $ date_to
456
+ );
457
+ $ this ->availQty = $ total_available_rooms + $ req_rm ;
458
+
438
459
}
460
+ $ this ->context ->cookie ->avail_rooms = $ this ->availQty ;
439
461
}
440
- $ this ->availQty = $ total_available_rooms - $ req_rm ;
441
- $ this ->context ->cookie ->avail_rooms = $ this ->availQty ;
442
462
/*------ BY Webkul ------*/
443
463
444
464
if ($ update_quantity < 0 ) {
0 commit comments