diff --git a/app/Http/Controllers/Shop/HomeController.php b/app/Http/Controllers/Shop/HomeController.php index 097d8804..d151bb20 100644 --- a/app/Http/Controllers/Shop/HomeController.php +++ b/app/Http/Controllers/Shop/HomeController.php @@ -9,6 +9,7 @@ use App\Repositories\Shop\Articles; use App\Repositories\Shop\Categories; use App\Repositories\Shop\Offers; use App\Repositories\Shop\Tags; +use App\Repositories\Shop\TagGroups; class HomeController extends Controller { @@ -24,11 +25,8 @@ class HomeController extends Controller $data['display_by_rows'] = $input['by_rows'] ?? false; // $data['offers'] = Offers::getLast()->toArray(); $data['articles'] = Articles::getArticlesToSell(); - $data['tags'] = Tags::getWithCountOffers(); - - // $data['prices'] = $data['articles']['offers'][0]['tariff']['price_lists'][0]['price_list_values'][0]; - // dump($data); - // exit; + // $data['tags'] = Tags::getWithCountOffers(); + $data['tags'] = TagGroups::getWithTagsAndCountOffers(); return view('Shop.home', $data); } } diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index b38b4be3..b8e35df3 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -64,8 +64,6 @@ class Articles public static function getArticlesToSell() { $articles = self::getArticlesWithOffers(); - // dump($articles->toArray()); - // exit; foreach ($articles as $article) { $price_lists = $article->offers[0]->tariff->price_lists->toArray(); // dump($price_lists); @@ -75,6 +73,8 @@ class Articles 'image' => $article->image, 'product_type' => $article->product_type, 'product_id' => $article->product_id, + 'product_name' => $article->product->name, + 'parent_name' => trim(str_replace($article->product->name, '', $article->name)), ]; $prices = $price_lists[0]['price_list_values'][0]; $article_nature_name = strtolower($article->article_nature->name); diff --git a/app/Repositories/Shop/TagGroups.php b/app/Repositories/Shop/TagGroups.php index a0775eb8..3b9231db 100644 --- a/app/Repositories/Shop/TagGroups.php +++ b/app/Repositories/Shop/TagGroups.php @@ -2,17 +2,11 @@ namespace App\Repositories\Shop; -use Yajra\DataTables\DataTables; - use App\Models\Shop\TagGroup; +use App\Models\Shop\Tag; class TagGroups { - public static function getDatatable() - { - $model = TagGroup::query(); - return Datatables::of($model)->make(true); - } public static function getOptions() { @@ -21,7 +15,17 @@ class TagGroups public static function getWithTagsAndCountOffers() { - return TagGroup::with('tags')->withCount(['tags.articles'])->get()->toArray(); + $tags = Tag::withCount(['articles'])->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']]; + $data[$tag['tag_group_id']]['tags'][] = [ + 'id' => $tag['id'], + 'name' => $tag['name'], + 'count' => $tag['articles_count'], + ]; + } + return $data; } public static function getTreeTags() diff --git a/resources/views/Shop/Articles/partials/article.blade.php b/resources/views/Shop/Articles/partials/article.blade.php index a57e513d..d7dc1232 100644 --- a/resources/views/Shop/Articles/partials/article.blade.php +++ b/resources/views/Shop/Articles/partials/article.blade.php @@ -2,31 +2,34 @@
-