Fixed merge cart issue for booking product

This commit is contained in:
Jitendra Singh 2020-02-24 16:40:44 +05:30
parent 5c696f8d00
commit 95d198c1d6
5 changed files with 42 additions and 15 deletions

View File

@ -10,4 +10,13 @@ namespace Webkul\BookingProduct\Helpers;
*/
class AppointmentSlot extends Booking
{
/**
* @param integer $qty
* @param BookingProduct $bookingProduct
* @return bool
*/
public function haveSufficientQuantity($qty, $bookingProduct)
{
return true;
}
}

View File

@ -313,6 +313,16 @@ class Booking
return $slots;
}
/**
* @param integer $qty
* @param BookingProduct $bookingProduct
* @return bool
*/
public function haveSufficientQuantity($qty, $bookingProduct)
{
return true;
}
/**
* Returns additional cart item information
*

View File

@ -138,7 +138,11 @@ class RentalSlot extends Booking
$bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $item->product_id);
$rentingType = $item->additional['booking']['renting_type'] ?? $bookingProduct->rental_slot->renting_type;
try {
$rentingType = $item->additional['booking']['renting_type'] ?? $bookingProduct->rental_slot->renting_type;
} catch(\Exception $e) {
dd($item, $bookingProduct, $bookingProduct->rental_slot, 111);
}
if ($rentingType == 'daily') {
$from = Carbon::createFromTimeString($item->additional['booking']['date_from'] . " 00:00:00");

View File

@ -116,13 +116,13 @@ class Booking extends Virtual
*/
public function getBookingProduct($productId)
{
static $bookingProduct;
static $bookingProducts = [];
if ($bookingProduct) {
return $bookingProduct;
if (isset($bookingProducts[$productId])) {
return $bookingProducts[$productId];
}
return $bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $productId);
return $bookingProducts[$productId] = $this->bookingProductRepository->findOneByField('product_id', $productId);
}
/**
@ -131,7 +131,9 @@ class Booking extends Virtual
*/
public function haveSufficientQuantity($qty)
{
return true;
$bookingProduct = $this->getBookingProduct($this->product->id);
return app($this->bookingHelper->getTypeHepler($bookingProduct->type))->haveSufficientQuantity($qty, $bookingProduct);
}
/**

View File

@ -170,8 +170,9 @@ class Cart
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct, ['cart_id' => $cart->id]));
} else {
if (isset($cartProduct['parent_id']) && $cartItem->parent_id != $parentCartItem->id) {
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct,
['cart_id' => $cart->id]));
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct, [
'cart_id' => $cart->id
]));
} else {
if ($cartItem->product->getTypeInstance()->showQuantityBox() === false) {
return ['warning' => __('shop::app.checkout.cart.integrity.qty_impossible')];
@ -225,7 +226,7 @@ class Cart
$cart = $this->cartRepository->create($cartData);
if (!$cart) {
if (! $cart) {
session()->flash('error', trans('shop::app.checkout.cart.create-error'));
return;
@ -368,7 +369,6 @@ class Cart
}
foreach ($guestCart->items as $key => $guestCartItem) {
$found = false;
foreach ($cart->items as $cartItem) {
@ -378,7 +378,7 @@ class Cart
$cartItem->quantity = $newQuantity = $cartItem->quantity + $guestCartItem->quantity;
if (!$this->isItemHaveQuantity($cartItem)) {
if (! $this->isItemHaveQuantity($cartItem)) {
$this->cartItemRepository->delete($guestCartItem->id);
continue;
@ -399,7 +399,7 @@ class Cart
$found = true;
}
if (!$found) {
if (! $found) {
$this->cartItemRepository->update([
'cart_id' => $cart->id,
], $guestCartItem->id);
@ -431,7 +431,7 @@ class Cart
*/
public function putCart($cart)
{
if (!$this->getCurrentCustomer()->check()) {
if (! $this->getCurrentCustomer()->check()) {
session()->put('cart', $cart);
}
}
@ -720,7 +720,7 @@ class Cart
foreach ($cart->items as $item) {
$item->product->getTypeInstance()->validateCartItem($item);
$price = !is_null($item->custom_price) ? $item->custom_price : $item->base_price;
$price = ! is_null($item->custom_price) ? $item->custom_price : $item->base_price;
$this->cartItemRepository->update([
'price' => core()->convertPrice($price),
@ -766,6 +766,7 @@ class Cart
if ($address === null) {
$address = new class() {
public $country;
public $postcode;
function __construct()
@ -788,7 +789,8 @@ class Cart
if ($rate->state != '' && $rate->state != $address->state) {
continue;
}
if (!$rate->is_zip) {
if (! $rate->is_zip) {
if ($rate->zip_code == '*' || $rate->zip_code == $address->postcode) {
$haveTaxRate = true;
}