diff --git a/CHANGELOG for v1.x.x.md b/CHANGELOG for v1.x.x.md index 32f39a178..eab1841e0 100644 --- a/CHANGELOG for v1.x.x.md +++ b/CHANGELOG for v1.x.x.md @@ -182,6 +182,8 @@ * #2716 [fixed] - After saving the default booking time product selected time for date range changes to 00:00:00 ,because of which not able to book appointment on frontend. +* #2717 [fixed] - Getting error message on adding rental product in cart if rental booking is not available for that day. + * #2722 [fixed] - warning showing when update event booking cart quantity from the product page * #2723 [fixed] - Compare product icon on header showing counts of compare product but there are no product in compare list. diff --git a/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php b/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php index a6c82a26f..7351eed17 100644 --- a/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php +++ b/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php @@ -140,24 +140,46 @@ class RentalSlot extends Booking public function isSlotExpired($cartItem) { $bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $cartItem['product_id']); - - $typeHelper = app($this->typeHelpers[$bookingProduct->type]); - $timeIntervals = $typeHelper->getSlotsByDate($bookingProduct, $cartItem['additional']['booking']['date']); + if (isset($cartItem['additional']['booking']['date'])) { + $timeIntervals = $this->getSlotsByDate($bookingProduct, $cartItem['additional']['booking']['date']); - $isExpired = true; + $isExpired = true; - foreach ($timeIntervals as $timeInterval) { - foreach ($timeInterval['slots'] as $slot) { - if ($slot['from_timestamp'] == $cartItem['additional']['booking']['slot']['from'] - && $slot['to_timestamp'] == $cartItem['additional']['booking']['slot']['to'] - ) { - $isExpired = false; + foreach ($timeIntervals as $timeInterval) { + foreach ($timeInterval['slots'] as $slot) { + if ($slot['from_timestamp'] == $cartItem['additional']['booking']['slot']['from'] + && $slot['to_timestamp'] == $cartItem['additional']['booking']['slot']['to'] + ) { + $isExpired = false; + } } } - } - return $isExpired; + return $isExpired; + } else { + $requestedFromDate = Carbon::createFromTimeString($cartItem['additional']['booking']['date_from'] . " 00:00:00"); + + $requestedToDate = Carbon::createFromTimeString($cartItem['additional']['booking']['date_to'] . " 23:59:59"); + + $availableFrom = ! $bookingProduct->available_every_week && $bookingProduct->available_from + ? Carbon::createFromTimeString($bookingProduct->available_from) + : Carbon::createFromTimeString($currentTime->format('Y-m-d 00:00:00')); + + $availableTo = ! $bookingProduct->available_every_week && $bookingProduct->available_from + ? Carbon::createFromTimeString($bookingProduct->available_to) + : Carbon::createFromTimeString('2080-01-01 00:00:00'); + + if ($requestedFromDate < $availableFrom + || $requestedFromDate > $availableTo + || $requestedToDate < $availableFrom + || $requestedToDate > $availableTo + ) { + return true; + } + + return false; + } } /**