This commit is contained in:
ludo
2023-11-14 00:25:58 +01:00
parent 3cdb30a0dc
commit 216c408596
3 changed files with 23 additions and 20 deletions

View File

@@ -27,11 +27,11 @@ class Articles
return $export;
}
public static function getOffersGroupedByNature($id, $sale_channel_id = false)
public static function getOffersGroupedByNature($id, $saleChannelId = false)
{
$article_ids = self::getSiblingsIds($id);
$article_ids[] = $id;
$offers = Offers::getOffersByArticles($article_ids, $sale_channel_id);
$articleIds = self::getSiblingsIds($id);
$articleIds[] = $id;
$offers = Offers::getOffersByArticles($articleIds, $saleChannelId);
foreach ($offers as $offer) {
$data[strtolower($offer->article_nature->name)][] = [
'id' => $offer->id,
@@ -90,10 +90,10 @@ class Articles
return Article::orderBy('name', 'asc')->get();
}
public static function getArticleToSell($id, $sale_channel_id = false)
public static function getArticleToSell($id, $saleChannelId = false)
{
$data = self::getArticle($id);
$data['offers'] = self::getOffersGroupedByNature($id, $sale_channel_id);
$data['offers'] = self::getOffersGroupedByNature($id, $saleChannelId);
return $data;
}
@@ -220,20 +220,20 @@ class Articles
public static function getArticlesWithOffers($options = false)
{
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
$saleChannelId = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
$model = self::getModelByOptions($options);
$data = $model->withAvailableOffers($sale_channel_id)->with([
$data = $model->withAvailableOffers($saleChannelId)->with([
'image',
'product',
'article_nature',
'offers' => function ($query) use ($sale_channel_id) {
$query->bySaleChannel($sale_channel_id);
'offers' => function ($query) use ($saleChannelId) {
$query->bySaleChannel($saleChannelId);
},
'offers.tariff' => function ($query) use ($sale_channel_id) {
$query->bySaleChannel($sale_channel_id);
'offers.tariff' => function ($query) use ($saleChannelId) {
$query->bySaleChannel($saleChannelId);
},
'offers.tariff.price_lists' => function ($query) use ($sale_channel_id) {
$query->where('sale_channel_id', $sale_channel_id);
'offers.tariff.price_lists' => function ($query) use ($saleChannelId) {
$query->where('sale_channel_id', $saleChannelId);
},
'offers.tariff.price_lists.price_list_values',
'offers.variation.package',
@@ -255,9 +255,9 @@ class Articles
public static function getArticleNaturesIdsWithOffers($options = false)
{
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
$saleChannelId = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
$model = self::getModelByOptions($options);
$data = $model->withAvailableOffers($sale_channel_id)->get()->pluck('article_nature_id')->unique();
$data = $model->withAvailableOffers($saleChannelId)->get()->pluck('article_nature_id')->unique();
return array_values($data->toArray());
}
@@ -276,9 +276,9 @@ class Articles
public static function getProductTypesClassesWithOffers($options = false)
{
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
$saleChannelId = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
$model = self::getModelByOptions($options);
$data = $model->withAvailableOffers($sale_channel_id)->get()->pluck('product_type')->unique();
$data = $model->withAvailableOffers($saleChannelId)->get()->pluck('product_type')->unique();
return $data->toArray();
}