diff --git a/app/Datatables/Shop/ArticlesDataTable.php b/app/Datatables/Shop/ArticlesDataTable.php index 82fdff43..9a56945c 100644 --- a/app/Datatables/Shop/ArticlesDataTable.php +++ b/app/Datatables/Shop/ArticlesDataTable.php @@ -3,18 +3,20 @@ namespace App\Datatables\Shop; use Yajra\DataTables\Html\Column; + use App\Datatables\ParentDataTable as DataTable; use App\Models\Shop\Article; class ArticlesDataTable extends DataTable { public $model_name = 'articles'; + public $sortedColumn = 1; public function query(Article $model) { // $model = $model::with('Family')->select('shop_articles.*','family.name as family_name')->join('shop_article_families as family', 'family.id', '=', 'shop_articles.article_family_id')->groupBy('shop_articles.id'); - $model = $model::with('article_nature')->select('shop_articles.*'); - // $model = $model::joinRelations('Family')->select('shop_articles.*','shop_article_families.name as family_name'); + // $model = $model::with('article_nature')->select('shop_articles.*'); + $model = $model::with('article_nature')->joinRelationship('article_nature')->select('shop_articles.*','shop_article_natures.name as nature_name'); $model = self::filterByArticleNature($model); return self::buildQuery($model); } @@ -28,7 +30,7 @@ class ArticlesDataTable extends DataTable protected function getColumns() { return [ - Column::make('article_nature.name')->title('Nature')->orderable(false), + Column::make('article_nature.name')->data('nature_name')->title('Nature'), Column::make('name')->title('Nom'), self::makeColumnButtons(), ]; diff --git a/app/Http/Controllers/Admin/Shop/ArticleController.php b/app/Http/Controllers/Admin/Shop/ArticleController.php index 1307a49f..54dbee3f 100644 --- a/app/Http/Controllers/Admin/Shop/ArticleController.php +++ b/app/Http/Controllers/Admin/Shop/ArticleController.php @@ -45,6 +45,8 @@ class ArticleController extends Controller public function edit($id) { $data = Articles::getFull($id); + // dump($data); + // exit; return view('Admin.Shop.Articles.edit', $data); } @@ -53,6 +55,24 @@ class ArticleController extends Controller return Articles::destroy($id); } + public function getProductDescription($product_id, $model) + { + $data['article']['inherited'] = Articles::getInheritedByProduct($product_id, base64_decode($model)); + return view('Admin.Shop.Articles.partials.product.description', $data); + } + + public function getProductTags($product_id, $model) + { + $data = Articles::getInheritedByProduct($product_id, base64_decode($model)); + return view('Admin.Shop.Articles.partials.product.tags', $data); + } + + public function getProductImages($product_id, $model) + { + $data = Articles::getInheritedByProduct($product_id, base64_decode($model)); + return view('Admin.Shop.Articles.partials.product.images', $data); + } + public function getImages(Request $request, $id = false) { $id = $id ? $id : $request->input('id'); diff --git a/app/Http/Controllers/Admin/Shop/CategoryController.php b/app/Http/Controllers/Admin/Shop/CategoryController.php index 9e47c18c..3d44c1cb 100644 --- a/app/Http/Controllers/Admin/Shop/CategoryController.php +++ b/app/Http/Controllers/Admin/Shop/CategoryController.php @@ -31,7 +31,7 @@ class CategoryController extends Controller public function store(Request $request) { - $ret = Categories::store($request->all()); + $ret = Categories::storeFull($request->all()); return redirect()->route('Admin.Shop.Categories.index'); } diff --git a/app/Models/Shop/Article.php b/app/Models/Shop/Article.php index 29082561..43900dfd 100644 --- a/app/Models/Shop/Article.php +++ b/app/Models/Shop/Article.php @@ -14,12 +14,13 @@ use Spatie\MediaLibrary\MediaCollections\Models\Media; use BeyondCode\Comments\Traits\HasComments; use Rinvex\Categories\Traits\Categorizable; use Rinvex\Tags\Traits\Taggable; +use Kirschbaum\PowerJoins\PowerJoins; use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin; use Wildside\Userstamps\Userstamps; class Article extends Model implements HasMedia { - use Categorizable, EloquentJoin, HasComments, InteractsWithMedia, Taggable, SoftDeletes, UserStamps; + use Categorizable, EloquentJoin, HasComments, InteractsWithMedia, Powerjoins, Taggable, SoftDeletes, UserStamps; protected $guarded = ['id']; protected $table = 'shop_articles'; diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index d20452f5..e34ba989 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -35,7 +35,7 @@ class Articles public static function getArticle($id) { - $article = Article::with('product.tags')->findOrFail($id); + $article = self::get($id); $data = $article->toArray(); $data['inherited'] = self::getInherited($id); $data['categories'] = self::getCategoriesNameByArticle($article); @@ -53,7 +53,7 @@ class Articles public static function getArticleEdit($id) { - $article = Article::with('product.tags')->findOrFail($id); + $article = self::get($id); $data = $article->toArray(); $data['inherited'] = self::getInherited($id); $data['categories'] = self::getCategoriesByArticle($article); @@ -81,6 +81,26 @@ class Articles return $data; } + public static function getInheritedByProduct($product_id, $product_type) + { + switch ($product_type) { + case 'App\Models\Botanic\Variety': + $product = Varieties::get($product_id); + $data[] = ['name' => 'Espèces', 'description' => Species::getDescription($product->specie_id), 'tags' => Species::getTags($product->specie_id)]; + $data[] = ['name' => 'Variétés', 'description' => $product->description, 'tags' => $product->tags->toArray()]; + break; + case 'App\Models\Botanic\Specie': + $product = Species::get($product_id); + $data[] = ['name' => 'Espèces', 'description' => $product->description, 'tags' => $product->tags->toArray()]; + break; + case 'App\Models\Shop\Merchandise': + $product = Merchandises::get($product_id); + $data[] = ['name' => 'Marchandise', 'description' => $product->description, 'tags' => $product->tags->toArray()]; + break; + } + return $data; + } + public static function getMeta(&$data = []) { $data['products'] = (($data['article']['product_type'] ?? false) == 'App\Models\Botanic\Variety') ? Varieties::getOptionsWithSpecie() : Species::getOptions(); diff --git a/app/Repositories/Shop/Categories.php b/app/Repositories/Shop/Categories.php index b7be28f0..ef5484f9 100644 --- a/app/Repositories/Shop/Categories.php +++ b/app/Repositories/Shop/Categories.php @@ -28,10 +28,10 @@ class Categories public static function storeFull($data) { - $images = isset($data['images']) ? $data['images'] : false; + $images = $data['images'] ?? false; unset($data['images']); - $tags = isset($data['tags']) ? $data['tags'] : false; + $tags = $data['tags'] ?? false; unset($data['tags']); $category = self::store($data); @@ -54,6 +54,7 @@ class Categories return (int) $item; } )->toArray(); + return $category->syncTags($tags, true); } else { return false; diff --git a/app/Repositories/Shop/CategoryTrees.php b/app/Repositories/Shop/CategoryTrees.php index d31ad4e2..55d6c2b8 100644 --- a/app/Repositories/Shop/CategoryTrees.php +++ b/app/Repositories/Shop/CategoryTrees.php @@ -33,11 +33,11 @@ class CategoryTrees switch ($type) { case 'after': - dump("$node_id After $target_id"); + // dump("$node_id After $target_id"); $category->afterNode($category_target); break; case 'inside': - dump("$node_id inside $target_id"); + // dump("$node_id inside $target_id"); $category_target->appendNode($category); break; } diff --git a/resources/views/Admin/Shop/Articles/partials/characteristics.blade.php b/resources/views/Admin/Shop/Articles/partials/characteristics.blade.php index 89c4c362..9a08a717 100644 --- a/resources/views/Admin/Shop/Articles/partials/characteristics.blade.php +++ b/resources/views/Admin/Shop/Articles/partials/characteristics.blade.php @@ -23,7 +23,7 @@