fix on customer auth, fix filters on shelves, refactor for article_nature, add slug

This commit is contained in:
ludo
2023-10-17 17:20:30 +02:00
parent 002644cb97
commit e6b15e2438
30 changed files with 1205 additions and 177 deletions

View File

@@ -25,7 +25,7 @@ class ArticleNaturesDataTable extends DataTable
{
$datatables
->editColumn('icon', function (ArticleNature $nature) {
$logo = Medias::getImage($nature, 'thumb');
$logo = Medias::getImage($nature, 'normal', 'icon');
return $logo ? "<img src='{$logo}'>" : '';
})

View File

@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin\Shop;
use App\Datatables\Admin\Shop\ArticleNaturesDataTable;
use App\Repositories\Shop\ArticleNatures;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class ArticleNatureController extends Controller
{
@@ -20,8 +21,11 @@ class ArticleNatureController extends Controller
public function store(Request $request)
{
$data = $request->all();
$data['slug'] = Str::slug($data['name'], '-');
$articleNature = ArticleNatures::store($request->all());
ArticleNatures::storeIcon($articleNature, $request->file('icon'));
ArticleNatures::storeIcon($articleNature, $request->file('icon'), 'icon');
ArticleNatures::storeIcon($articleNature, $request->file('icon_selection'), 'icon_selection');
return redirect()->route('Admin.Shop.ArticleNatures.index');
}
@@ -41,7 +45,8 @@ class ArticleNatureController extends Controller
'article_nature' => ArticleNatures::get($id),
'product_types' => ArticleNatures::getProductTypes(),
];
$data['article_nature']['icon'] = ArticleNatures::getIcon($id);
$data['article_nature']['icon'] = ArticleNatures::getIcon($id, 'normal', 'icon');
$data['article_nature']['icon_selection'] = ArticleNatures::getIcon($id, 'normal', 'icon_selection');
return view('Admin.Shop.ArticleNatures.edit', $data);
}

View File

@@ -2,7 +2,7 @@
namespace App\Http\Controllers\Admin\Shop;
use App\Datatables\Shop\MerchandisesDataTable;
use App\Datatables\Admin\Shop\MerchandisesDataTable;
use App\Repositories\Shop\Merchandises;
use App\Repositories\Shop\Producers;
use App\Repositories\Shop\TagGroups;

View File

