Fixes on available offers in category childrens for building menu

This commit is contained in:
Ludovic CANDELLIER
2022-04-25 22:36:43 +02:00
parent 3ba5a833b2
commit c79facd0ca
3 changed files with 5 additions and 8 deletions

View File

@@ -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)

View File

@@ -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);
});
}
}

View File

@@ -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)