diff --git a/app/Http/Controllers/Shop/CategoryController.php b/app/Http/Controllers/Shop/CategoryController.php index 8c5b7da3..f7539f00 100644 --- a/app/Http/Controllers/Shop/CategoryController.php +++ b/app/Http/Controllers/Shop/CategoryController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Shop; use Illuminate\Http\Request; use App\Http\Controllers\Controller; +use App\Repositories\Shop\Articles; use App\Repositories\Shop\Categories; use App\Repositories\Shop\Offers; use App\Repositories\Shop\Tags; @@ -17,15 +18,14 @@ class CategoryController extends Controller return $dataTable->render('Shop.Categories.list'); } - public function show($id) + public function show($category_id) { $data = self::init(); - $data['category'] = Categories::getFull($id); - $data['offers'] = Offers::getByCategoryWithTags($id); - $data['tags'] = Tags::getWithCountOffers(); - $data['tags2'] = TagGroups::getWithTagsAndCountOffers(); - dump($data); - exit; + $data['category'] = Categories::getFull($category_id); + $data['articles'] = Articles::getArticlesToSell($category_id); + $data['tags'] = TagGroups::getWithTagsAndCountOffers(); + // dump($data); + // exit; return view('Shop.shelve', $data); } diff --git a/app/Http/Controllers/Shop/HomeController.php b/app/Http/Controllers/Shop/HomeController.php index d151bb20..e9debb86 100644 --- a/app/Http/Controllers/Shop/HomeController.php +++ b/app/Http/Controllers/Shop/HomeController.php @@ -23,9 +23,7 @@ class HomeController extends Controller $input = $request->input(); $data = self::init(); $data['display_by_rows'] = $input['by_rows'] ?? false; - // $data['offers'] = Offers::getLast()->toArray(); $data['articles'] = Articles::getArticlesToSell(); - // $data['tags'] = Tags::getWithCountOffers(); $data['tags'] = TagGroups::getWithTagsAndCountOffers(); return view('Shop.home', $data); } diff --git a/app/Models/Shop/Article.php b/app/Models/Shop/Article.php index 4aa14757..99118e7d 100644 --- a/app/Models/Shop/Article.php +++ b/app/Models/Shop/Article.php @@ -78,9 +78,9 @@ class Article extends Model implements HasMedia public function scopeByCategory($query, $category_id) { - return $query->whereHas('categories', function ($query) use ($category_id) { + return $category_id ? $query->whereHas('categories', function ($query) use ($category_id) { $query->where('id', $category_id); - }); + }) : $query; } public function scopeByProduct($query, $model) @@ -93,6 +93,20 @@ class Article extends Model implements HasMedia return $query->where($this->table . '.product_id', $model_id); } + public function scopeByTag($query, $tag_id) + { + return $tag_id ? $query->whereHas('tags', function ($query) use ($tag_id) { + $query->where('id', $tag_id); + }) : $query; + } + + public function scopeByTags($query, $tags) + { + return $tags ? $query->whereHas('tags', function ($query) use ($tags) { + $query->whereIn('id', $tags); + }) : $query; + } + public function scopeWithOffers($query) { return $query->has('offers'); diff --git a/app/Models/Shop/Offer.php b/app/Models/Shop/Offer.php index 6431600b..0304a343 100644 --- a/app/Models/Shop/Offer.php +++ b/app/Models/Shop/Offer.php @@ -112,5 +112,4 @@ class Offer extends Model $query->whereIn('tag_id', $tags); }); } - } diff --git a/app/Models/Shop/PriceListValue.php b/app/Models/Shop/PriceListValue.php index 6750129d..ef626982 100644 --- a/app/Models/Shop/PriceListValue.php +++ b/app/Models/Shop/PriceListValue.php @@ -22,14 +22,10 @@ class PriceListValue extends Model public function tariff() { - return $this->belongsToThrough( - 'App\Models\Shop\Tariff', - 'App\Models\Shop\PriceList', - null, - '', + return $this->belongsToThrough('App\Models\Shop\Tariff', 'App\Models\Shop\PriceList', null, '', [ 'App\Models\Shop\Tariff' => 'tariff_id', - 'App\Models\Shop\PriceList' => 'price_list_id' + 'App\Models\Shop\PriceList' => 'price_list_id', ] ); } diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index d6439024..cbd135e8 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -61,9 +61,9 @@ class Articles return $data; } - public static function getArticlesToSell() + public static function getArticlesToSell($category_id = false, $tags = false) { - $articles = self::getArticlesWithOffers(); + $articles = self::getArticlesWithOffers($category_id, $tags); foreach ($articles as $article) { $price_lists = $article->offers[0]->tariff->price_lists->toArray(); // dump($price_lists); @@ -93,9 +93,9 @@ class Articles return $data; } - public static function getArticlesWithOffers() + public static function getArticlesWithOffers($category_id = false, $tags = false) { - return Article::visible()->withAvailableOffers()->with([ + return Article::byCategory($category_id)->byTags($tags)->visible()->withAvailableOffers()->with([ 'image', 'product', 'article_nature', diff --git a/resources/views/Shop/Tags/partials/filter.blade.php b/resources/views/Shop/Tags/partials/filter.blade.php index 8dfc12ad..322f8eaf 100644 --- a/resources/views/Shop/Tags/partials/filter.blade.php +++ b/resources/views/Shop/Tags/partials/filter.blade.php @@ -1,3 +1,9 @@ +