diff --git a/packages/Webkul/Shop/src/Http/Controllers/CartController.php b/packages/Webkul/Shop/src/Http/Controllers/CartController.php index a996d2fe8..ac88f9e0d 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/CartController.php @@ -2,24 +2,24 @@ namespace Webkul\Shop\Http\Controllers; +use Cart; +use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Log; +use Webkul\Checkout\Contracts\Cart as CartModel; use Webkul\Customer\Repositories\WishlistRepository; use Webkul\Product\Repositories\ProductRepository; -use Webkul\Checkout\Contracts\Cart as CartModel; -use Illuminate\Support\Facades\Event; -use Cart; class CartController extends Controller { /** - * WishlistRepository Repository object + * Wishlist repository instance. * * @var \Webkul\Customer\Repositories\WishlistRepository */ protected $wishlistRepository; /** - * ProductRepository object + * Product repository instance. * * @var \Webkul\Product\Repositories\ProductRepository */ @@ -35,9 +35,10 @@ class CartController extends Controller public function __construct( WishlistRepository $wishlistRepository, ProductRepository $productRepository - ) - { - $this->middleware('customer')->only(['moveToWishlist']); + ) { + $this->middleware('throttle:5,1')->only('applyCoupon'); + + $this->middleware('customer')->only('moveToWishlist'); $this->wishlistRepository = $wishlistRepository; @@ -86,13 +87,15 @@ class CartController extends Controller return redirect()->route('shop.checkout.onepage.index'); } } - } catch(\Exception $e) { + } catch (\Exception $e) { session()->flash('warning', __($e->getMessage())); $product = $this->productRepository->find($id); - Log::error('Shop CartController: ' . $e->getMessage(), - ['product_id' => $id, 'cart_id' => cart()->getCart() ?? 0]); + Log::error( + 'Shop CartController: ' . $e->getMessage(), + ['product_id' => $id, 'cart_id' => cart()->getCart() ?? 0] + ); return redirect()->route('shop.productOrCategory.index', $product->url_key); } @@ -101,7 +104,7 @@ class CartController extends Controller } /** - * Removes the item from the cart if it exists + * Removes the item from the cart if it exists. * * @param int $itemId * @return \Illuminate\Http\Response @@ -130,7 +133,7 @@ class CartController extends Controller if ($result) { session()->flash('success', trans('shop::app.checkout.cart.quantity.success')); } - } catch(\Exception $e) { + } catch (\Exception $e) { session()->flash('error', trans($e->getMessage())); } @@ -159,10 +162,10 @@ class CartController extends Controller } /** - * Apply coupon to the cart + * Apply coupon to the cart. * * @return \Illuminate\Http\Response - */ + */ public function applyCoupon() { $couponCode = request()->get('code'); @@ -194,10 +197,10 @@ class CartController extends Controller } /** - * Apply coupon to the cart + * Remove applied coupon from the cart. * * @return \Illuminate\Http\Response - */ + */ public function removeCoupon() { Cart::removeCouponCode()->collectTotals(); @@ -210,10 +213,9 @@ class CartController extends Controller /** * Returns true, if result of adding product to cart - * is an array and contains a key "warning" or "info" + * is an array and contains a key "warning" or "info". * * @param array $result - * * @return boolean */ private function onFailureAddingToCart($result): bool