diff --git a/app/Datatables/Admin/Shop/ArticleNaturesDataTable.php b/app/Datatables/Admin/Shop/ArticleNaturesDataTable.php
index 9a4c6daa..edc6efc9 100644
--- a/app/Datatables/Admin/Shop/ArticleNaturesDataTable.php
+++ b/app/Datatables/Admin/Shop/ArticleNaturesDataTable.php
@@ -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 ? "" : '';
})
diff --git a/app/Http/Controllers/Admin/Shop/ArticleNatureController.php b/app/Http/Controllers/Admin/Shop/ArticleNatureController.php
index f00844dd..406d20c0 100644
--- a/app/Http/Controllers/Admin/Shop/ArticleNatureController.php
+++ b/app/Http/Controllers/Admin/Shop/ArticleNatureController.php
@@ -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);
}
diff --git a/app/Http/Controllers/Admin/Shop/MerchandiseController.php b/app/Http/Controllers/Admin/Shop/MerchandiseController.php
index e5c68274..0c0e0081 100644
--- a/app/Http/Controllers/Admin/Shop/MerchandiseController.php
+++ b/app/Http/Controllers/Admin/Shop/MerchandiseController.php
@@ -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;
diff --git a/app/Http/Controllers/Shop/CategoryController.php b/app/Http/Controllers/Shop/CategoryController.php
index 020eb2ee..35520bfb 100644
--- a/app/Http/Controllers/Shop/CategoryController.php
+++ b/app/Http/Controllers/Shop/CategoryController.php
@@ -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);
}
diff --git a/app/Http/Controllers/Shop/CustomerController.php b/app/Http/Controllers/Shop/CustomerController.php
index d16e9b87..d23be811 100644
--- a/app/Http/Controllers/Shop/CustomerController.php
+++ b/app/Http/Controllers/Shop/CustomerController.php
@@ -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]);
}
diff --git a/app/Http/Controllers/Shop/OrderController.php b/app/Http/Controllers/Shop/OrderController.php
index da3ab0f2..eeaaa4b0 100644
--- a/app/Http/Controllers/Shop/OrderController.php
+++ b/app/Http/Controllers/Shop/OrderController.php
@@ -37,6 +37,7 @@ class OrderController extends Controller
{
if (ShopCart::count()) {
$customer = Customers::getWithAddresses();
+
$data = [
'customer' => $customer ? $customer->toArray() : false,
'basket' => ShopCart::getSummary(),
diff --git a/app/Models/Shop/ArticleNature.php b/app/Models/Shop/ArticleNature.php
index d3479088..84f88548 100644
--- a/app/Models/Shop/ArticleNature.php
+++ b/app/Models/Shop/ArticleNature.php
@@ -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);
diff --git a/app/Models/Shop/Customer.php b/app/Models/Shop/Customer.php
index 82addf10..a3450a23 100644
--- a/app/Models/Shop/Customer.php
+++ b/app/Models/Shop/Customer.php
@@ -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);
diff --git a/app/Repositories/Shop/ArticleNatures.php b/app/Repositories/Shop/ArticleNatures.php
index 0f908a32..e74f42b4 100644
--- a/app/Repositories/Shop/ArticleNatures.php
+++ b/app/Repositories/Shop/ArticleNatures.php
@@ -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;
}
diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php
index 02d6fa06..bc0d4f1e 100644
--- a/app/Repositories/Shop/Articles.php
+++ b/app/Repositories/Shop/Articles.php
@@ -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));
diff --git a/app/Repositories/Shop/Customers.php b/app/Repositories/Shop/Customers.php
index 125b8af5..68c0f308 100644
--- a/app/Repositories/Shop/Customers.php
+++ b/app/Repositories/Shop/Customers.php
@@ -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();
diff --git a/app/Repositories/Shop/TagGroups.php b/app/Repositories/Shop/TagGroups.php
index 61bb3ab0..d0b09dc1 100644
--- a/app/Repositories/Shop/TagGroups.php
+++ b/app/Repositories/Shop/TagGroups.php
@@ -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'],
diff --git a/app/Traits/Model/Basic.php b/app/Traits/Model/Basic.php
index 940815d1..a5acda32 100644
--- a/app/Traits/Model/Basic.php
+++ b/app/Traits/Model/Basic.php
@@ -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;
}
}
diff --git a/app/Traits/Model/Imageable.php b/app/Traits/Model/Imageable.php
index 6911bb76..be0e26a5 100644
--- a/app/Traits/Model/Imageable.php
+++ b/app/Traits/Model/Imageable.php
@@ -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();
}
}
diff --git a/database/migrations/2023_09_18_144437_create_sessions_table.php b/database/migrations/2023_09_18_144437_create_sessions_table.php
new file mode 100644
index 00000000..06c3e450
--- /dev/null
+++ b/database/migrations/2023_09_18_144437_create_sessions_table.php
@@ -0,0 +1,35 @@
+string('id')->primary();
+ $table->foreignId('user_id')->nullable()->index();
+ $table->string('ip_address', 45)->nullable();
+ $table->text('user_agent')->nullable();
+ $table->longText('payload');
+ $table->integer('last_activity')->index();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('sessions');
+ }
+};
diff --git a/database/migrations/2023_10_17_153458_modify_shop_article_natures_table.php b/database/migrations/2023_10_17_153458_modify_shop_article_natures_table.php
new file mode 100644
index 00000000..b0c00618
--- /dev/null
+++ b/database/migrations/2023_10_17_153458_modify_shop_article_natures_table.php
@@ -0,0 +1,15 @@
+string('slug', 50)->after('name')->nullable();
+ });
+ }
+};
diff --git a/resources/views/Admin/Shop/ArticleNatures/form.blade.php b/resources/views/Admin/Shop/ArticleNatures/form.blade.php
index 76d79c3a..d1de5068 100644
--- a/resources/views/Admin/Shop/ArticleNatures/form.blade.php
+++ b/resources/views/Admin/Shop/ArticleNatures/form.blade.php
@@ -32,7 +32,7 @@
-
{!! $article['description'] !!}
+{!! Str::limit($article['description'], 500) !!}