From 5794cbb045305c522a39e33ba3a6e2e75ce48a64 Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Tue, 22 Feb 2022 23:03:29 +0100 Subject: [PATCH] Fixes on articles by sale_channel --- app/Models/Shop/Article.php | 6 +++--- app/Repositories/Shop/Articles.php | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/Models/Shop/Article.php b/app/Models/Shop/Article.php index 70266ea3..3487ef3f 100644 --- a/app/Models/Shop/Article.php +++ b/app/Models/Shop/Article.php @@ -120,10 +120,10 @@ class Article extends Model implements HasMedia return $query->has('offers'); } - public function scopeWithAvailableOffers($query) + public function scopeWithAvailableOffers($query, $sale_channel_id = false) { - return $query->whereHas('offers', function ($query) { - $query->active(); + return $query->whereHas('offers', function ($query) use ($sale_channel_id) { + $query->active()->bySaleChannel($sale_channel_id); }); } diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index 67745a75..a3ae54b3 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -75,7 +75,7 @@ class Articles return Article::orderBy('name', 'asc')->get(); } - public static function getArticleToSell($id) + public static function getArticleToSell($id, $sale_channel = false) { $article = self::get($id); $data = $article->toArray(); @@ -85,7 +85,7 @@ class Articles $data['inherited'] = self::getInherited($id); $data['categories'] = self::getCategoriesNameByArticle($article); $data['tags'] = self::getTagsSlugByArticle($article); - $data['offers'] = self::getOffersGroupedByNature($id); + $data['offers'] = self::getOffersGroupedByNature($id, $sale_channel); return $data; } @@ -135,9 +135,10 @@ class Articles return $data ?? false; } - public static function getArticlesWithOffers($category_id = false, $tags = false) + public static function getArticlesWithOffers($category_id = false, $tags = false, $sale_channel_id = false) { - return Article::byCategory($category_id)->byTags($tags)->visible()->withAvailableOffers()->with([ + $sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID(); + return Article::byCategory($category_id)->byTags($tags)->visible()->withAvailableOffers($sale_channel_id)->with([ 'image', 'product', 'article_nature',