add methods to detect distinct product type et article nature on shelve

This commit is contained in:
Ludovic CANDELLIER
2023-04-01 22:01:15 +02:00
parent bc1cf1190b
commit 6649c32501
4 changed files with 59 additions and 10 deletions

View File

@@ -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);