add methods to get icon on article natures

This commit is contained in:
Ludovic CANDELLIER
2023-09-12 23:00:36 +02:00
parent 470560efb6
commit a29faabbf2
22 changed files with 583 additions and 155 deletions

View File

@@ -7,12 +7,71 @@ use App\Models\Botanic\Variety;
use App\Models\Shop\Article;
use App\Models\Shop\ArticleNature;
use App\Models\Shop\Merchandise;
use App\Repositories\Core\Medias;
use App\Traits\Model\Basic;
class ArticleNatures
{
use Basic;
public static function getIconBySlug($slug, $conversion = 'normal', $collection = 'images')
{
return self::getIcon(self::getIdBySlug($slug), $conversion, $collection);
}
public static function getIcon($id, $conversion = 'normal', $collection = 'images')
{
return Medias::getImage(self::get($id), $conversion, $collection);
}
public static function getIdBySlug($slug)
{
switch ($slug) {
case 'semences':
$id = 1;
break;
case 'plants':
$id = 2;
break;
case 'legumes':
$id = 3;
break;
case 'marchandises':
$id = 4;
break;
default:
$id = 1;
break;
}
return $id;
}
public static function getProductTypeBySlug($slug)
{
switch ($slug) {
case 'semences':
case 'plants':
case 'legumes':
$productType = 'botanic';
break;
case 'marchandises':
$productType = 'merchandise';
break;
default:
$productType = 'botanic';
break;
}
return $productType;
}
public static function storeIcon($nature, $file, $collection = 'images')
{
Medias::deleteImages($nature, $collection);
return Medias::storeImage($nature, $file, $collection);
}
public static function getProductType($id)
{
$type = self::get($id)->product_type ?? false;