From 0eaa11b2a90b0211fa9745d2a856ce139aa21f0e Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Mon, 7 Mar 2022 22:58:40 +0100 Subject: [PATCH] Fix on default sale channel --- app/Repositories/Shop/Articles.php | 5 +++-- app/Repositories/Shop/Offers.php | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index 93ffb9a5..c7fd7de9 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -75,8 +75,9 @@ class Articles return Article::orderBy('name', 'asc')->get(); } - public static function getArticleToSell($id, $sale_channel = false) + public static function getArticleToSell($id, $sale_channel_id = false) { + $sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID(); $article = self::get($id); $data = $article->toArray(); $parents = self::getInheritedByProduct($article->product_id, $article->product_type); @@ -87,7 +88,7 @@ class Articles $data['inherited'] = self::getInherited($id); $data['categories'] = self::getCategoriesNameByArticle($article); $data['tags'] = self::getTagsSlugByArticle($article); - $data['offers'] = self::getOffersGroupedByNature($id, $sale_channel); + $data['offers'] = self::getOffersGroupedByNature($id, $sale_channel_id); return $data; } diff --git a/app/Repositories/Shop/Offers.php b/app/Repositories/Shop/Offers.php index a4587e64..7543f175 100644 --- a/app/Repositories/Shop/Offers.php +++ b/app/Repositories/Shop/Offers.php @@ -10,7 +10,14 @@ class Offers { $sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID(); return Offer::active() - ->with(['article_nature', 'variation', 'tariff.price_lists.price_list_values']) + ->with([ + 'article_nature', + 'variation', + 'tariff.price_lists' => function($query) use ($sale_channel_id) { + $query->bySaleChannel($sale_channel_id); + }, + 'tariff.price_lists.price_list_values', + ]) ->byArticles($articles_ids) ->bySaleChannel($sale_channel_id) ->get(); @@ -20,7 +27,14 @@ class Offers { $sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID(); return Offer::active() - ->with(['article_nature', 'variation', 'tariff.price_lists.price_list_values']) + ->with([ + 'article_nature', + 'variation', + 'tariff.price_lists' => function($query) use ($sale_channel_id) { + $query->bySaleChannel($sale_channel_id); + }, + 'tariff.price_lists.price_list_values', + ]) ->byArticle($article_id) ->bySaleChannel($sale_channel_id) ->get();