Issue #2677 fixed
This commit is contained in:
parent
d76a8d8dec
commit
17abfdb1d6
|
|
@ -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']);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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([
|
||||
|
|
|
|||
Loading…
Reference in New Issue