add methods to detect distinct product type et article nature on shelve
This commit is contained in:
@@ -21,6 +21,11 @@ class ArticleNatures
|
||||
return $type ? self::getProductTypes()[$type] : false;
|
||||
}
|
||||
|
||||
public static function getProductTypeNameByClass($model)
|
||||
{
|
||||
return self::getProductTypeName(self::getProductTypeByModel($model));
|
||||
}
|
||||
|
||||
public static function getProductTypeName($type)
|
||||
{
|
||||
return self::getProductTypes()[$type] ?? false;
|
||||
@@ -30,16 +35,12 @@ class ArticleNatures
|
||||
{
|
||||
switch ($model) {
|
||||
case Specie::class:
|
||||
$type = 1;
|
||||
break;
|
||||
case Variety::class:
|
||||
$type = 1;
|
||||
break;
|
||||
return 1;
|
||||
case Merchandise::class:
|
||||
$type = 2;
|
||||
break;
|
||||
return 2;
|
||||
}
|
||||
return $type ?? false;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getProductTypes()
|
||||
@@ -83,6 +84,12 @@ class ArticleNatures
|
||||
return ArticleNature::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getNamesByIds($ids)
|
||||
{
|
||||
$names = ArticleNature::byIds($ids)->pluck('name')->toArray();
|
||||
return array_map('strtolower', $names);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return ArticleNature::find($id);
|
||||
|
||||
@@ -194,7 +194,8 @@ class Articles
|
||||
{
|
||||
return [
|
||||
'id' => $article->id,
|
||||
'description' => (!empty($article->description)) ? $article->description : $article->product->description,
|
||||
'article_nature_id' => $article->article_nature_id,
|
||||
'description' => $article->description ? $article->description : $article->product->description,
|
||||
'image' => self::getFullImageByArticle($article),
|
||||
'product_type' => $article->product_type,
|
||||
'product_id' => $article->product_id,
|
||||
@@ -238,6 +239,38 @@ class Articles
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getArticleNaturesWithOffers($options = false)
|
||||
{
|
||||
return ArticleNatures::getNamesByIds(self::getArticleNaturesIdsWithOffers($options));
|
||||
}
|
||||
|
||||
public static function getArticleNaturesIdsWithOffers($options = false)
|
||||
{
|
||||
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
|
||||
$model = self::getModelByOptions($options);
|
||||
$data = $model->withAvailableOffers($sale_channel_id)->get()->pluck('article_nature_id')->unique();
|
||||
return array_values($data->toArray());
|
||||
}
|
||||
|
||||
public static function getProductTypesWithOffers($options = false)
|
||||
{
|
||||
$data = [];
|
||||
$classes = self::getProductTypesClassesWithOffers($options);
|
||||
foreach ($classes as $class) {
|
||||
$type = ArticleNatures::getProductTypeNameByClass($class);
|
||||
$data[$type] = true;
|
||||
}
|
||||
return array_keys($data);
|
||||
}
|
||||
|
||||
public static function getProductTypesClassesWithOffers($options = false)
|
||||
{
|
||||
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
|
||||
$model = self::getModelByOptions($options);
|
||||
$data = $model->withAvailableOffers($sale_channel_id)->get()->pluck('product_type')->unique();
|
||||
return $data->toArray();
|
||||
}
|
||||
|
||||
public static function getModelByOptions($options = false)
|
||||
{
|
||||
$category_id = $options['category_id'] ?? false;
|
||||
|
||||
Reference in New Issue
Block a user