Bundle product add to cart issue fixed

This commit is contained in:
jitendra 2019-10-24 16:29:09 +05:30
parent ce52c1832e
commit 5f0b26f038
2 changed files with 22 additions and 4 deletions

View File

@ -158,7 +158,11 @@ class Cart {
if (! $cartItem) {
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct, ['cart_id' => $cart->id]));
} else {
$cartItem = $this->cartItemRepository->update($cartProduct, $cartItem->id);
if (isset($cartProduct['parent_id']) && $cartItem->parent_id != $parentCartItem->id) {
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct, ['cart_id' => $cart->id]));
} else {
$cartItem = $this->cartItemRepository->update($cartProduct, $cartItem->id);
}
}
if (! $parentCartItem)
@ -261,7 +265,7 @@ class Cart {
/**
* Get cart item by product
*
* @param array $data
* @param array $data
* @return CartItem|void
*/
public function getItemByProduct($data)
@ -269,8 +273,14 @@ class Cart {
$items = $this->getCart()->all_items;
foreach ($items as $item) {
if ($item->product->getTypeInstance()->compareOptions($item->additional, $data['additional']))
return $item;
if ($item->product->getTypeInstance()->compareOptions($item->additional, $data['additional'])) {
if (isset($data['additional']['parent_id'])) {
if ($item->parent->product->getTypeInstance()->compareOptions($item->parent->additional, request()->all()))
return $item;
} else {
return $item;
}
}
}
}

View File

@ -56,6 +56,14 @@ class CartItem extends Model implements CartItemContract
return $this->belongsTo(static::class, 'id', 'parent_id');
}
/**
* Get the parent item record associated with the cart item.
*/
public function parent()
{
return $this->belongsTo(self::class, 'parent_id');
}
/**
* Get the children items.
*/