diff --git a/packages/Webkul/Customer/src/Http/Controllers/AddressController.php b/packages/Webkul/Customer/src/Http/Controllers/AddressController.php index cd6f9e9c2..b14677b54 100755 --- a/packages/Webkul/Customer/src/Http/Controllers/AddressController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/AddressController.php @@ -30,8 +30,6 @@ class AddressController extends Controller public function __construct(protected CustomerAddressRepository $customerAddressRepository) { $this->_config = request('_config'); - - $this->customer = auth()->guard('customer')->user(); } /** @@ -41,7 +39,9 @@ class AddressController extends Controller */ public function index() { - return view($this->_config['view'])->with('addresses', $this->customer->addresses); + $customer = auth()->guard('customer')->user(); + + return view($this->_config['view'])->with('addresses', $customer->addresses); } /** @@ -63,12 +63,14 @@ class AddressController extends Controller */ public function store(CustomerAddressRequest $request) { + $customer = auth()->guard('customer')->user(); + $data = $request->all(); - $data['customer_id'] = $this->customer->id; + $data['customer_id'] = $customer->id; $data['address1'] = implode(PHP_EOL, array_filter(request()->input('address1'))); - if ($this->customer->addresses->count() == 0) { + if ($customer->addresses->count() == 0) { $data['default_address'] = 1; } @@ -90,9 +92,11 @@ class AddressController extends Controller */ public function edit($id) { + $customer = auth()->guard('customer')->user(); + $address = $this->customerAddressRepository->findOneWhere([ 'id' => $id, - 'customer_id' => $this->customer->id, + 'customer_id' => $customer->id, ]); if (! $address) { @@ -112,11 +116,13 @@ class AddressController extends Controller */ public function update($id, CustomerAddressRequest $request) { + $customer = auth()->guard('customer')->user(); + $data = $request->all(); $data['address1'] = implode(PHP_EOL, array_filter(request()->input('address1'))); - $addresses = $this->customer->addresses; + $addresses = $customer->addresses; foreach ($addresses as $address) { if ($id == $address->id) { @@ -141,7 +147,9 @@ class AddressController extends Controller */ public function makeDefault($id) { - if ($default = $this->customer->default_address) { + $customer = auth()->guard('customer')->user(); + + if ($default = $customer->default_address) { $this->customerAddressRepository->find($default->id)->update(['default_address' => 0]); } @@ -162,9 +170,11 @@ class AddressController extends Controller */ public function destroy($id) { + $customer = auth()->guard('customer')->user(); + $address = $this->customerAddressRepository->findOneWhere([ 'id' => $id, - 'customer_id' => $this->customer->id, + 'customer_id' => $customer->id, ]); if (! $address) { diff --git a/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php b/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php index 7512f5c38..18dd8b8da 100755 --- a/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php @@ -36,8 +36,6 @@ class WishlistController extends Controller ) { $this->_config = request('_config'); - - $this->currentCustomer = auth()->guard('customer')->user(); } /** @@ -47,6 +45,8 @@ class WishlistController extends Controller */ public function index() { + $customer = auth()->guard('customer')->user(); + if (! core()->getConfigData('general.content.shop.wishlist_option')) { abort(404); } @@ -54,8 +54,8 @@ class WishlistController extends Controller return view($this->_config['view'], [ 'items' => $this->wishlistRepository->getCustomerWishlist(), 'isSharingEnabled' => $this->isSharingEnabled(), - 'isWishlistShared' => $this->currentCustomer->isWishlistShared(), - 'wishlistSharedLink' => $this->currentCustomer->getWishlistSharedLink() + 'isWishlistShared' => $customer->isWishlistShared(), + 'wishlistSharedLink' => $customer->getWishlistSharedLink() ]); } @@ -67,6 +67,8 @@ class WishlistController extends Controller */ public function add($itemId) { + $customer = auth()->guard('customer')->user(); + $product = $this->productRepository->find($itemId); if ( $product == null ) { @@ -79,13 +81,13 @@ class WishlistController extends Controller $data = [ 'channel_id' => core()->getCurrentChannel()->id, 'product_id' => $itemId, - 'customer_id' => $this->currentCustomer->id, + 'customer_id' => $customer->id, ]; $checked = $this->wishlistRepository->findWhere([ 'channel_id' => core()->getCurrentChannel()->id, 'product_id' => $itemId, - 'customer_id' => $this->currentCustomer->id, + 'customer_id' => $customer->id, ]); if ( @@ -124,20 +126,22 @@ class WishlistController extends Controller */ public function share() { + $customer = auth()->guard('customer')->user(); + if ($this->isSharingEnabled()) { $data = $this->validate(request(), [ 'shared' => 'required|boolean' ]); - $updateCounts = $this->currentCustomer->wishlist_items()->update(['shared' => $data['shared']]); + $updateCounts = $customer->wishlist_items()->update(['shared' => $data['shared']]); if ( $updateCounts && $updateCounts > 0 ) { return response()->json([ - 'isWishlistShared' => $this->currentCustomer->isWishlistShared(), - 'wishlistSharedLink' => $this->currentCustomer->getWishlistSharedLink() + 'isWishlistShared' => $customer->isWishlistShared(), + 'wishlistSharedLink' => $customer->getWishlistSharedLink() ]); } } @@ -185,7 +189,9 @@ class WishlistController extends Controller */ public function remove($itemId) { - $customerWishlistItems = $this->currentCustomer->wishlist_items; + $customer = auth()->guard('customer')->user(); + + $customerWishlistItems = $customer->wishlist_items; foreach ($customerWishlistItems as $customerWishlistItem) { if ($itemId == $customerWishlistItem->id) { @@ -210,9 +216,11 @@ class WishlistController extends Controller */ public function move($itemId) { + $customer = auth()->guard('customer')->user(); + $wishlistItem = $this->wishlistRepository->findOneWhere([ 'id' => $itemId, - 'customer_id' => $this->currentCustomer->id, + 'customer_id' => $customer->id, ]); if (! $wishlistItem) { @@ -247,7 +255,9 @@ class WishlistController extends Controller */ public function removeAll() { - $wishlistItems = $this->currentCustomer->wishlist_items; + $customer = auth()->guard('customer')->user(); + + $wishlistItems = $customer->wishlist_items; if ($wishlistItems->count() > 0) { foreach ($wishlistItems as $wishlistItem) { diff --git a/packages/Webkul/Shop/src/Http/Controllers/OrderController.php b/packages/Webkul/Shop/src/Http/Controllers/OrderController.php index 09a4b353b..e1747cfba 100644 --- a/packages/Webkul/Shop/src/Http/Controllers/OrderController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/OrderController.php @@ -23,8 +23,6 @@ class OrderController extends Controller protected InvoiceRepository $invoiceRepository ) { - $this->currentCustomer = auth()->guard('customer')->user(); - parent::__construct(); } @@ -50,8 +48,10 @@ class OrderController extends Controller */ public function view($id) { + $customer = auth()->guard('customer')->user(); + $order = $this->orderRepository->findOneWhere([ - 'customer_id' => $this->currentCustomer->id, + 'customer_id' => $customer->id, 'id' => $id, ]); @@ -70,9 +70,11 @@ class OrderController extends Controller */ public function printInvoice($id) { + $customer = auth()->guard('customer')->user(); + $invoice = $this->invoiceRepository->findOrFail($id); - if ($invoice->order->customer_id !== $this->currentCustomer->id) { + if ($invoice->order->customer_id !== $customer->id) { abort(404); } @@ -90,8 +92,10 @@ class OrderController extends Controller */ public function cancel($id) { + $customer = auth()->guard('customer')->user(); + /* find by order id in customer's order */ - $order = $this->currentCustomer->all_orders()->find($id); + $order = $customer->all_orders()->find($id); /* if order id not found then process should be aborted with 404 page */ if (! $order) { diff --git a/packages/Webkul/Ui/src/DataGrid/DataGrid.php b/packages/Webkul/Ui/src/DataGrid/DataGrid.php index e06923fd4..4e4857cdd 100644 --- a/packages/Webkul/Ui/src/DataGrid/DataGrid.php +++ b/packages/Webkul/Ui/src/DataGrid/DataGrid.php @@ -200,8 +200,6 @@ abstract class DataGrid public function __construct() { $this->invoker = $this; - - $this->currentUser = auth()->guard('admin')->user(); } /**