add logging of catched exception
This commit is contained in:
parent
a32925f6ce
commit
dbc16cf7e6
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Webkul\Checkout\Repositories\CartRepository;
|
||||
use Webkul\Checkout\Repositories\CartItemRepository;
|
||||
use Webkul\API\Http\Resources\Checkout\Cart as CartResource;
|
||||
|
|
@ -69,7 +72,7 @@ class CartController extends Controller
|
|||
/**
|
||||
* Get customer cart
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
|
|
@ -87,9 +90,10 @@ class CartController extends Controller
|
|||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store($id)
|
||||
public function store($id): ?JsonResponse
|
||||
{
|
||||
if (request()->get('is_buy_now')) {
|
||||
Event::dispatch('shop.item.buy-now', $id);
|
||||
|
|
@ -97,13 +101,12 @@ class CartController extends Controller
|
|||
|
||||
Event::dispatch('checkout.cart.item.add.before', $id);
|
||||
|
||||
try {
|
||||
$result = Cart::addProduct($id, request()->except('_token'));
|
||||
|
||||
if (! $result) {
|
||||
$message = session()->get('warning') ?? session()->get('error');
|
||||
|
||||
if (is_array($result) && isset($result['warning'])) {
|
||||
return response()->json([
|
||||
'error' => session()->get('warning'),
|
||||
'error' => $result['warning'],
|
||||
], 400);
|
||||
}
|
||||
|
||||
|
|
@ -121,12 +124,23 @@ class CartController extends Controller
|
|||
'message' => __('shop::app.checkout.cart.item.success'),
|
||||
'data' => $cart ? new CartResource($cart) : null,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
Log::error('API CartController: ' . $e->getMessage(),
|
||||
['productID' => $id, 'cartID' => cart()->getCart() ?? 0]);
|
||||
|
||||
return response()->json([
|
||||
'error' => [
|
||||
'message' => $e->getMessage(),
|
||||
'code' => $e->getCode()
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
|
|
@ -161,7 +175,7 @@ class CartController extends Controller
|
|||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
|
|
@ -183,7 +197,8 @@ class CartController extends Controller
|
|||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function destroyItem($id)
|
||||
{
|
||||
|
|
@ -207,6 +222,8 @@ class CartController extends Controller
|
|||
* Function to move a already added product to wishlist will run only on customer authentication.
|
||||
*
|
||||
* @param \Webkul\Checkout\Repositories\CartItemRepository $id
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function moveToWishlist($id)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -151,7 +151,6 @@ class Cart
|
|||
session()->forget('cart');
|
||||
}
|
||||
|
||||
Log::error($cartProducts, ['product' => $product, 'cartData' => $data]);
|
||||
throw new Exception($cartProducts);
|
||||
} else {
|
||||
$parentCartItem = null;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Webkul\Shop\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Webkul\Customer\Repositories\WishlistRepository;
|
||||
use Webkul\Product\Repositories\ProductRepository;
|
||||
use Webkul\Checkout\Contracts\Cart as CartModel;
|
||||
|
|
@ -75,7 +76,7 @@ class CartController extends Controller
|
|||
}
|
||||
|
||||
if ($result instanceof CartModel) {
|
||||
session()->flash('success', trans('shop::app.checkout.cart.item.success'));
|
||||
session()->flash('success', __('shop::app.checkout.cart.item.success'));
|
||||
|
||||
if ($customer = auth()->guard('customer')->user()) {
|
||||
$this->wishlistRepository->deleteWhere(['product_id' => $id, 'customer_id' => $customer->id]);
|
||||
|
|
@ -88,10 +89,12 @@ class CartController extends Controller
|
|||
}
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
session()->flash('error', trans($e->getMessage()));
|
||||
session()->flash('error', __($e->getMessage()));
|
||||
|
||||
$product = $this->productRepository->find($id);
|
||||
|
||||
Log::error('Shop CartController: ' . $e->getMessage(), ['productID' => $id, 'cartID' => cart()->getCart() ?? 0]);
|
||||
|
||||
return redirect()->route('shop.productOrCategory.index', $product->url_key);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Webkul\Velocity\Http\Controllers\Shop;
|
||||
|
||||
use Cart;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Webkul\Velocity\Helpers\Helper;
|
||||
use Webkul\Checkout\Contracts\Cart as CartModel;
|
||||
use Webkul\Product\Repositories\ProductRepository;
|
||||
|
|
@ -93,16 +94,18 @@ class CartController extends Controller
|
|||
} catch(\Exception $exception) {
|
||||
$product = $this->productRepository->find($id);
|
||||
|
||||
Log::error('Velocity CartController: ' . $exception->getMessage(), ['productID' => $id, 'cartID' => cart()->getCart() ?? 0]);
|
||||
|
||||
$response = [
|
||||
'status' => 'danger',
|
||||
'message' => trans($exception->getMessage()),
|
||||
'message' => __($exception->getMessage()),
|
||||
'redirectionRoute' => route('shop.productOrCategory.index', $product->url_key),
|
||||
];
|
||||
}
|
||||
|
||||
return $response ?? [
|
||||
'status' => 'danger',
|
||||
'message' => trans('velocity::app.error.something_went_wrong'),
|
||||
'message' => __('velocity::app.error.something_went_wrong'),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue