From 449a2e1d4744ba1b13bdf67427db49303aaadddd Mon Sep 17 00:00:00 2001 From: Annika Wolff Date: Tue, 9 Jun 2020 08:15:17 +0200 Subject: [PATCH] add logging to exception thrown in cart --- packages/Webkul/Checkout/src/Cart.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 635764533..21059ae07 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -2,6 +2,8 @@ namespace Webkul\Checkout; +use Exception; +use Illuminate\Support\Facades\Log; use Webkul\Checkout\Models\Cart as CartModel; use Webkul\Checkout\Models\CartAddress; use Webkul\Checkout\Repositories\CartRepository; @@ -122,9 +124,11 @@ class Cart /** * Add Items in a cart with some cart and item details. * - * @param int $productId - * @param array $data - * @return \Webkul\Checkout\Contracts\Cart|\Exception|array + * @param int $productId + * @param array $data + * + * @return \Webkul\Checkout\Contracts\Cart|string|array + * @throws Exception */ public function addProduct($productId, $data) { @@ -147,7 +151,8 @@ class Cart session()->forget('cart'); } - throw new \Exception($cartProducts); + Log::error($cartProducts, ['product' => $product, 'cartData' => $data]); + throw new Exception($cartProducts); } else { $parentCartItem = null; @@ -161,7 +166,7 @@ class Cart if (! $cartItem) { $cartItem = $this->cartItemRepository->create(array_merge($cartProduct, ['cart_id' => $cart->id])); } 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, [ 'cart_id' => $cart->id ])); @@ -232,7 +237,8 @@ class Cart * Update cart items information * * @param array $data - * @return bool|void|\Exception + * + * @return bool|void|Exception */ public function updateItems($data) { @@ -246,13 +252,13 @@ class Cart if ($quantity <= 0) { $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; 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); @@ -499,7 +505,7 @@ class Cart $this->saveAddressesWhenRequested($data, $billingAddressData, $shippingAddressData); $this->linkAddresses($cart, $billingAddressData, $shippingAddressData); - + $this->assignCustomerFields($cart); $cart->save();