Issue #2669 fixed
This commit is contained in:
parent
cdc1eb7bc1
commit
d76a8d8dec
|
|
@ -3,6 +3,7 @@
|
|||
namespace Webkul\BookingProduct\Helpers;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Arr;
|
||||
use Carbon\Carbon;
|
||||
use Webkul\BookingProduct\Repositories\BookingProductRepository;
|
||||
use Webkul\BookingProduct\Repositories\BookingProductDefaultSlotRepository;
|
||||
|
|
@ -269,6 +270,13 @@ class Booking
|
|||
? $bookingProductSlot->slots
|
||||
: ($bookingProductSlot->slots[$requestedDate->format('w')] ?? []);
|
||||
|
||||
if ($requestedDate < $currentTime
|
||||
|| $requestedDate < $availableFrom
|
||||
|| $requestedDate > $availableTo
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$slots = [];
|
||||
|
||||
foreach ($timeDurations as $timeDuration) {
|
||||
|
|
@ -332,7 +340,7 @@ class Booking
|
|||
{
|
||||
$bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $cartItem['product_id']);
|
||||
|
||||
if ($bookingProduct->qty - $this->getBookedQuantity($cartItem) < $cartItem['quantity']) {
|
||||
if ($bookingProduct->qty - $this->getBookedQuantity($cartItem) < $cartItem['quantity'] || $this->isSlotExpired($cartItem)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -354,6 +362,25 @@ class Booking
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Webkul\Ceckout\Contracts\CartItem|array $cartItem
|
||||
* @return bool
|
||||
*/
|
||||
public function isSlotExpired($cartItem)
|
||||
{
|
||||
$bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $cartItem['product_id']);
|
||||
|
||||
$typeHelper = app($this->typeHelpers[$bookingProduct->type]);
|
||||
|
||||
$slots = $typeHelper->getSlotsByDate($bookingProduct, $cartItem['additional']['booking']['date']);
|
||||
|
||||
$filtered = Arr::where($slots, function ($slot, $key) use ($cartItem) {
|
||||
return $slot['timestamp'] == $cartItem['additional']['booking']['slot'];
|
||||
});
|
||||
|
||||
return count($filtered) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return int
|
||||
|
|
@ -501,7 +528,7 @@ class Booking
|
|||
* Validate cart item product price
|
||||
*
|
||||
* @param \Webkul\Checkout\Contracts\CartItem $item
|
||||
* @return float
|
||||
* @return void
|
||||
*/
|
||||
public function validateCartItem($item)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -38,6 +38,13 @@ class RentalSlot extends Booking
|
|||
? $bookingProductSlot->slots
|
||||
: $bookingProductSlot->slots[$requestedDate->format('w')];
|
||||
|
||||
if ($requestedDate < $currentTime
|
||||
|| $requestedDate < $availableFrom
|
||||
|| $requestedDate > $availableTo
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$slots = [];
|
||||
|
||||
foreach ($timeDurations as $index => $timeDuration) {
|
||||
|
|
@ -126,6 +133,33 @@ class RentalSlot extends Booking
|
|||
return ! is_null($result->total_qty_booked) ? $result->total_qty_booked : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Webkul\Ceckout\Contracts\CartItem|array $cartItem
|
||||
* @return bool
|
||||
*/
|
||||
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']);
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $isExpired;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add booking additional prices to cart item
|
||||
*
|
||||
|
|
|
|||
|
|
@ -706,7 +706,7 @@ class Cart
|
|||
return false;
|
||||
} else {
|
||||
foreach ($cart->items as $item) {
|
||||
$item->product->getTypeInstance()->validateCartItem($item);
|
||||
$response = $item->product->getTypeInstance()->validateCartItem($item);
|
||||
|
||||
$price = ! is_null($item->custom_price) ? $item->custom_price : $item->base_price;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue