little refactoring
This commit is contained in:
@@ -3,12 +3,21 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Merchandise;
|
||||
use App\Traits\Model\Basic;
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Traits\Repository\Imageable;
|
||||
|
||||
class Merchandises
|
||||
{
|
||||
use Imageable;
|
||||
use Basic, Imageable;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
return [
|
||||
'producers_list' => Producers::getOptions(),
|
||||
'tags_list' => TagGroups::getTreeTags(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
@@ -26,11 +35,6 @@ class Merchandises
|
||||
return Merchandise::with(['price_lists.price_list_values', 'price_lists.sale_channel'])->find($id);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Merchandise::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getStatus($status_id)
|
||||
{
|
||||
return self::getStatuses()[$status_id];
|
||||
@@ -41,36 +45,11 @@ class Merchandises
|
||||
return ['Actif', 'Suspendu', 'Invisible', 'Obsolete'];
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Merchandise::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Merchandise::find($id);
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$data = self::get($id)->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getTags($id)
|
||||
{
|
||||
return self::get($id)->tags;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = $data['images'] ?? false;
|
||||
@@ -89,22 +68,9 @@ class Merchandises
|
||||
return Tag::storeTags($merchandise, $tags);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Merchandise::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
public static function getModel()
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Merchandise::destroy($id);
|
||||
return Merchandise::query();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user