diff --git a/app/Console/Commands/addTagGroup.php b/app/Console/Commands/addTagGroup.php new file mode 100644 index 00000000..8554121b --- /dev/null +++ b/app/Console/Commands/addTagGroup.php @@ -0,0 +1,26 @@ +get(); + foreach ($tags as $tag) { + $tag->update(['group' => TagGroups::getName($tag->tag_group_id)]); + } + } +} diff --git a/app/Http/Controllers/Shop/ArticleController.php b/app/Http/Controllers/Shop/ArticleController.php index 3acefcb8..b7ee3e8b 100644 --- a/app/Http/Controllers/Shop/ArticleController.php +++ b/app/Http/Controllers/Shop/ArticleController.php @@ -14,8 +14,6 @@ class ArticleController extends Controller { $data = self::init(); $data['article'] = Articles::getArticleToSell($id); - dump($data); - exit; return view('Shop.Articles.show', $data); } } diff --git a/app/Models/Shop/Merchandise.php b/app/Models/Shop/Merchandise.php index 9b4ca47a..dda691a1 100644 --- a/app/Models/Shop/Merchandise.php +++ b/app/Models/Shop/Merchandise.php @@ -24,8 +24,18 @@ class Merchandise extends Model implements HasMedia return $this->morphMany(Article::class, 'product'); } + public function Producer() + { + return $this->belongsTo(Producer::class); + } + public function tags() { return $this->morphToMany(Tag::class, 'taggable'); } + + public function scopeByProducer($query, $producer_id) + { + return $query->where('producer_id', $producer_id); + } } diff --git a/app/Models/Shop/TagGroup.php b/app/Models/Shop/TagGroup.php index e5c5f2e2..ccc9483b 100644 --- a/app/Models/Shop/TagGroup.php +++ b/app/Models/Shop/TagGroup.php @@ -3,11 +3,17 @@ namespace App\Models\Shop; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; + +use Dyrynda\Database\Support\CascadeSoftDeletes; class TagGroup extends Model { + use CascadeSoftDeletes, SoftDeletes; + protected $guarded = ['id']; protected $table = 'tag_groups'; + protected $cascadeDeletes = ['tags']; public function tags() { diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index 78d42fdf..01eeb90d 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -30,6 +30,7 @@ class Articles public static function getOffersGroupedByNature($id, $sale_channel_id = false) { $article_ids = self::getSiblingsIds($id); + $article_ids[] = $id; $offers = Offers::getOffersByArticles($article_ids, $sale_channel_id); foreach ($offers as $offer) { $data[strtolower($offer->article_nature->name)][] = [ @@ -92,10 +93,16 @@ class Articles } public static function getArticleToSell($id, $sale_channel_id = false) + { + $data = self::getArticle($id); + $data['offers'] = self::getOffersGroupedByNature($id, $sale_channel_id); + return $data; + } + + public static function getArticle($id) { $article = self::get($id); $data = $article->toArray(); - // $parents = self::getInheritedByProduct($article->product_id, $article->product_type); $data['description'] = self::getFullDescriptionByArticle($article); $images = self::getFullImagesByArticle($article); $data['image'] = self::getPreviewSrc($images[0] ?? false); @@ -103,8 +110,8 @@ class Articles $data['image_big'] = self::getImageSrc($images[0] ?? false); $data['inherited'] = self::getInherited($id); $data['categories'] = self::getCategoriesNameByArticle($article); - $data['tags'] = self::getTagsSlugByArticle($article); - $data['offers'] = self::getOffersGroupedByNature($id, $sale_channel_id); + $data['tags'] = self::getFullTagsSlugByArticle($article); + $data['comments'] = Comments::getByModel($article); return $data; } @@ -113,6 +120,7 @@ class Articles switch ($article->product_type) { case 'App\Models\Botanic\Variety': $data['variety'] = $article->product->description; + $data['plus'] = $article->product->plus; if ($article->product->specie->description ?? false) { $data['specie'] = $article->product->specie->description; } @@ -122,6 +130,7 @@ class Articles break; case 'App\Models\Shop\Merchandise': $data['merchandise'] = $article->product->description; + $data['producer'] = $article->product->producer->description; break; default: } @@ -132,20 +141,14 @@ class Articles if ($siblings) { array_push($data, $siblings); } - return $data; - } - - public static function getArticle($id) - { - $article = self::get($id); - $data = $article->toArray(); - $data['description'] = (!empty($article->description)) ? $article->description : $article->product->description; - $data['image'] = Articles::getPreview($article->image); - $data['image_big'] = Articles::getImage($article->image); - $data['inherited'] = self::getInherited($id); - $data['categories'] = self::getCategoriesNameByArticle($article); - $data['tags'] = self::getTagsSlugByArticle($article); - $data['comments'] = Comments::getByModel($article); + /* + $data['resume'] = ($data['semences'] ?? null) . + ($data['plants'] ?? null) . + ($data['variety'] ?? null) . + ($data['merchandise'] ?? null) . + ($data['plus'] ?? null); + */ + $data['description'] = $article->description; return $data; } @@ -421,6 +424,36 @@ class Articles return $article->tags->pluck('slug', 'id')->toArray(); } + public static function getFullTagsSlugByArticle($article) + { + $data = []; + + switch ($article->product_type) { + case 'App\Models\Botanic\Variety': + $data += $article->product->tags->toArray(); + if ($article->product->specie ?? false) { + $data += $article->product->specie->tags->toArray(); + } + break; + case 'App\Models\Botanic\Specie': + $data += $article->product->tags->toArray(); + break; + case 'App\Models\Shop\Merchandise': + $data += $article->product->tags->toArray(); + $data += $article->product->producer->tags->toArray(); + break; + default: + } + $data += $article->tags->toArray(); + + foreach ($data as $tag) { + if (!isset($tags[$tag['group']][$tag['name']])) { + $tags[$tag['group']][] = $tag['name']; + } + } + return $tags; + } + public static function getPricesByArticle($article) { return Prices::getByArticle($article->id); @@ -472,8 +505,7 @@ class Articles public static function getFullImageById($id) { - $article = self::get($id); - return self::getFullImageByImage($article); + return self::getFullImageByArticle(self::get($id)); } public static function getFullImageByArticle($article) diff --git a/app/Repositories/Shop/TagGroups.php b/app/Repositories/Shop/TagGroups.php index b0e0ea80..6f011827 100644 --- a/app/Repositories/Shop/TagGroups.php +++ b/app/Repositories/Shop/TagGroups.php @@ -3,6 +3,7 @@ namespace App\Repositories\Shop; use Illuminate\Support\Str; + use App\Models\Shop\TagGroup; use App\Models\Shop\Tag; @@ -55,7 +56,12 @@ class TagGroups public static function getSlug($id) { - return self::get($id)->slug; + return self::get($id)->slug ?? ''; + } + + public static function getName($id) + { + return self::get($id)->name ?? ''; } public static function get($id) @@ -84,6 +90,7 @@ class TagGroups $data['slug'] = Str::slug($data['name']); } $model->update($data); + Tags::updateGroup($id, $data['name']); return $model; } diff --git a/app/Repositories/Shop/Tags.php b/app/Repositories/Shop/Tags.php index 1afe1d14..6c785be8 100644 --- a/app/Repositories/Shop/Tags.php +++ b/app/Repositories/Shop/Tags.php @@ -66,8 +66,8 @@ class Tags public static function create($data) { - $data['name'] = ['fr' => $data['name']]; $data['slug'] = self::buildSlug($data); + $data['group'] = TagGroups::getName($data['tag_group_id']); $data['sort_order'] = self::getNewOrder($data['tag_group_id']); $tag = Tag::create($data); return $tag; @@ -78,15 +78,20 @@ class Tags { $id = $id ? $id : $data['id']; $tag = self::get($id); - $data['name'] = ['fr' => $data['name']]; $data['slug'] = self::buildSlug($data); + $data['group'] = TagGroups::getName($data['tag_group_id']); $tag->update($data); return $tag; } + public static function updateGroup($tag_group_id, $group) + { + return Tag::byGroup($tag_group_id)->update(['group' => $group]); + } + public static function buildSlug($data) { - return TagGroups::getSlug($data['tag_group_id']) . '-' . Str::slug($data['name']['fr']); + return Str::slug($data['name']); } public static function destroy($id) diff --git a/resources/views/Admin/Shop/Offers/partials/article.blade.php b/resources/views/Admin/Shop/Offers/partials/article.blade.php index 5331f083..4ebbe571 100644 --- a/resources/views/Admin/Shop/Offers/partials/article.blade.php +++ b/resources/views/Admin/Shop/Offers/partials/article.blade.php @@ -11,7 +11,7 @@ {{ $article['name'] ?? null }}
- {!! $article['image'] !!} +
@@ -19,7 +19,7 @@
{{ Form::label('categories', __('shop.shelves.title')) }}
@foreach (($article['categories'] ?? null) as $category) - {{ $category }} + {{ $category }} @endforeach
@@ -42,7 +42,7 @@
{{ Form::label('description', 'Description') }} - {!! $article['description'] ?? null !!} + {!! $article['description']['description'] ?? null !!}
diff --git a/resources/views/Shop/Articles/partials/ArticleAddBasket.blade.php b/resources/views/Shop/Articles/partials/ArticleAddBasket.blade.php index 04cf5c5c..ff1ea6ae 100644 --- a/resources/views/Shop/Articles/partials/ArticleAddBasket.blade.php +++ b/resources/views/Shop/Articles/partials/ArticleAddBasket.blade.php @@ -3,6 +3,7 @@ 'data' => $article['offers']['semences'], 'title' => 'Semence', 'model' => 'semences', + 'bgClass' => 'bg-yellow', ]) @endif @@ -11,6 +12,7 @@ 'data' => $article['offers']['plants'], 'title' => 'Plant', 'model' => 'plants', + 'bgClass' => 'bg-green', ]) @endif diff --git a/resources/views/Shop/Articles/partials/addBasket.blade.php b/resources/views/Shop/Articles/partials/addBasket.blade.php index ad4426b8..9517b470 100644 --- a/resources/views/Shop/Articles/partials/addBasket.blade.php +++ b/resources/views/Shop/Articles/partials/addBasket.blade.php @@ -1,7 +1,7 @@ @component('components.card', [ 'id_card' => $model . '-basket', 'title' => $title, - 'class' => 'mb-3', + 'class' => 'mb-3 ' . ($bgClass ?? null), ]) @include('components.form.select', [ diff --git a/resources/views/Shop/Articles/show.blade.php b/resources/views/Shop/Articles/show.blade.php index 9d0c36c8..f2da5313 100644 --- a/resources/views/Shop/Articles/show.blade.php +++ b/resources/views/Shop/Articles/show.blade.php @@ -9,14 +9,40 @@
-
+
@include('components.multi-images', ['images' => $article['images']])
+
+
{!! $article['description']['semences'] ?? null !!} {!! $article['description']['plants'] ?? null !!} {!! $article['description']['variety'] ?? null !!} {!! $article['description']['merchandise'] ?? null !!} + + @if ($article['description']['plus'] ?? false) +

Spécificités

+ {!! $article['description']['plus'] !!} + @endif + + @if (count($article['tags'] ?? [])) +

Caractéristiques

+ @foreach ($article['tags'] as $tag_group => $items) +
+ {{ $tag_group }} : + @foreach ($items as $tag) + {{ $tag }} + @endforeach +
+ @endforeach + @endif + + @if ($article['description']['specie'] ?? false) +

Complément

+ {!! $article['description']['specie'] ?? null !!} + {!! $article['description']['producer'] ?? null !!} + @endif +
@include('Shop.Articles.partials.ArticleAddBasket') diff --git a/routes/Admin/Shop/Tags.php b/routes/Admin/Shop/Tags.php index 1db02813..bd4e89ad 100644 --- a/routes/Admin/Shop/Tags.php +++ b/routes/Admin/Shop/Tags.php @@ -1,12 +1,11 @@ name('Tags.')->group(function () { - Route::get('', 'TagController@index')->name('index'); - Route::get('create', 'TagController@create')->name('create'); - Route::delete('destroy/{id?}', 'TagController@destroy')->name('destroy'); - Route::post('update', 'TagController@update')->name('update'); - Route::post('store', 'TagController@store')->name('store'); - Route::get('edit/{id}', 'TagController@edit')->name('edit'); - + Route::get('', 'TagController@index')->name('index'); + Route::get('create', 'TagController@create')->name('create'); + Route::delete('destroy/{id?}', 'TagController@destroy')->name('destroy'); + Route::post('update', 'TagController@update')->name('update'); + Route::post('store', 'TagController@store')->name('store'); + Route::get('edit/{id}', 'TagController@edit')->name('edit'); });