This commit is contained in:
Jitendra Singh 2020-03-18 13:24:12 +05:30
parent d76a8d8dec
commit 17abfdb1d6
3 changed files with 24 additions and 3 deletions

View File

@ -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']);

View File

@ -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);
}
}

View File

@ -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([