Add prices and filtering by sale_channel with default
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user