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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,19 @@ namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Producer;
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Traits\Model\Basic;
|
||||
use App\Traits\Repository\Imageable;
|
||||
|
||||
class Producers
|
||||
{
|
||||
use Imageable;
|
||||
use Basic, Imageable;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
return [
|
||||
'tags_list' => TagGroups::getTreeTags(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
@@ -31,21 +39,6 @@ class Producers
|
||||
return Tag::storeTags($variety, $tags);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Producer::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Producer::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Producer::find($id);
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$producer = self::get($id);
|
||||
@@ -73,27 +66,8 @@ class Producers
|
||||
return $producer;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
public static function getModel()
|
||||
{
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Producer::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Producer::destroy($id);
|
||||
return Producer::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,20 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Variation;
|
||||
use App\Traits\Model\Basic;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Variations
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
return [
|
||||
'packages' => Packages::getOptions(),
|
||||
'unities' => Unities::getOptions(),
|
||||
];
|
||||
}
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Variation::where('name', 'LIKE', "%${str}%")->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
@@ -36,7 +46,10 @@ class Variations
|
||||
|
||||
public static function getName($variation)
|
||||
{
|
||||
return $variation->package->value.' '.$variation->quantity.' '.($variation->unity->value ?? null).' '.Str::limit(strip_tags($variation->description), 15, ' (...)');
|
||||
return $variation->package->value.' '.
|
||||
$variation->quantity.' '.
|
||||
($variation->unity->value ?? null).' '.
|
||||
Str::limit(strip_tags($variation->description), 15, ' (...)');
|
||||
}
|
||||
|
||||
public static function buildName($data)
|
||||
@@ -44,29 +57,12 @@ class Variations
|
||||
return Packages::getName($data['package_id']).' '.$data['quantity'].' '.Unities::getName($data['unity_id']);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Variation::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
return Variation::with(['package', 'unity'])->findOrFail($id);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Variation::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$data['name'] = self::buildName($data);
|
||||
@@ -76,7 +72,7 @@ class Variations
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$id = $id ? $id : $data['id'];
|
||||
$variation = self::get($id);
|
||||
$data['name'] = self::buildName($data);
|
||||
$variation->update($data);
|
||||
@@ -84,8 +80,8 @@ class Variations
|
||||
return $variation;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
public static function getModel()
|
||||
{
|
||||
return Variation::destroy($id);
|
||||
return Variation::query();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user