Add prices and filtering by sale_channel with default
This commit is contained in:
@@ -14,8 +14,6 @@ class ArticleController extends Controller
|
|||||||
{
|
{
|
||||||
$data = self::init();
|
$data = self::init();
|
||||||
$data['article'] = Articles::getArticleToSell($id);
|
$data['article'] = Articles::getArticleToSell($id);
|
||||||
// dump($data['article']);
|
|
||||||
// exit;
|
|
||||||
return view('Shop.Articles.show', $data);
|
return view('Shop.Articles.show', $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,4 +23,9 @@ class SaleChannel extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasManyThrough(Tariff::class, PriceList::class, 'sale_channel_id', 'id', 'id', 'tariff_id');
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,15 +27,14 @@ class Articles
|
|||||||
return $export;
|
return $export;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getOffersGroupedByNature($id)
|
public static function getOffersGroupedByNature($id, $sale_channel_id = false)
|
||||||
{
|
{
|
||||||
$article_ids = self::getSiblingsIds($id);
|
$article_ids = self::getSiblingsIds($id);
|
||||||
$offers = Offers::getOffersByArticles($article_ids);
|
$offers = Offers::getOffersByArticles($article_ids, $sale_channel_id);
|
||||||
// dump($offers->toArray());
|
|
||||||
foreach ($offers as $offer) {
|
foreach ($offers as $offer) {
|
||||||
$data[$offer->article_nature->name][] = [
|
$data[strtolower($offer->article_nature->name)] = [
|
||||||
'name' => $offer->variation->name,
|
'name' => $offer->variation->name,
|
||||||
'tariff' => $offer->tariff,
|
'prices' => $offer->tariff->price_lists->first()->price_list_values->toArray(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
@@ -86,7 +85,7 @@ class Articles
|
|||||||
$data['inherited'] = self::getInherited($id);
|
$data['inherited'] = self::getInherited($id);
|
||||||
$data['categories'] = self::getCategoriesNameByArticle($article);
|
$data['categories'] = self::getCategoriesNameByArticle($article);
|
||||||
$data['tags'] = self::getTagsSlugByArticle($article);
|
$data['tags'] = self::getTagsSlugByArticle($article);
|
||||||
$data['offers'] = self::getOffersById($id)->toArray();
|
$data['offers'] = self::getOffersGroupedByNature($id);
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,15 +6,24 @@ use App\Models\Shop\Offer;
|
|||||||
|
|
||||||
class Offers
|
class Offers
|
||||||
{
|
{
|
||||||
|
public static function getOffersByArticles($articles_ids, $sale_channel_id = false)
|
||||||
public static function getOffersByArticles($articles_ids)
|
|
||||||
{
|
{
|
||||||
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)
|
public static function getThumbSrcById($id)
|
||||||
|
|||||||
@@ -6,6 +6,21 @@ use App\Models\Shop\SaleChannel;
|
|||||||
|
|
||||||
class SaleChannels
|
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()
|
public static function getOptions()
|
||||||
{
|
{
|
||||||
return SaleChannel::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
return SaleChannel::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
'title' => 'Semence',
|
'title' => 'Semence',
|
||||||
'class' => 'mb-3',
|
'class' => 'mb-3',
|
||||||
])
|
])
|
||||||
|
{{ $article['offers']['semences']['name'] }}<br>
|
||||||
|
{{ $article['offers']['semences']['prices'][0]['price_taxed'] }}<br>
|
||||||
@include('components.form.button', [
|
@include('components.form.button', [
|
||||||
'class' => 'btn-success basket semences',
|
'class' => 'btn-success basket semences',
|
||||||
'txt' => 'Ajouter au panier',
|
'txt' => 'Ajouter au panier',
|
||||||
@@ -28,6 +30,8 @@
|
|||||||
'title' => 'Plant',
|
'title' => 'Plant',
|
||||||
'class' => 'mb-3',
|
'class' => 'mb-3',
|
||||||
])
|
])
|
||||||
|
{{ $article['offers']['plants']['name'] }}<br>
|
||||||
|
{{ $article['offers']['plants']['prices'][0]['price_taxed'] }}<br>
|
||||||
@include('components.form.button', [
|
@include('components.form.button', [
|
||||||
'class' => 'btn-success basket plants',
|
'class' => 'btn-success basket plants',
|
||||||
'txt' => 'Ajouter au panier',
|
'txt' => 'Ajouter au panier',
|
||||||
|
|||||||
Reference in New Issue
Block a user