Fix on preview mode
This commit is contained in:
@@ -23,44 +23,60 @@ class Articles
|
||||
return $export;
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Article::orderBy('name','asc')->pluck('name','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Article::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
public static function getArticle($id)
|
||||
{
|
||||
$article = Article::with('product.tags')->findOrFail($id);
|
||||
$data['article'] = $article->toArray();
|
||||
$data['article']['inherited'] = self::getInherited($id);
|
||||
// dump($data);
|
||||
// exit;
|
||||
$data['article']['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['article']['tags'] = self::getTagsByArticle($article);
|
||||
// $data['article']['prices'] = self::getPricesByArticle($article);
|
||||
|
||||
// $data['datatables']['comments'] = Comments::getDatatable();
|
||||
$data['article']['comments'] = $article->comments;
|
||||
$data = $article->toArray();
|
||||
$data['inherited'] = self::getInherited($id);
|
||||
$data['categories'] = self::getCategoriesNameByArticle($article);
|
||||
$data['tags'] = self::getTagsNameByArticle($article);
|
||||
$data['comments'] = Comments::getByModel($article);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$data = self::getArticleEdit($id);
|
||||
self::getMeta($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getArticleEdit($id)
|
||||
{
|
||||
$article = Article::with('product.tags')->findOrFail($id);
|
||||
$data = $article->toArray();
|
||||
$data['inherited'] = self::getInherited($id);
|
||||
$data['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['tags'] = self::getTagsByArticle($article);
|
||||
$data['comments'] = Comments::getByModel($article);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getInherited($id)
|
||||
{
|
||||
$article = Article::with('product.tags')->findOrFail($id);
|
||||
$product_type = $article->product_type;
|
||||
switch ($product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$data[] = ['name' => 'Espèces', 'description' => Species::getDescription($article->product->specie_id), 'tags' => Species::getTags($article->product->specie_id)];
|
||||
$data[] = ['name' => 'Variétés', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()];
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$data[] = ['name' => 'Espèces', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()];
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$data[] = ['name' => 'Marchandise', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()];
|
||||
break;
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$data[] = ['name' => 'Espèces', 'description' => Species::getDescription($article->product->specie_id), 'tags' => Species::getTags($article->product->specie_id)];
|
||||
$data[] = ['name' => 'Variétés', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()];
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$data[] = ['name' => 'Espèces', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()];
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$data[] = ['name' => 'Marchandise', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()];
|
||||
break;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
@@ -86,11 +102,21 @@ class Articles
|
||||
return $article->categories->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getCategoriesNameByArticle($article)
|
||||
{
|
||||
return $article->categories->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getTagsByArticle($article)
|
||||
{
|
||||
return $article->tags->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getTagsNameByArticle($article)
|
||||
{
|
||||
return $article->tags->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getPricesByArticle($article)
|
||||
{
|
||||
return Prices::getByArticle($article->id);
|
||||
|
||||
@@ -32,11 +32,13 @@ class PriceListValues
|
||||
return PriceListValue::find($id);
|
||||
}
|
||||
|
||||
public static function storePrices($generic_id, $values)
|
||||
public static function storePrices($price_list_id, $values)
|
||||
{
|
||||
foreach ($values as $value) {
|
||||
$value['price_generic_id'] = $generic_id;
|
||||
self::store($value);
|
||||
$value['price_list_id'] = $price_list_id;
|
||||
if ($value['price']) {
|
||||
self::store($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +46,7 @@ class PriceListValues
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$price = $id ? self::update($data) : self::create($data);
|
||||
return $price->id;
|
||||
return $price;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
|
||||
@@ -38,6 +38,11 @@ class PriceLists
|
||||
return PriceList::find($id);
|
||||
}
|
||||
|
||||
public static function getPrices($id)
|
||||
{
|
||||
return PriceList::with('price_list_values')->find($id);
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
return PriceList::with(['price_list_values'])->find($id);
|
||||
|
||||
@@ -16,6 +16,11 @@ class Tariffs
|
||||
return $export;
|
||||
}
|
||||
|
||||
public static function getPrices($id)
|
||||
{
|
||||
return Tariff::with(['price_lists.price_list_values','price_lists.sale_channel'])->find($id);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Tariff::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
|
||||
Reference in New Issue
Block a user