diff --git a/app/Http/Controllers/Shop/ArticleController.php b/app/Http/Controllers/Shop/ArticleController.php index 5b752ce0..b7ee3e8b 100644 --- a/app/Http/Controllers/Shop/ArticleController.php +++ b/app/Http/Controllers/Shop/ArticleController.php @@ -14,8 +14,6 @@ class ArticleController extends Controller { $data = self::init(); $data['article'] = Articles::getArticleToSell($id); - // dump($data['article']); - // exit; return view('Shop.Articles.show', $data); } } diff --git a/app/Models/Shop/SaleChannel.php b/app/Models/Shop/SaleChannel.php index 7bc42f85..42d57dfb 100644 --- a/app/Models/Shop/SaleChannel.php +++ b/app/Models/Shop/SaleChannel.php @@ -23,4 +23,9 @@ class SaleChannel extends Model { return $this->hasManyThrough(Tariff::class, PriceList::class, 'sale_channel_id', 'id', 'id', 'tariff_id'); } + + public function scopeByCode($query, $code) + { + return $query->where($this->table . '.code', $code); + } } diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index 4d801962..2531c8ed 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -27,15 +27,14 @@ class Articles return $export; } - public static function getOffersGroupedByNature($id) + public static function getOffersGroupedByNature($id, $sale_channel_id = false) { $article_ids = self::getSiblingsIds($id); - $offers = Offers::getOffersByArticles($article_ids); - // dump($offers->toArray()); + $offers = Offers::getOffersByArticles($article_ids, $sale_channel_id); foreach ($offers as $offer) { - $data[$offer->article_nature->name][] = [ + $data[strtolower($offer->article_nature->name)] = [ 'name' => $offer->variation->name, - 'tariff' => $offer->tariff, + 'prices' => $offer->tariff->price_lists->first()->price_list_values->toArray(), ]; } return $data; @@ -86,7 +85,7 @@ class Articles $data['inherited'] = self::getInherited($id); $data['categories'] = self::getCategoriesNameByArticle($article); $data['tags'] = self::getTagsSlugByArticle($article); - $data['offers'] = self::getOffersById($id)->toArray(); + $data['offers'] = self::getOffersGroupedByNature($id); return $data; } diff --git a/app/Repositories/Shop/Offers.php b/app/Repositories/Shop/Offers.php index 72f9d65a..9be3c8d1 100644 --- a/app/Repositories/Shop/Offers.php +++ b/app/Repositories/Shop/Offers.php @@ -6,15 +6,24 @@ use App\Models\Shop\Offer; class Offers { - - public static function getOffersByArticles($articles_ids) + public static function getOffersByArticles($articles_ids, $sale_channel_id = false) { - return Offer::active()->with(['article_nature', 'variation', 'tariff.price_lists.price_list_values'])->byArticles($articles_ids)->get(); + $sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID(); + return Offer::active() + ->with(['article_nature', 'variation', 'tariff.price_lists.price_list_values']) + ->byArticles($articles_ids) + ->bySaleChannel($sale_channel_id) + ->get(); } - public static function getOffersByArticle($article_id) + public static function getOffersByArticle($article_id, $sale_channel_id = false) { - return Offer::active()->with(['article_nature', 'variation', 'tariff.price_lists.price_list_values'])->byArticle($article_id)->get(); + $sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID(); + return Offer::active() + ->with(['article_nature', 'variation', 'tariff.price_lists.price_list_values']) + ->byArticle($article_id) + ->bySaleChannel($sale_channel_id) + ->get(); } public static function getThumbSrcById($id) diff --git a/app/Repositories/Shop/SaleChannels.php b/app/Repositories/Shop/SaleChannels.php index df1fc1e1..f8b581c3 100644 --- a/app/Repositories/Shop/SaleChannels.php +++ b/app/Repositories/Shop/SaleChannels.php @@ -6,6 +6,21 @@ use App\Models\Shop\SaleChannel; class SaleChannels { + public static function getDefaultID() + { + return self::getDefault()->id; + } + + public static function getDefault() + { + return self::getByCode('clic'); + } + + public static function getByCode($code) + { + return SaleChannel::byCode($code)->first(); + } + public static function getOptions() { return SaleChannel::orderBy('name', 'asc')->pluck('name', 'id')->toArray(); diff --git a/resources/views/Shop/Articles/show.blade.php b/resources/views/Shop/Articles/show.blade.php index 66c908f7..96c7fc24 100644 --- a/resources/views/Shop/Articles/show.blade.php +++ b/resources/views/Shop/Articles/show.blade.php @@ -18,6 +18,8 @@ 'title' => 'Semence', 'class' => 'mb-3', ]) + {{ $article['offers']['semences']['name'] }}
+ {{ $article['offers']['semences']['prices'][0]['price_taxed'] }}
@include('components.form.button', [ 'class' => 'btn-success basket semences', 'txt' => 'Ajouter au panier', @@ -28,6 +30,8 @@ 'title' => 'Plant', 'class' => 'mb-3', ]) + {{ $article['offers']['plants']['name'] }}
+ {{ $article['offers']['plants']['prices'][0]['price_taxed'] }}
@include('components.form.button', [ 'class' => 'btn-success basket plants', 'txt' => 'Ajouter au panier',