From 9e7e9394792bd3886d79cc13b2633e498da09970 Mon Sep 17 00:00:00 2001 From: Jitendra Singh Date: Wed, 19 Feb 2020 19:18:54 +0530 Subject: [PATCH] Improved customer package code style --- packages/Webkul/Customer/src/Helpers/Wishlist.php | 7 ++++--- .../src/Http/Controllers/AddressController.php | 6 ++++-- .../Http/Controllers/ResetPasswordController.php | 4 ++-- .../src/Http/Controllers/SessionController.php | 2 +- .../src/Http/Controllers/WishlistController.php | 13 +++++++------ .../Webkul/Customer/src/Models/CustomerAddress.php | 6 +++--- .../src/Notifications/CustomerResetPassword.php | 2 +- .../src/Repositories/CustomerAddressRepository.php | 1 + .../src/Repositories/WishlistRepository.php | 2 +- packages/Webkul/Customer/src/Rules/VatValidator.php | 2 ++ 10 files changed, 26 insertions(+), 19 deletions(-) diff --git a/packages/Webkul/Customer/src/Helpers/Wishlist.php b/packages/Webkul/Customer/src/Helpers/Wishlist.php index 5bf4d348f..e96d1db7f 100644 --- a/packages/Webkul/Customer/src/Helpers/Wishlist.php +++ b/packages/Webkul/Customer/src/Helpers/Wishlist.php @@ -36,14 +36,15 @@ class Wishlist if (auth()->guard('customer')->user()) { $wishlist = $this->wishlistRepository->findOneWhere([ - 'channel_id' => core()->getCurrentChannel()->id, - 'product_id' => $product->product_id, + 'channel_id' => core()->getCurrentChannel()->id, + 'product_id' => $product->product_id, 'customer_id' => auth()->guard('customer')->user()->id ]); } - if ($wishlist) + if ($wishlist) { return true; + } return false; } diff --git a/packages/Webkul/Customer/src/Http/Controllers/AddressController.php b/packages/Webkul/Customer/src/Http/Controllers/AddressController.php index bbc4f09dc..c63d5e4f4 100755 --- a/packages/Webkul/Customer/src/Http/Controllers/AddressController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/AddressController.php @@ -182,8 +182,9 @@ class AddressController extends Controller */ public function makeDefault($id) { - if ($default = $this->customer->default_address) + if ($default = $this->customer->default_address) { $this->customerAddressRepository->find($default->id)->update(['default_address' => 0]); + } if ($address = $this->customerAddressRepository->find($id)) { $address->update(['default_address' => 1]); @@ -208,8 +209,9 @@ class AddressController extends Controller 'customer_id' => auth()->guard('customer')->user()->id, ]); - if (! $address) + if (! $address) { abort(404); + } $this->customerAddressRepository->delete($id); diff --git a/packages/Webkul/Customer/src/Http/Controllers/ResetPasswordController.php b/packages/Webkul/Customer/src/Http/Controllers/ResetPasswordController.php index 2f6c07869..d6fc3b00d 100755 --- a/packages/Webkul/Customer/src/Http/Controllers/ResetPasswordController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/ResetPasswordController.php @@ -59,8 +59,8 @@ class ResetPasswordController extends Controller { try { $this->validate(request(), [ - 'token' => 'required', - 'email' => 'required|email', + 'token' => 'required', + 'email' => 'required|email', 'password' => 'required|confirmed|min:6', ]); diff --git a/packages/Webkul/Customer/src/Http/Controllers/SessionController.php b/packages/Webkul/Customer/src/Http/Controllers/SessionController.php index 05f43a5ff..4036000b8 100755 --- a/packages/Webkul/Customer/src/Http/Controllers/SessionController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/SessionController.php @@ -54,7 +54,7 @@ class SessionController extends Controller public function create() { $this->validate(request(), [ - 'email' => 'required|email', + 'email' => 'required|email', 'password' => 'required' ]); diff --git a/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php b/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php index 48f0e543f..592e49dc4 100755 --- a/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php @@ -82,14 +82,14 @@ class WishlistController extends Controller return redirect()->back(); $data = [ - 'channel_id' => core()->getCurrentChannel()->id, - 'product_id' => $itemId, + 'channel_id' => core()->getCurrentChannel()->id, + 'product_id' => $itemId, 'customer_id' => auth()->guard('customer')->user()->id ]; $checked = $this->wishlistRepository->findWhere([ - 'channel_id' => core()->getCurrentChannel()->id, - 'product_id' => $itemId, + 'channel_id' => core()->getCurrentChannel()->id, + 'product_id' => $itemId, 'customer_id' => auth()->guard('customer')->user()->id ]); @@ -152,12 +152,13 @@ class WishlistController extends Controller public function move($itemId) { $wishlistItem = $this->wishlistRepository->findOneWhere([ - 'id' => $itemId, + 'id' => $itemId, 'customer_id' => auth()->guard('customer')->user()->id ]); - if (! $wishlistItem) + if (! $wishlistItem) { abort(404); + } try { $result = Cart::moveToCart($wishlistItem); diff --git a/packages/Webkul/Customer/src/Models/CustomerAddress.php b/packages/Webkul/Customer/src/Models/CustomerAddress.php index b1f49e447..389857a53 100755 --- a/packages/Webkul/Customer/src/Models/CustomerAddress.php +++ b/packages/Webkul/Customer/src/Models/CustomerAddress.php @@ -20,9 +20,9 @@ class CustomerAddress extends Model implements CustomerAddressContract 'city', 'postcode', 'phone', - 'default_address', - 'first_name', - 'last_name', + 'default_address', + 'first_name', + 'last_name', ]; /** diff --git a/packages/Webkul/Customer/src/Notifications/CustomerResetPassword.php b/packages/Webkul/Customer/src/Notifications/CustomerResetPassword.php index 07a7e6d3a..d3a85feca 100755 --- a/packages/Webkul/Customer/src/Notifications/CustomerResetPassword.php +++ b/packages/Webkul/Customer/src/Notifications/CustomerResetPassword.php @@ -24,7 +24,7 @@ class CustomerResetPassword extends ResetPassword ->subject(__('shop::app.mail.forget-password.subject') ) ->view('shop::emails.customer.forget-password', [ 'user_name' => $notifiable->name, - 'token' => $this->token + 'token' => $this->token ]); } } diff --git a/packages/Webkul/Customer/src/Repositories/CustomerAddressRepository.php b/packages/Webkul/Customer/src/Repositories/CustomerAddressRepository.php index 30798eeef..6fd6f81ad 100755 --- a/packages/Webkul/Customer/src/Repositories/CustomerAddressRepository.php +++ b/packages/Webkul/Customer/src/Repositories/CustomerAddressRepository.php @@ -72,6 +72,7 @@ class CustomerAddressRepository extends Repository if ($default_address->id != $address->id) { $default_address->update(['default_address' => 0]); } + $address->update($data); } else { $address->update($data); diff --git a/packages/Webkul/Customer/src/Repositories/WishlistRepository.php b/packages/Webkul/Customer/src/Repositories/WishlistRepository.php index a491d3828..08ae3347b 100755 --- a/packages/Webkul/Customer/src/Repositories/WishlistRepository.php +++ b/packages/Webkul/Customer/src/Repositories/WishlistRepository.php @@ -69,7 +69,7 @@ class WishlistRepository extends Repository */ public function getCustomerWhishlist() { return $this->model->where([ - 'channel_id' => core()->getCurrentChannel()->id, + 'channel_id' => core()->getCurrentChannel()->id, 'customer_id' => auth()->guard('customer')->user()->id ])->paginate(5); } diff --git a/packages/Webkul/Customer/src/Rules/VatValidator.php b/packages/Webkul/Customer/src/Rules/VatValidator.php index 12e4370fa..816e10df3 100644 --- a/packages/Webkul/Customer/src/Rules/VatValidator.php +++ b/packages/Webkul/Customer/src/Rules/VatValidator.php @@ -64,6 +64,7 @@ class VatValidator public function validate(string $vatNumber): bool { $vatNumber = $this->vatCleaner($vatNumber); + list($country, $number) = $this->splitVat($vatNumber); if (! isset(self::$pattern_expression[$country])) { @@ -81,6 +82,7 @@ class VatValidator private function vatCleaner(string $vatNumber): string { $vatNumber_no_spaces = trim($vatNumber); + return strtoupper($vatNumber_no_spaces); }