diff --git a/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php b/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php index d2a125e79..3919ef428 100644 --- a/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php +++ b/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php @@ -4,6 +4,7 @@ namespace Webkul\BookingProduct\Helpers; use Illuminate\Support\Facades\DB; use Carbon\Carbon; +use Webkul\Checkout\Facades\Cart; class RentalSlot extends Booking { @@ -196,7 +197,7 @@ class RentalSlot extends Booking * Validate cart item product price * * @param \Webkul\Checkout\Contracts\CartItem $item - * @return float + * @return void|null */ public function validateCartItem($item) { @@ -207,11 +208,27 @@ class RentalSlot extends Booking $rentingType = $item->additional['booking']['renting_type'] ?? $bookingProduct->rental_slot->renting_type; if ($rentingType == 'daily') { + if (! isset($item->additional['booking']['date_from']) + || ! isset($item->additional['booking']['date_to']) + ) { + Cart::removeItem($item->id); + + return true; + } + $from = Carbon::createFromTimeString($item->additional['booking']['date_from'] . " 00:00:00"); $to = Carbon::createFromTimeString($item->additional['booking']['date_to'] . " 24:00:00"); $price += $bookingProduct->rental_slot->daily_price * $to->diffInDays($from); } else { + if (! isset($item->additional['booking']['slot']['from']) + || ! isset($item->additional['booking']['slot']['to']) + ) { + Cart::removeItem($item->id); + + return true; + } + $from = Carbon::createFromTimestamp($item->additional['booking']['slot']['from']); $to = Carbon::createFromTimestamp($item->additional['booking']['slot']['to']); diff --git a/packages/Webkul/BookingProduct/src/Type/Booking.php b/packages/Webkul/BookingProduct/src/Type/Booking.php index ba0ad2fe3..7b112062a 100644 --- a/packages/Webkul/BookingProduct/src/Type/Booking.php +++ b/packages/Webkul/BookingProduct/src/Type/Booking.php @@ -243,6 +243,6 @@ class Booking extends Virtual return; } - app($this->bookingHelper->getTypeHepler($bookingProduct->type))->validateCartItem($item); + return app($this->bookingHelper->getTypeHepler($bookingProduct->type))->validateCartItem($item); } } \ No newline at end of file diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 717ee7d4b..48d54672e 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -298,7 +298,7 @@ class Cart * Remove the item from the cart * * @param int $itemId - * @return bool + * @return boolean */ public function removeItem($itemId) { @@ -708,6 +708,10 @@ class Cart foreach ($cart->items as $item) { $response = $item->product->getTypeInstance()->validateCartItem($item); + if ($response) { + return; + } + $price = ! is_null($item->custom_price) ? $item->custom_price : $item->base_price; $this->cartItemRepository->update([