From 94234218d6061ef2d63fa56309676a8e22c901c4 Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Wed, 20 Apr 2022 00:16:16 +0200 Subject: [PATCH] Filters collapsed, customer auth and register, fix on basket recalculation --- app/Http/Controllers/Auth/LoginController.php | 2 +- .../Controllers/Shop/Auth/LoginController.php | 43 ++------- .../Shop/Auth/RegisterController.php | 89 ++----------------- .../Shop/Auth/ResetPasswordController.php | 21 ----- .../Controllers/Shop/CategoryController.php | 6 +- app/Models/Core/Auth/User.php | 19 +--- app/Models/Shop/Article.php | 15 ++++ app/Models/Shop/Customer.php | 10 ++- app/Repositories/Core/User/ShopCart.php | 21 ++++- app/Repositories/Shop/Articles.php | 2 +- app/Repositories/Shop/Offers.php | 3 +- app/Repositories/Shop/TagGroups.php | 2 +- build/css/site.css | 17 ++++ composer.json | 1 - config/auth.php | 16 ++++ .../Shop/Articles/partials/article.blade.php | 16 ++-- .../Articles/partials/article_rows.blade.php | 49 ++++++---- resources/views/Shop/Baskets/basket.blade.php | 7 +- .../Shop/Baskets/partials/article.blade.php | 2 +- .../Baskets/partials/modalBasket.blade.php | 2 +- .../partials/sliderByShelve.blade.php | 26 +++--- .../views/Shop/Tags/partials/filter.blade.php | 28 +++--- resources/views/Shop/auth/login.blade.php | 29 +++--- resources/views/Shop/auth/register.blade.php | 5 +- resources/views/Shop/home.blade.php | 2 +- resources/views/Shop/layout/layout.blade.php | 2 +- .../layout/partials/category_add.blade.php | 18 ++-- .../layout/partials/header-profile.blade.php | 2 +- .../components/layout/box-collapse.blade.php | 10 ++- routes/Shop/Categories.php | 2 +- routes/Shop/route.php | 2 + 31 files changed, 218 insertions(+), 251 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index c4597183..e8ef22af 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -20,7 +20,7 @@ class LoginController extends Controller public function showLoginForm() { - return view('Shop.auth.login', $data); + return view('Shop.auth.login', $data ?? []); } public function authenticated(Request $request, $user) diff --git a/app/Http/Controllers/Shop/Auth/LoginController.php b/app/Http/Controllers/Shop/Auth/LoginController.php index e90d5d9b..73d34da5 100644 --- a/app/Http/Controllers/Shop/Auth/LoginController.php +++ b/app/Http/Controllers/Shop/Auth/LoginController.php @@ -7,64 +7,39 @@ use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Support\Facades\Auth; use Illuminate\Http\Request; -use App\Repositories\Layout; -use App\Repositories\Languages; -use App\Repositories\Shop\Customers; - class LoginController extends Controller { - /* - |-------------------------------------------------------------------------- - | Login Controller - |-------------------------------------------------------------------------- - | - | This controller handles authenticating users for the application and - | redirecting them to your home screen. The controller uses a trait - | to conveniently provide its functionality to your applications. - | - */ - use AuthenticatesUsers; - /** - * Where to redirect users after login. - * - * @var string - */ protected $redirectTo = '/'; - /** - * Create a new controller instance. - * - * @return void - */ public function __construct() { // $this->middleware('guest')->except('logout'); } + protected function guard() + { + return Auth::guard('customer'); + } + public function showLoginForm() { $data['url'] = route('Shop.login.post'); return view('Shop.auth.login', $data); } - protected function guard() - { - return Auth::guard('guest'); - } - public function login(Request $request) { $this->validate($request, [ - 'username' => 'required|email', - 'password' => 'required|min:8' + 'email' => 'required|email', + 'password' => 'required|min:8', ]); - if (Auth::guard('guest')->attempt(['username' => $request->username, 'password' => $request->password], $request->get('remember'))) { + if (Auth::guard('customer')->attempt(['email' => $request->email, 'password' => $request->password], $request->get('remember'))) { return redirect()->intended(route('home')); } - return back()->withInput($request->only('username', 'remember')); + return back()->withInput($request->only('email', 'remember')); } public function logout(Request $request) diff --git a/app/Http/Controllers/Shop/Auth/RegisterController.php b/app/Http/Controllers/Shop/Auth/RegisterController.php index 4bd5a0bd..dafc9f4b 100644 --- a/app/Http/Controllers/Shop/Auth/RegisterController.php +++ b/app/Http/Controllers/Shop/Auth/RegisterController.php @@ -16,114 +16,52 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; use Sebastienheyd\Boilerplate\Rules\Password; +use App\Models\Shop\Customer; + class RegisterController extends Controller { use RegistersUsers; - /** - * Where to redirect users after registration. - * - * @var string - */ protected $redirectTo; - /** - * Is registering the first user ? - * - * @var bool - */ - protected $firstUser; - - /** - * Create a new controller instance. - */ - public function __construct() + protected function guard() { - $userModel = config('auth.providers.users.model'); - $this->firstUser = $userModel::whereRoleIs('admin')->count() === 0; + return Auth::guard('customer'); } - /** - * Return route where to redirect after login success. - * - * @return string - */ protected function redirectTo() { return route(config('boilerplate.app.redirectTo', 'boilerplate.dashboard')); } - /** - * Get a validator for an incoming registration request. - * - * @param array $data - * @return \Illuminate\Contracts\Validation\Validator - */ protected function validator(array $data) { return Validator::make($data, [ 'last_name' => 'required|max:255', 'first_name' => 'required|max:255', - 'email' => 'required|email|max:255|unique:users,email,NULL,id,deleted_at,NULL', + 'email' => 'required|email|max:255|unique:shop_customers,email,NULL,id,deleted_at,NULL', 'password' => ['required', 'confirmed', new Password()], ]); } - /** - * Show the application registration form. - * - * @return Application|Factory|View - */ public function showRegistrationForm() { - if (! $this->firstUser && ! config('boilerplate.auth.register')) { - abort('404'); - } - - return view('boilerplate::auth.register', ['firstUser' => $this->firstUser]); + return view('Shop.auth.register'); } - /** - * Create a new user instance after a valid registration. - * - * @param array $data - * @return mixed - */ protected function create(array $data) { - if (! $this->firstUser && ! config('boilerplate.auth.register')) { - abort('404'); - } - - $userModel = config('auth.providers.users.model'); - $roleModel = config('laratrust.models.role'); - - $user = $userModel::withTrashed()->updateOrCreate(['email' => $data['email']], [ + $user = Customer::withTrashed()->updateOrCreate(['email' => $data['email']], [ 'active' => true, 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), - 'last_login' => Carbon::now()->toDateTimeString(), ]); - if ($this->firstUser) { - $admin = $roleModel::whereName('admin')->first(); - $user->attachRole($admin); - } else { - $user->restore(); - $role = $roleModel::whereName(config('boilerplate.auth.register_role'))->first(); - $user->roles()->sync([$role->id]); - } - return $user; } - /** - * Show message to verify e-mail. - * - * @return Application|Factory|View - */ public function emailVerify() { if (Auth::user()->hasVerifiedEmail()) { @@ -133,25 +71,12 @@ class RegisterController extends Controller return view('boilerplate::auth.verify-email'); } - /** - * If e-mail has been verified, redirect to the given route. - * - * @param EmailVerificationRequest $request - * @return Application|RedirectResponse|Redirector - */ public function emailVerifyRequest(EmailVerificationRequest $request) { $request->fulfill(); - return redirect(route(config('boilerplate.app.redirectTo', 'boilerplate.dashboard'))); } - /** - * Send verification e-mail. - * - * @param Request $request - * @return RedirectResponse - */ public function emailSendVerification(Request $request) { $request->user()->sendEmailVerificationNotification(); diff --git a/app/Http/Controllers/Shop/Auth/ResetPasswordController.php b/app/Http/Controllers/Shop/Auth/ResetPasswordController.php index 533a51ce..e43179b8 100644 --- a/app/Http/Controllers/Shop/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Shop/Auth/ResetPasswordController.php @@ -8,31 +8,10 @@ use Illuminate\Foundation\Auth\ResetsPasswords; class ResetPasswordController extends Controller { - /* - |-------------------------------------------------------------------------- - | Password Reset Controller - |-------------------------------------------------------------------------- - | - | This controller is responsible for handling password reset requests - | and uses a simple trait to include this behavior. You're free to - | explore this trait and override any methods you wish to tweak. - | - */ - use ResetsPasswords; - /** - * Where to redirect users after resetting their password. - * - * @var string - */ protected $redirectTo = '/'; - /** - * Create a new controller instance. - * - * @return void - */ public function __construct() { $this->middleware('guest'); diff --git a/app/Http/Controllers/Shop/CategoryController.php b/app/Http/Controllers/Shop/CategoryController.php index b9a59f33..f9609b0f 100644 --- a/app/Http/Controllers/Shop/CategoryController.php +++ b/app/Http/Controllers/Shop/CategoryController.php @@ -18,12 +18,14 @@ class CategoryController extends Controller return $dataTable->render('Shop.Categories.list'); } - public function show(Request $request, $category_id) + public function show($category_id, $by_rows = false) { $data = self::init(); - $data['display_by_rows'] = $request->input('by_rows') ?? false; + $data['display_by_rows'] = $by_rows; $data['category'] = Categories::getFull($category_id); $data['articles'] = Articles::getArticlesToSell(['category_id' => $category_id]); + // dump($data['articles']); + // exit; $data['tags'] = TagGroups::getWithTagsAndCountOffers(); return view('Shop.shelve', $data); } diff --git a/app/Models/Core/Auth/User.php b/app/Models/Core/Auth/User.php index 1ad956d0..0c254db1 100644 --- a/app/Models/Core/Auth/User.php +++ b/app/Models/Core/Auth/User.php @@ -6,29 +6,16 @@ use Carbon\Carbon; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\SoftDeletes; use Yadahan\AuthenticationLog\AuthenticationLogable; -use HighIdeas\UsersOnline\Traits\UsersOnlineTrait; +// use HighIdeas\UsersOnline\Traits\UsersOnlineTrait; use Sebastienheyd\Boilerplate\Models\User as parentUser; class User extends parentUser { - // use UserHasTeams; - use AuthenticationLogable, SoftDeletes, UsersOnlineTrait; + // use UserHasTeams, UsersOnlineTrait; + use AuthenticationLogable, SoftDeletes; - /** - * The attributes that are mass assignable. - * - * @var array - */ protected $fillable = ['active', 'last_name', 'first_name', 'username', 'email', 'password', 'remember_token', 'last_login']; - protected $hidden = ['password', 'remember_token']; - - - /** - * The attributes that should be cast to native types. - * - * @var array - */ protected $casts = [ 'email_verified_at' => 'datetime', ]; diff --git a/app/Models/Shop/Article.php b/app/Models/Shop/Article.php index a57e26a9..decb6b3f 100644 --- a/app/Models/Shop/Article.php +++ b/app/Models/Shop/Article.php @@ -94,6 +94,21 @@ class Article extends Model implements HasMedia return $query->where($this->table . '.article_nature_id', $id); } + public function scopeByCategories($query, $categories_id) + { + return $categories_id ? $query->whereHas('categories', function ($query) use ($categories_id) { + $query->whereIn('id', $categories_id); + }) : $query; + } + + public function scopeByCategoryParent($query, $category_id) + { + $category = Category::find($category_id); + return $category_id ? $query->whereHas('categories', function ($query) use ($category) { + $query->where('_lft', '>=', $category->_lft)->where('_rgt', '<=', $category->_rgt); + }) : $query; + } + public function scopeByCategory($query, $category_id) { return $category_id ? $query->whereHas('categories', function ($query) use ($category_id) { diff --git a/app/Models/Shop/Customer.php b/app/Models/Shop/Customer.php index 82a00bc3..197b2551 100644 --- a/app/Models/Shop/Customer.php +++ b/app/Models/Shop/Customer.php @@ -3,11 +3,19 @@ namespace App\Models\Shop; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; +use Yadahan\AuthenticationLog\AuthenticationLogable; +use Illuminate\Foundation\Auth\User as Authenticatable; -class Customer extends Model +class Customer extends Authenticatable { + use AuthenticationLogable, SoftDeletes; + protected $guarded = ['id']; protected $table = 'shop_customers'; + protected $fillable = ['active', 'last_name', 'first_name', 'username', 'email', 'password', 'remember_token', 'settings', 'last_login']; + protected $hidden = ['password', 'remember_token']; + protected $casts = ['email_verified_at' => 'datetime',]; public function addresses() { diff --git a/app/Repositories/Core/User/ShopCart.php b/app/Repositories/Core/User/ShopCart.php index 37b08dfa..545a5d14 100644 --- a/app/Repositories/Core/User/ShopCart.php +++ b/app/Repositories/Core/User/ShopCart.php @@ -12,10 +12,13 @@ class ShopCart { if (self::has($item['id'])) { if ($update) { - self::remove($id); + self::remove($item['id']); $ret = self::get()->add($item); + // $ret = self::get()->update($item['id'], ['quantity' => $item['quantity']]); } else { $ret = self::get()->update($item['id'], ['quantity' => $item['quantity']]); + // self::remove($item['id']); + // $ret = self::get()->add($item); } } else { $ret = self::get()->add($item); @@ -45,7 +48,7 @@ class ShopCart public static function clear() { Cart::clear(); - return Cart::session(Auth::id())->clear(); + return self::get()->clear(); } public static function has($id) @@ -70,7 +73,17 @@ class ShopCart public static function getTotal() { - return self::get()->getTotal(); + return number_format(round(self::get()->getTotal(),2),2); + } + + public static function getItemQuantity($id) + { + return self::getItem($id) ? (int) self::getItem($id)->quantity : 0; + } + + public static function getItem($id) + { + return Cart::get($id); } public static function getContent() @@ -80,6 +93,6 @@ class ShopCart public static function get() { - return Cart::session(Users::getId()); + return Cart::session('_token'); } } diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index b6bacc1e..d45a3790 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -195,7 +195,7 @@ class Articles $model = ($options['homepage'] ?? false) ? Article::homepage()->visible() : Article::visible(); // exit; - $data = $model->byCategory($category_id)->byTags($tags)->withAvailableOffers($sale_channel_id)->with([ + $data = $model->byCategoryParent($category_id)->byTags($tags)->withAvailableOffers($sale_channel_id)->with([ 'image', 'product', 'article_nature', diff --git a/app/Repositories/Shop/Offers.php b/app/Repositories/Shop/Offers.php index 05afbf98..980b681a 100644 --- a/app/Repositories/Shop/Offers.php +++ b/app/Repositories/Shop/Offers.php @@ -31,7 +31,8 @@ class Offers 'tariff.price_lists.price_list_values', 'variation', ])->find($id); - $offer->article->image = Articles::getFullImageByArticle($offer->article); + $images = Articles::getFullImagesByArticle($offer->article); + $offer->article->image = Articles::getPreviewSrc($images[0] ?? false); return $offer; } diff --git a/app/Repositories/Shop/TagGroups.php b/app/Repositories/Shop/TagGroups.php index 9584a95c..316bffda 100644 --- a/app/Repositories/Shop/TagGroups.php +++ b/app/Repositories/Shop/TagGroups.php @@ -14,7 +14,7 @@ class TagGroups return TagGroup::get()->SortBy('name')->pluck('name', 'id')->toArray(); } - public static function getWithTagsAndCountOffers() + public static function getWithTagsAndCountOffers($category_id = false) { $tags = Tag::withCount(['articles'])->get()->toArray(); $tag_groups = TagGroup::pluck('name', 'id')->toArray(); diff --git a/build/css/site.css b/build/css/site.css index a6045816..2ecc82b9 100644 --- a/build/css/site.css +++ b/build/css/site.css @@ -30,6 +30,19 @@ a.green-dark:hover { text-shadow: 4px black; } +.btn-green-dark { + color: #fff; + background-color: #335012; + border-color: #28a745; +} + +.btn-green-dark a:hover { + color: #fff; + font-weight: 900; + text-decoration: none; + text-shadow: 4px black; +} + .green-light { color: #F1F7EE; } @@ -60,6 +73,10 @@ a.green-dark:hover { width: 100% } +.slick-prev:before, .slick-next:before { + color: #335012!important; +} + @font-face { font-family: 'noto_sanscondensed'; src: url('/fonts/notosans-condensed/notosans-condensed-webfont.eot'); diff --git a/composer.json b/composer.json index 8298f6e4..375e8c1b 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,6 @@ "geo6/geocoder-php-addok-provider": "^1.1", "gzero/eloquent-tree": "^3.1", "hassankhan/config": "^2.1", - "highideas/laravel-users-online": "^3.0", "intervention/image": "^2.5", "intervention/imagecache": "^2.4", "jasonlewis/expressive-date": "^1.0", diff --git a/config/auth.php b/config/auth.php index 811e37e0..d9ca2fa9 100644 --- a/config/auth.php +++ b/config/auth.php @@ -46,6 +46,11 @@ return [ 'provider' => 'guests', ], + 'customer' => [ + 'driver' => 'session', + 'provider' => 'customers', + ], + 'api' => [ 'driver' => 'token', 'provider' => 'users', @@ -81,6 +86,11 @@ return [ 'model' => App\Models\Shop\Customer::class, ], + 'customers' => [ + 'driver' => 'eloquent', + 'model' => App\Models\Shop\Customer::class, + ], + // 'users' => [ // 'driver' => 'database', // 'table' => 'users', @@ -115,6 +125,12 @@ return [ 'expire' => 60, 'throttle' => 60, ], + 'customers' => [ + 'provider' => 'customers', + 'table' => 'shop_customer_password_resets', + 'expire' => 60, + 'throttle' => 60, + ], ], /* diff --git a/resources/views/Shop/Articles/partials/article.blade.php b/resources/views/Shop/Articles/partials/article.blade.php index c51b661c..a91ec7d0 100644 --- a/resources/views/Shop/Articles/partials/article.blade.php +++ b/resources/views/Shop/Articles/partials/article.blade.php @@ -3,18 +3,18 @@ {{ $product_name }}
-
-
{{ $article['parent_name'] }}
- {{ $article['product_name'] }} -
-
- +
+ +
{{ $article['parent_name'] }}
+
{{ $article['product_name'] }}
- Semence + Semence
@if ($article['semences'] ?? false) {{ $article['semences']['price'] ?? null }}
@else @@ -22,7 +22,7 @@ @endif
- Plant + Plant
@if ($article['plants'] ?? false) {{ $article['plants']['price'] }}
@else diff --git a/resources/views/Shop/Articles/partials/article_rows.blade.php b/resources/views/Shop/Articles/partials/article_rows.blade.php index 32d85605..f0f45ccb 100644 --- a/resources/views/Shop/Articles/partials/article_rows.blade.php +++ b/resources/views/Shop/Articles/partials/article_rows.blade.php @@ -1,47 +1,60 @@ -
+
- +
-
-
+
+
@if ($article['semences'] ?? false) - {{ $article['semences']['price'] ?? null }}
- {{ $article['semences']['variation'] }} -
- Quantité : +
+ {{ $article['semences']['price'] ?? null }}
+ {{ $article['semences']['variation'] }} +
+ Quantité : 1 +
+ @include('components.form.button', [ + 'class' => 'btn-green-dark basket semences mb-3 mt-2 shadow', + 'txt' => 'Ajouter au panier', + ])
- @include('components.form.button', [ - 'class' => 'btn-success basket semences', - 'txt' => 'Ajouter au panier', - ]) @endif
-
+
@if ($article['plants'] ?? false) - {{ $article['plants']['price'] }}
- {{ $article['plants']['variation'] }} +
+ {{ $article['plants']['price'] ?? null }}
+ {{ $article['plants']['variation'] }} +
+ Quantité : 1 +
+ @include('components.form.button', [ + 'class' => 'btn-success basket semences mb-3 mt-2 shadow', + 'txt' => 'Ajouter au panier', + ]) +
@endif
diff --git a/resources/views/Shop/Baskets/basket.blade.php b/resources/views/Shop/Baskets/basket.blade.php index 8305648a..95da0626 100644 --- a/resources/views/Shop/Baskets/basket.blade.php +++ b/resources/views/Shop/Baskets/basket.blade.php @@ -17,7 +17,7 @@
@foreach ($basket as $nature => $items) -
+

{{ ucfirst($nature) }}

@foreach ($items as $item) @@ -75,10 +75,11 @@ $('.basket-quantity').change(function() { var offer_id = $(this).data('id'); var quantity = $(this).val(); + var $row = $(this).parents('.row'); console.log("add basket"); console.log(quantity); updateBasket(offer_id, quantity, function() { - calculatePrice($(this).parents('.basket-row')); + calculatePrice($row); calculateTotal(); }); }); @@ -98,6 +99,8 @@ } function calculatePrice($that) { + console.log('calculatePrice'); + console.log($that); var quantity = $that.find('.basket-quantity').val(); var price = $that.find('.basket-price').text(); var total_price = fixNumber(quantity * price); diff --git a/resources/views/Shop/Baskets/partials/article.blade.php b/resources/views/Shop/Baskets/partials/article.blade.php index c2292e75..5886a062 100644 --- a/resources/views/Shop/Baskets/partials/article.blade.php +++ b/resources/views/Shop/Baskets/partials/article.blade.php @@ -1,4 +1,4 @@ -
+
diff --git a/resources/views/Shop/Baskets/partials/modalBasket.blade.php b/resources/views/Shop/Baskets/partials/modalBasket.blade.php index aab2085c..2519d8bf 100644 --- a/resources/views/Shop/Baskets/partials/modalBasket.blade.php +++ b/resources/views/Shop/Baskets/partials/modalBasket.blade.php @@ -2,7 +2,7 @@
- ... + ...
diff --git a/resources/views/Shop/Homepage/partials/sliderByShelve.blade.php b/resources/views/Shop/Homepage/partials/sliderByShelve.blade.php index 53c96836..0ae3d4b5 100644 --- a/resources/views/Shop/Homepage/partials/sliderByShelve.blade.php +++ b/resources/views/Shop/Homepage/partials/sliderByShelve.blade.php @@ -2,22 +2,24 @@
-

{{ $shelve['name'] }}

+

{{ $shelve['name'] }}

-
- @foreach ($shelve['articles'] as $name => $article) - - @endforeach +
+
+ @foreach ($shelve['articles'] as $name => $article) + + @endforeach +
@endif \ No newline at end of file diff --git a/resources/views/Shop/Tags/partials/filter.blade.php b/resources/views/Shop/Tags/partials/filter.blade.php index d8b0124a..626862d8 100644 --- a/resources/views/Shop/Tags/partials/filter.blade.php +++ b/resources/views/Shop/Tags/partials/filter.blade.php @@ -1,5 +1,5 @@