diff --git a/app/Models/Shop/Article.php b/app/Models/Shop/Article.php index 1311d445..d4ef9e52 100644 --- a/app/Models/Shop/Article.php +++ b/app/Models/Shop/Article.php @@ -43,7 +43,7 @@ class Article extends Model implements HasMedia public function product() { - return $this->belongsTo($this->model, 'model_id'); + return $this->morphTo(); } public function scopeByArticle($query, $id) @@ -51,4 +51,15 @@ class Article extends Model implements HasMedia return $query->where('shop_articles.id',$id); } + public function scopeByCategory($query, $category_id) + { + + } + + public function scopeByFamily($query, $id) + { + return $query->where('shop_articles.article_family_id',$id); + } + + } \ No newline at end of file diff --git a/app/Models/Shop/ArticleAttribute.php b/app/Models/Shop/ArticleAttribute.php index 6e785463..8f70a37f 100644 --- a/app/Models/Shop/ArticleAttribute.php +++ b/app/Models/Shop/ArticleAttribute.php @@ -33,4 +33,11 @@ class ArticleAttribute extends Model { return $query->where('attribute_value_id', $id); } + + public function scopeByFamily($query, $id) + { + return $query->whereHas('attribute_value', function ($query) use ($id) { + $query->byFamily($id); + }); + } } \ No newline at end of file diff --git a/app/Models/Shop/ArticlePrice.php b/app/Models/Shop/ArticlePrice.php index c30f866b..e9b47173 100644 --- a/app/Models/Shop/ArticlePrice.php +++ b/app/Models/Shop/ArticlePrice.php @@ -33,7 +33,20 @@ class ArticlePrice extends Model return $query->whereHas('article', function ($query) use ($id) { $query->byArticle($id); }); + } + public function scopeByAttributeValue($query, $id) + { + return $query->whereHas('article_attribute', function ($query) use ($id) { + $query->byAttributeValue($id); + }); + } + + public function scopeByFamily($query, $id) + { + return $query->whereHas('article_attribute', function ($query) use ($id) { + $query->byFamily($id); + }); } } \ No newline at end of file