[WIP] Refactor generic & normal price

This commit is contained in:
Ludovic CANDELLIER
2020-08-31 23:23:55 +02:00
parent c9198de890
commit c025dbb385
18 changed files with 267 additions and 32 deletions

View File

@@ -38,6 +38,7 @@ class Articles
public static function getMeta(&$data = [])
{
$data['categories_options'] = Categories::getOptions();
$data['price_generics'] = PriceGenericCategories::getOptionsWithChildrens();
$data['families_options'] = ArticleFamilies::getOptions();
$data['taxes_options'] = Taxes::getOptions();
$data['attribute_families_options'] = PriceFamilies::getOptions();
@@ -64,7 +65,7 @@ class Articles
public static function getPricesByArticle($article)
{
return Prices::getByArticle($article->id)->toArray();
return Prices::getByArticle($article->id);
}
public static function get($id)

View File

@@ -33,6 +33,21 @@ class PriceGenericCategories
return PriceGenericCategory::get()->pluck('name','id')->toArray();
}
public static function getOptionsWithChildrens()
{
$prices = PriceGenericCategory::with('price_generics')->get();
$data = [];
foreach ($prices as $key => $price)
{
$data[$key]['label'] = $price->name;
foreach($price->price_generics as $generic)
{
$data[$key]['options'][$generic->id] = $generic->name;
}
}
return $data;
}
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;

View File

@@ -29,6 +29,13 @@ class PriceGenerics
return Datatables::of($model)->make(true);
}
public static function getOptions()
{
$model = PriceGeneric::with('category')->get()->toArray();
dump($model);
exit;
}
public static function getAll()
{
return PriceGeneric::orderBy('name','asc')->get();

View File

@@ -16,8 +16,7 @@ class Prices
public static function getByArticle($id)
{
$prices = Article::byArticle($id)->with('prices.price')->get()->pluck('prices')->toArray()[0];
// dump($prices);
$prices = Price::byArticle($id)->with('price')->get()->toArray();
$data = [];
foreach ($prices as $price)
{
@@ -32,7 +31,7 @@ class Prices
}
}
}
dump($data);
return $data;
}
public static function getDatatable()