Change tag routines, articles saving is ok
This commit is contained in:
@@ -25,6 +25,16 @@ class ArticleAttributes
|
||||
return ArticleAttribute::find($id);
|
||||
}
|
||||
|
||||
public static function storeAttributes($article_price_id, $attributes)
|
||||
{
|
||||
foreach ($attributes as $key => $attribute)
|
||||
{
|
||||
$attributes[$key]['article_price_id'] = $article_price_id;
|
||||
unset($attributes[$key]['attribute_family_id']);
|
||||
self::store($attributes[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
|
||||
@@ -13,42 +13,65 @@ use App\Models\Shop\ArticlePrice;
|
||||
class ArticlePrices
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = ArticlePrice::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
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 getAll()
|
||||
{
|
||||
return ArticlePrice::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return ArticlePrice::find($id);
|
||||
}
|
||||
public static function get($id)
|
||||
{
|
||||
return ArticlePrice::find($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 storePrices($article_id, $prices)
|
||||
{
|
||||
if ($prices) {
|
||||
foreach ($prices as $$key => $price) {
|
||||
$prices[$key]['article_id'] = $article_id;
|
||||
self::store($prices[$key]);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return ArticlePrice::create($data);
|
||||
}
|
||||
public static function storeAttributes($article_price_id,$attributes)
|
||||
{
|
||||
return ArticleAttributes::storeAttributes($article_price_id, $attributes);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return ArticlePrice::find($id)->update($data);
|
||||
}
|
||||
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 destroy($id)
|
||||
{
|
||||
return ArticlePrice::destroy($id);
|
||||
}
|
||||
public static function create($data)
|
||||
{
|
||||
return ArticlePrice::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return ArticlePrice::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return ArticlePrice::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,37 @@ class Articles
|
||||
return Article::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$article = Articles::get($id);
|
||||
$data = $article->toArray();
|
||||
$data['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['tags'] = self::getTagsByArticle($article);
|
||||
$data = self::getMeta($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getMeta($data = [])
|
||||
{
|
||||
$data['categories_options'] = Categories::getOptions();
|
||||
$data['families_options'] = ArticleFamilies::getOptions();
|
||||
$data['taxes_options'] = Taxes::getOptions();
|
||||
$data['attribute_families_options'] = ArticleAttributeFamilies::getOptions();
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
$data['models_options'] = ['App\Models\Botanic\Specie' => 'Espèces', 'App\Models\Botanic\Variety' => 'Variétés'];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getCategoriesByArticle($article)
|
||||
{
|
||||
return $article->categories->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getTagsByArticle($article)
|
||||
{
|
||||
return $article->tags->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Article::find($id);
|
||||
@@ -32,8 +63,7 @@ class Articles
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
return $id ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
@@ -41,9 +71,12 @@ class Articles
|
||||
return Article::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
return Article::find($id)->update($data);
|
||||
$id = $id ? $id : $data['id'];
|
||||
$article = Article::find($id);
|
||||
$ret = $article->update($data);
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
@@ -51,14 +84,57 @@ class Articles
|
||||
return Article::destroy($id);
|
||||
}
|
||||
|
||||
public static function storeCategories($article, $categories)
|
||||
{
|
||||
if ($categories)
|
||||
{
|
||||
$categories = collect($categories)->transform(function ($item, $key) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
return $article->attachCategories($categories);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
public static function storeTags($article, $tags)
|
||||
{
|
||||
if ($tags)
|
||||
{
|
||||
return $article->attachTags($tags);
|
||||
}
|
||||
}
|
||||
|
||||
public static function storePrices($article, $prices)
|
||||
{
|
||||
return ArticlePrices::storePrices($article->id, $prices);
|
||||
}
|
||||
|
||||
public static function storeImages($article, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
self::storeImage($article, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeImage($article, $file)
|
||||
{
|
||||
return $article->addMedia($file)->withResponsiveImages()->toMediaCollection('images');
|
||||
}
|
||||
|
||||
public static function getImages($id)
|
||||
{
|
||||
$variety = self::get($id);
|
||||
$variety->getMedia();
|
||||
foreach ($variety->media as $key => $media) {
|
||||
$variety->media[$key]['url'] = $media->getUrl();
|
||||
$article = self::get($id);
|
||||
if ($article)
|
||||
{
|
||||
$article->getMedia();
|
||||
foreach ($article->media as $key => $media) {
|
||||
$article->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $article->media;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return $variety->media;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -43,11 +43,19 @@ class Tags
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Tag::create($data);
|
||||
$tag = app('rinvex.tags.tag')->create(['name' => ['fr' => $data['name']]]);
|
||||
$tag2 = Tag::find($tag->id);
|
||||
$tag2->tag_group_id = $data['tag_group_id'];
|
||||
$tag2->sort_order = self::getNewOrder($data['tag_group_id']);
|
||||
$tag2->save();
|
||||
// return app('rinvex.tags.tag')->createByName($data['name']);
|
||||
// return Tag::create($data);
|
||||
return $tag;
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
return Tag::find($id)->update($data);
|
||||
}
|
||||
|
||||
@@ -56,4 +64,9 @@ class Tags
|
||||
return Tag::destroy($id);
|
||||
}
|
||||
|
||||
public static function getNewOrder($tag_group_id)
|
||||
{
|
||||
$tag = Tag::byGroup($tag_group_id)->orderBy('sort_order', 'desc')->first();
|
||||
return $tag ? (int) $tag->sort_order + 1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
58
app/Repositories/Shop/Taxes.php
Normal file
58
app/Repositories/Shop/Taxes.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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\Tax;
|
||||
|
||||
class Taxes
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Tax::orderBy('value','asc')->get()->pluck('value','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Tax::orderBy('value','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Tax::find($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)
|
||||
{
|
||||
return Tax::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return Tax::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Tax::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user