Files
opensem/app/Repositories/Shop/ArticlePrices.php
Ludovic CANDELLIER ef791fbcf2 Fix on new model
2020-07-26 23:48:12 +02:00

92 lines
1.9 KiB
PHP

<?php
namespace App\Repositories\Shop;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Yajra\DataTables\DataTables;
use App\Models\Shop\ArticlePrice;
class ArticlePrices
{
public static function getByArticle($id)
{
return ArticlePrice::byArticle($id)->get();
}
public static function getByArticleWithAttribute($id)
{
return ArticlePrice::with('article_attribute.attribute_value')->byArticle($id)->get();
}
public static function getDatatable()
{
$model = ArticlePrice::orderBy('name');
return Datatables::of($model)->make(true);
}
public static function getAll()
{
return ArticlePrice::orderBy('name','asc')->get();
}
public static function get($id)
{
return ArticlePrice::find($id);
}
public static function storePrices($article_attribute_id, $prices)
{
if ($prices) {
foreach ($prices as $key => $price) {
$prices[$key]['article_attribute_id'] = $article_attribute_id;
self::store($prices[$key]);
}
} else {
return false;
}
}
public static function store($data)
{
$attributes = isset($data['attributes']) ? $data['attributes'] : false;
unset($data['attributes']);
$id = isset($data['id']) ? $data['id'] : false;
$price = $id ? self::update($data) : self::create($data);
$ret = $attributes ? self::storeAttributes($price->id, $attributes) : false;
return $price->id;
}
public static function storeAttributes($article_price_id,$attributes)
{
return ArticleAttributes::storeAttribute($article_price_id, $attributes);
}
public static function create($data)
{
return ArticlePrice::create($data);
}
public static function update($data, $id = false)
{
$id = isset($data['id']) ? $data['id'] : false;
$article = ArticlePrice::find($id);
$article->update($data);
return $article;
}
public static function destroy($id)
{
return ArticlePrice::destroy($id);
}
}