Merge branch 'master' of https://github.com/bagisto/bagisto into velocity-updated
This commit is contained in:
commit
e96c6011e0
|
|
@ -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
|
||||
*
|
||||
|
|
@ -176,7 +210,7 @@ class RentalSlot extends Booking
|
|||
$from = Carbon::createFromTimeString($item->additional['booking']['date_from'] . " 00:00:00");
|
||||
$to = Carbon::createFromTimeString($item->additional['booking']['date_to'] . " 24:00:00");
|
||||
|
||||
$price += $item->product->getTypeInstance()->getFinalPrice() + $bookingProduct->rental_slot->daily_price * $to->diffInDays($from);
|
||||
$price += $bookingProduct->rental_slot->daily_price * $to->diffInDays($from);
|
||||
} else {
|
||||
$from = Carbon::createFromTimestamp($item->additional['booking']['slot']['from']);
|
||||
$to = Carbon::createFromTimestamp($item->additional['booking']['slot']['to']);
|
||||
|
|
|
|||
|
|
@ -209,7 +209,13 @@ class Booking extends Virtual
|
|||
return false;
|
||||
}
|
||||
|
||||
return $options1['booking'] == $options2['booking'];
|
||||
if (isset($options1['booking']) && isset($options2['booking'])) {
|
||||
return $options1['booking'] === $options2['booking'];
|
||||
} elseif (! isset($options1['booking'])) {
|
||||
return false;
|
||||
} elseif (! isset($options2['booking'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -1039,7 +1039,7 @@ class Cart
|
|||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
if (! $found) {
|
||||
$this->wishlistRepository->create([
|
||||
'channel_id' => $cart->channel_id,
|
||||
'customer_id' => $this->getCurrentCustomer()->user()->id,
|
||||
|
|
|
|||
|
|
@ -496,8 +496,14 @@ class Bundle extends AbstractType
|
|||
return false;
|
||||
}
|
||||
|
||||
return $options1['bundle_options'] == $options2['bundle_options']
|
||||
&& $options1['bundle_option_qty'] == $this->getOptionQuantities($options2);
|
||||
if (isset($options1['bundle_options']) && isset($options2['bundle_options'])) {
|
||||
return $options1['bundle_options'] == $options2['bundle_options']
|
||||
&& $options1['bundle_option_qty'] == $this->getOptionQuantities($options2);
|
||||
} elseif (! isset($options1['bundle_options'])) {
|
||||
return false;
|
||||
} elseif (! isset($options2['bundle_options'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -460,7 +460,13 @@ class Configurable extends AbstractType
|
|||
return false;
|
||||
}
|
||||
|
||||
return $options1['selected_configurable_option'] === $options2['selected_configurable_option'];
|
||||
if (isset($options1['selected_configurable_option']) && isset($options2['selected_configurable_option'])) {
|
||||
return $options1['selected_configurable_option'] === $options2['selected_configurable_option'];
|
||||
} elseif (! isset($options1['selected_configurable_option'])) {
|
||||
return false;
|
||||
} elseif (! isset($options2['selected_configurable_option'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -188,7 +188,13 @@ class Downloadable extends AbstractType
|
|||
return false;
|
||||
}
|
||||
|
||||
return $options1['links'] == $options2['links'];
|
||||
if (isset($options1['links']) && isset($options2['links'])) {
|
||||
return $options1['links'] === $options2['links'];
|
||||
} elseif (! isset($options1['links'])) {
|
||||
return false;
|
||||
} elseif (! isset($options2['links'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ class CartController extends Controller
|
|||
|
||||
if ($this->onWarningAddingToCart($result)) {
|
||||
session()->flash('warning', $result['warning']);
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
|
@ -82,6 +83,7 @@ class CartController extends Controller
|
|||
|
||||
if (request()->get('is_buy_now')) {
|
||||
Event::dispatch('shop.item.buy-now', $id);
|
||||
|
||||
return redirect()->route('shop.checkout.onepage.index');
|
||||
}
|
||||
}
|
||||
|
|
@ -205,10 +207,11 @@ class CartController extends Controller
|
|||
/**
|
||||
* Returns true, if result of adding product to cart is an array and contains a key "warning"
|
||||
*
|
||||
* @param array $result
|
||||
* @return bool
|
||||
* @param array $result
|
||||
* @return boolean
|
||||
*/
|
||||
private function onWarningAddingToCart($result): bool {
|
||||
private function onWarningAddingToCart($result): bool
|
||||
{
|
||||
return is_array($result) && isset($result['warning']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue