diff --git a/app/Models/Shop/Categorizable.php b/app/Models/Shop/Categorizable.php index ca1157e9..e5aa54db 100644 --- a/app/Models/Shop/Categorizable.php +++ b/app/Models/Shop/Categorizable.php @@ -18,9 +18,9 @@ class Categorizable extends Model return $this->belongsTo(Category::class); } - public function articles() + public function article() { - return $this->belongsTo(Article::class)->where('categorizable_type', Article::class); + return $this->belongsTo(Article::class, 'categorizable_id'); } public function scopeByCategory($query, $category_id) diff --git a/app/Models/Shop/Category.php b/app/Models/Shop/Category.php index d8a4ae12..f689b176 100644 --- a/app/Models/Shop/Category.php +++ b/app/Models/Shop/Category.php @@ -36,11 +36,6 @@ class Category extends parentCategory return $this->morphedByMany(Article::class, 'categorizable'); } - public function ArticlesByParent() - { - - } - public function ArticlesTagged() { return $this->tags->articles; @@ -94,6 +89,8 @@ class Category extends parentCategory $sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID(); return $query->whereHas('articles', function ($query) use ($sale_channel_id) { $query->WithAvailableOffers($sale_channel_id); + })->orWhereHas('descendants.articles', function ($query) use ($sale_channel_id) { + $query->WithAvailableOffers($sale_channel_id); }); } } diff --git a/app/Repositories/Core/Categories.php b/app/Repositories/Core/Categories.php index 1e18469b..409a6986 100644 --- a/app/Repositories/Core/Categories.php +++ b/app/Repositories/Core/Categories.php @@ -36,7 +36,7 @@ class Categories public static function getCategoryTreeVisibles($sale_channel_id = false) { // return self::getModel()->defaultOrder()->visible()->hasAvailableOffers($sale_channel_id)->get()->toTree(); - return self::getModel()->defaultOrder()->visible()->get()->toTree(); + return self::getModel()->defaultOrder()->hasAvailableOffersByCategoryParent($sale_channel_id)->visible()->get()->toTree(); } public static function getChildren($data, $withFolder = false)