@@ -19,25 +19,17 @@ class CategoryController extends Controller
public function show(Request $request, $categoryId, $articleNatureId = false)
{
$productTypes = Articles::getProductTypesWithOffers([
'category_id' => $categoryId,
]);
$articleNatures = Articles::getArticleNaturesWithOffers([
'category_id' => $categoryId,
]);
if ($articleNatureId) {
$productType = ArticleNatures::getProductType($articleNatureId);
dump($productType);
exit;
} else {
$articleNature = $request->input('article_nature');
if (! $articleNature) {
if (count($articleNatures) === 1) {
if (count($articleNatures)) {
$articleNature = $articleNatures[0];
} else {
$articleNature = 'semences';
}
}
$productType = ArticleNatures::getProductTypeBySlug($articleNature);
@@ -61,7 +53,7 @@ class CategoryController extends Controller
'tags' => TagGroups::getWithTagsAndCountOffers($categoryId),
];
// dump($data);
dump($data);
// exit;
return view('Shop.Shelves.shelve', $data);
}

View File

@@ -11,9 +11,7 @@ class CustomerController extends Controller
{
public function profile($id = false)
{
$data = Customers::editProfile($id);
return view('Shop.Customers.profile', $data);
return view('Shop.Customers.profile', Customers::editProfile($id));
}
public function modalProfile($id = false)
@@ -25,16 +23,14 @@ class CustomerController extends Controller
public function edit()
{
$id = Auth::id();
$data['customer'] = Customers::get($id, 'addresses')->toArray();
return view('Shop.Customers.edit', $data);
return view('Shop.Customers.edit', [
'customer' => Customers::getArray(Auth::id(), 'addresses'),
]);
}
public function storeProfileAjax(Request $request)
{
$data = $request->all();
$customer = Customers::store($data);
$customer = Customers::store($request->all());
return response()->json(['error' => 0]);
}

View File

@@ -37,6 +37,7 @@ class OrderController extends Controller
{
if (ShopCart::count()) {
$customer = Customers::getWithAddresses();
$data = [
'customer' => $customer ? $customer->toArray() : false,
'basket' => ShopCart::getSummary(),

View File

@@ -35,6 +35,11 @@ class ArticleNature extends Model implements HasMedia
return $query->where($this->table.'.id', $id);
}
public function scopeBySlug($query, $slug)
{
return $query->where($this->table.'.slug', $slug);
}
public function scopeByBotanic($query)
{
return $query->ByProductType(1);

View File

@@ -28,6 +28,16 @@ class Customer extends Authenticatable
return $this->hasMany(CustomerAddress::class);
}
public function invoicing_addresses(): HasMany
{
return $this->addresses()->where('type', 2);
}
public function delivery_addresses(): HasMany
{
return $this->addresses()->where('type', 1);
}
public function customer_deliveries(): HasMany
{
return $this->hasMany(CustomerDelivery::class);

View File

@@ -26,44 +26,21 @@ class ArticleNatures
public static function getIdBySlug($slug)
{
switch ($slug) {
case 'semences':
$id = 1;
break;
case 'plants':
$id = 2;
break;
case 'legumes':
$id = 3;
break;
case 'marchandises':
$id = 4;
break;
default:
$id = 1;
break;
}
$model = self::getBySlug($slug);
return $model ? $model->id : false;
}
return $id;
public static function getBySlug($slug)
{
return ArticleNature::bySlug($slug)->first();
}
public static function getProductTypeBySlug($slug)
{
switch ($slug) {
case 'semences':
case 'plants':
case 'legumes':
$productType = 'botanic';
break;
case 'marchandises':
$productType = 'merchandise';
break;
default:
$productType = 'botanic';
break;
}
$id = self::getIdBySlug($slug);
return $productType;
return $id ? self::getProductType($id) : false;
}
public static function storeIcon($nature, $file, $collection = 'images')
@@ -75,7 +52,8 @@ class ArticleNatures
public static function getProductType($id)
{
$type = self::get($id)->product_type ?? false;
$model = self::get($id);
$type = $model ? $model->product_type : false;
return $type ? self::getProductTypes()[$type] : false;
}

View File

@@ -246,6 +246,12 @@ class Articles
return $data;
}
public static function getArticleNaturesOptionsWithOffers($options = false)
{
$ids = self::getArticleNaturesIdsWithOffers($options);
}
public static function getArticleNaturesWithOffers($options = false)
{
return ArticleNatures::getNamesByIds(self::getArticleNaturesIdsWithOffers($options));

View File

@@ -84,7 +84,7 @@ class Customers
public static function getWithAddresses($id = false)
{
return self::get($id, 'addresses');
return self::get($id, ['invoicing_addresses', 'delivery_addresses']);
}
public static function getName($id = false)
@@ -99,6 +99,13 @@ class Customers
return self::guard()->user();
}
public static function get($id, $relations = false, $relationsCount = false)
{
$id = $id ? $id : self::getId();
return self::getModelRelations($relations, $relationsCount)->find($id);
}
public static function getId()
{
return self::guard()->id();

View File

@@ -15,13 +15,14 @@ class TagGroups
public static function getWithTagsAndCountOffers($category_id = false)
{
$data = [];
$tags = Tag::withCountArticlesByCategory($category_id)->get()->toArray();
$tag_groups = TagGroup::pluck('name', 'id')->toArray();
foreach ($tags as $tag) {
$data[$tag['tag_group_id']]['name'] = $tag_groups[$tag['tag_group_id']];
if (! $tag['articles_count']) {
continue;
}
$data[$tag['tag_group_id']]['name'] = $tag_groups[$tag['tag_group_id']];
$data[$tag['tag_group_id']]['tags'][] = [
'id' => $tag['id'],
'name' => $tag['name'],

View File

@@ -82,30 +82,37 @@ trait Basic
return self::get($id)->toArray();
}
public static function store($data)
public static function store($data, $stopStamping = false)
{
return $data['id'] ?? false ? self::update($data) : self::create($data);
return $data['id'] ?? false ? self::update($data, false, $stopStamping) : self::create($data, $stopStamping);
}
public static function create($data)
public static function create($data, $stopStamping = false)
{
return self::getModel()->create($data);
return self::getModel($stopStamping)->create($data);
}
public static function update($data, $id = false)
public static function update($data, $id = false, $stopStamping = false)
{
$id = $id ? $id : $data['id'];
$model = self::get($id);
if ($stopStamping) {
$model->stopUserstamping();
}
$model->update($data);
return $model;
}
public static function destroy($id)
public static function destroy($id, $force = false)
{
$model = self::get($id);
return $model ? $model->delete() : false;
if ($model) {
return $force ? $model->forceDelete() : $model->delete();
}
return false;
}
public static function count()
@@ -125,20 +132,39 @@ trait Basic
return $model ? $model->delete() : false;
}
public static function get($id, $relations = false, $relationscount = false)
public static function getArray($id, $relations = false, $relationsCount = false)
{
return self::getModelRelations($relations, $relationscount)->find($id);
$model = self::get($id, $relations, $relationsCount);
return $model ? $model->toArray() : false;
}
public static function getAll($relations = false, $relationscount = false)
public static function get($id, $relations = false, $relationsCount = false)
{
return self::getModelRelations($relations, $relationscount)->get();
return self::getModelRelations($relations, $relationsCount)->find($id);
}
public static function getModelRelations($relations = false, $relationscount = false)
public static function getWithTrashed($id, $relations = false, $relationsCount = false)
{
return self::getModelRelations($relations, $relationsCount)->withTrashed()->find($id);
}
public static function getAll($relations = false, $relationsCount = false)
{
return self::getModelRelations($relations, $relationsCount)->get();
}
public static function getRevisions($id)
{
$model = self::get($id, ['revisions.user'])->toArray();
return collect($model['revisions'])->sortBy('created_at')->reverse()->toArray();
}
public static function getModelRelations($relations = false, $relationsCount = false)
{
$model = $relations ? self::getModelWithRelations($relations) : false;
$model = $relationscount ? self::getModelWithCountRelations($relationscount, $model) : $model;
$model = $relationsCount ? self::getModelWithCountRelations($relationsCount, $model) : $model;
return $model ? $model : self::getModel();
}
@@ -153,8 +179,12 @@ trait Basic
return is_object($model) ? $model->withCount($relations) : self::getModel()->withCount($relations);
}
public static function getModel(): Model
public static function getModel($stopStamping = false): Model
{
return new Model();
$model = new Model();
if ($stopStamping) {
$model->stopUserstamping();
}
return $model;
}
}

View File

@@ -22,10 +22,28 @@ trait Imageable
public function registerMediaConversions(Media $media = null): void
{
$this->addMediaConversion('thumb')->fit(Manipulations::FIT_CROP, 32, 32);
$this->addMediaConversion('mini')->fit(Manipulations::FIT_CROP, 96, 96);
$this->addMediaConversion('preview')->fit(Manipulations::FIT_CROP, 160, 160);
$this->addMediaConversion('normal')->fit(Manipulations::FIT_CROP, 480, 480);
$watermark = public_path('img/watermark.png');
$this->addMediaConversion('thumb')->fit(Manipulations::FIT_CROP, 32, 32)
->watermark($watermark)
->watermarkHeight(100, Manipulations::UNIT_PERCENT)
->watermarkWidth(100, Manipulations::UNIT_PERCENT)
->watermarkFit(Manipulations::FIT_FILL);
$this->addMediaConversion('mini')->fit(Manipulations::FIT_CROP, 96, 96)
->watermark($watermark)
->watermarkHeight(100, Manipulations::UNIT_PERCENT)
->watermarkWidth(100, Manipulations::UNIT_PERCENT)
->watermarkFit(Manipulations::FIT_FILL);
$this->addMediaConversion('preview')->fit(Manipulations::FIT_CROP, 160, 160)
->watermark($watermark)
->watermarkHeight(100, Manipulations::UNIT_PERCENT)
->watermarkWidth(100, Manipulations::UNIT_PERCENT)
->watermarkFit(Manipulations::FIT_FILL);
$this->addMediaConversion('normal')->fit(Manipulations::FIT_CROP, 480, 480)
->watermark($watermark)
->watermarkHeight(100, Manipulations::UNIT_PERCENT)
->watermarkWidth(100, Manipulations::UNIT_PERCENT)
->watermarkFit(Manipulations::FIT_FILL);
// $this->addMediaConversion('zoom')->fit(Manipulations::FIT_CROP, 1200, 1200)->withResponsiveImages();
}
}