Filters collapsed, customer auth and register, fix on basket recalculation
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
];
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user