add logging to exception thrown in cart
This commit is contained in:
parent
bfeff060c2
commit
449a2e1d47
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Webkul\Checkout;
|
namespace Webkul\Checkout;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Webkul\Checkout\Models\Cart as CartModel;
|
use Webkul\Checkout\Models\Cart as CartModel;
|
||||||
use Webkul\Checkout\Models\CartAddress;
|
use Webkul\Checkout\Models\CartAddress;
|
||||||
use Webkul\Checkout\Repositories\CartRepository;
|
use Webkul\Checkout\Repositories\CartRepository;
|
||||||
|
|
@ -122,9 +124,11 @@ class Cart
|
||||||
/**
|
/**
|
||||||
* Add Items in a cart with some cart and item details.
|
* Add Items in a cart with some cart and item details.
|
||||||
*
|
*
|
||||||
* @param int $productId
|
* @param int $productId
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return \Webkul\Checkout\Contracts\Cart|\Exception|array
|
*
|
||||||
|
* @return \Webkul\Checkout\Contracts\Cart|string|array
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function addProduct($productId, $data)
|
public function addProduct($productId, $data)
|
||||||
{
|
{
|
||||||
|
|
@ -147,7 +151,8 @@ class Cart
|
||||||
session()->forget('cart');
|
session()->forget('cart');
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \Exception($cartProducts);
|
Log::error($cartProducts, ['product' => $product, 'cartData' => $data]);
|
||||||
|
throw new Exception($cartProducts);
|
||||||
} else {
|
} else {
|
||||||
$parentCartItem = null;
|
$parentCartItem = null;
|
||||||
|
|
||||||
|
|
@ -161,7 +166,7 @@ class Cart
|
||||||
if (! $cartItem) {
|
if (! $cartItem) {
|
||||||
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct, ['cart_id' => $cart->id]));
|
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct, ['cart_id' => $cart->id]));
|
||||||
} else {
|
} else {
|
||||||
if (isset($cartProduct['parent_id']) && $cartItem->parent_id != $parentCartItem->id) {
|
if (isset($cartProduct['parent_id']) && $cartItem->parent_id !== $parentCartItem->id) {
|
||||||
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct, [
|
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct, [
|
||||||
'cart_id' => $cart->id
|
'cart_id' => $cart->id
|
||||||
]));
|
]));
|
||||||
|
|
@ -232,7 +237,8 @@ class Cart
|
||||||
* Update cart items information
|
* Update cart items information
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return bool|void|\Exception
|
*
|
||||||
|
* @return bool|void|Exception
|
||||||
*/
|
*/
|
||||||
public function updateItems($data)
|
public function updateItems($data)
|
||||||
{
|
{
|
||||||
|
|
@ -246,13 +252,13 @@ class Cart
|
||||||
if ($quantity <= 0) {
|
if ($quantity <= 0) {
|
||||||
$this->removeItem($itemId);
|
$this->removeItem($itemId);
|
||||||
|
|
||||||
throw new \Exception(trans('shop::app.checkout.cart.quantity.illegal'));
|
throw new Exception(trans('shop::app.checkout.cart.quantity.illegal'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$item->quantity = $quantity;
|
$item->quantity = $quantity;
|
||||||
|
|
||||||
if (! $this->isItemHaveQuantity($item)) {
|
if (! $this->isItemHaveQuantity($item)) {
|
||||||
throw new \Exception(trans('shop::app.checkout.cart.quantity.inventory_warning'));
|
throw new Exception(trans('shop::app.checkout.cart.quantity.inventory_warning'));
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::dispatch('checkout.cart.update.before', $item);
|
Event::dispatch('checkout.cart.update.before', $item);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue