From d0e3bb6251df9b63629a281ea164c249014cf012 Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Tue, 5 May 2020 19:07:11 +0200 Subject: [PATCH] Attributes --- .../ArticleAttributeFamiliesDataTable.php | 34 +++++------ .../Shop/ArticleAttributeValuesDataTable.php | 34 +++++------ .../ArticleAttributeFamilyController.php | 3 +- .../Admin/ArticleAttributeValueController.php | 56 +++++++++++++++++++ app/Menu/Shop.php | 6 +- app/Models/Shop/Article.php | 2 +- app/Models/Shop/ArticleAttribute.php | 16 +++--- app/Models/Shop/ArticleAttributeFamily.php | 17 ++++++ app/Models/Shop/ArticleAttributeValue.php | 16 ++++++ routes/Shop/Admin/ArticleAttributeValues.php | 4 ++ routes/Shop/Admin/route.php | 1 + 11 files changed, 144 insertions(+), 45 deletions(-) create mode 100644 app/Http/Controllers/Shop/Admin/ArticleAttributeValueController.php create mode 100644 app/Models/Shop/ArticleAttributeFamily.php create mode 100644 app/Models/Shop/ArticleAttributeValue.php create mode 100644 routes/Shop/Admin/ArticleAttributeValues.php diff --git a/app/DataTables/Shop/ArticleAttributeFamiliesDataTable.php b/app/DataTables/Shop/ArticleAttributeFamiliesDataTable.php index 8602fec6..0bdacf97 100644 --- a/app/DataTables/Shop/ArticleAttributeFamiliesDataTable.php +++ b/app/DataTables/Shop/ArticleAttributeFamiliesDataTable.php @@ -8,23 +8,25 @@ use App\Models\Shop\ArticleAttributeFamily; class ArticleAttributeFamiliesDataTable extends DataTable { - public $model_name = 'ArticleAttributeFamilies'; + public $model_name = 'ArticleAttributeFamilies'; - public function query(ArticleFamily $model) - { - return self::buildQuery($model); - } + public function query(ArticleAttributeFamily $model) + { + $model = $model::withCount(['values']); + return self::buildQuery($model); + } - protected function getColumns() - { - return [ - Column::make('name'), - Column::computed('action') - ->exportable(false) - ->printable(false) - ->width(120) - ->addClass('text-center'), - ]; - } + protected function getColumns() + { + return [ + Column::make('name'), + Column::make('values_count')->title('Nb valeurs')->searchable(false), + Column::computed('action') + ->exportable(false) + ->printable(false) + ->width(120) + ->addClass('text-center'), + ]; + } } diff --git a/app/DataTables/Shop/ArticleAttributeValuesDataTable.php b/app/DataTables/Shop/ArticleAttributeValuesDataTable.php index 7ad0a8f4..18f99bbc 100644 --- a/app/DataTables/Shop/ArticleAttributeValuesDataTable.php +++ b/app/DataTables/Shop/ArticleAttributeValuesDataTable.php @@ -8,23 +8,25 @@ use App\Models\Shop\ArticleAttributeValue; class ArticleAttributeValuesDataTable extends DataTable { - public $model_name = 'ArticleAttributeValues'; + public $model_name = 'ArticleAttributeValues'; - public function query(ArticleFamily $model) - { - return self::buildQuery($model); - } + public function query(ArticleAttributeValue $model) + { + $model = $model::with(['attribute_family']); + return self::buildQuery($model); + } - protected function getColumns() - { - return [ - Column::make('name'), - Column::computed('action') - ->exportable(false) - ->printable(false) - ->width(120) - ->addClass('text-center'), - ]; - } + protected function getColumns() + { + return [ + Column::make('attribute_family.name')->title('Famille d\'attributs'), + Column::make('value'), + Column::computed('action') + ->exportable(false) + ->printable(false) + ->width(120) + ->addClass('text-center'), + ]; + } } diff --git a/app/Http/Controllers/Shop/Admin/ArticleAttributeFamilyController.php b/app/Http/Controllers/Shop/Admin/ArticleAttributeFamilyController.php index c5e3a35d..98a0a7bb 100644 --- a/app/Http/Controllers/Shop/Admin/ArticleAttributeFamilyController.php +++ b/app/Http/Controllers/Shop/Admin/ArticleAttributeFamilyController.php @@ -5,7 +5,8 @@ namespace App\Http\Controllers\Shop\Admin; use Illuminate\Http\Request; use App\Http\Controllers\Controller; -use App\Model\Shop\ArticleAttributeFamily; +use App\Repositories\Shop\ArticleAttributeFamilies; +use App\DataTables\Shop\ArticleAttributeFamiliesDataTable; class ArticleAttributeFamilyController extends Controller { diff --git a/app/Http/Controllers/Shop/Admin/ArticleAttributeValueController.php b/app/Http/Controllers/Shop/Admin/ArticleAttributeValueController.php new file mode 100644 index 00000000..6595c8e9 --- /dev/null +++ b/app/Http/Controllers/Shop/Admin/ArticleAttributeValueController.php @@ -0,0 +1,56 @@ +render('Shop.Admin.ArticleAttributeValues.list'); + } + + public function getDatatable(Request $request) + { + return ArticleAttributeValues::getTables($request->all()); + } + + public function create() + { + return view('Shop.Admin.ArticleAttributeValues.create'); + } + + public function store(Request $request) + { + $ret = ArticleAttributeValues::store($request->all()); + return redirect()->route('Shop.Admin.ArticleAttributeValues.index'); + } + + public function show($id) + { + $data = ArticleAttributeValues::get($id); + return view('Shop.Admin.ArticleAttributeValues.view', $data); + } + + public function edit($id) + { + $data = ArticleAttributeValues::get($id); + return view('Shop.Admin.ArticleAttributeValues.edit', $data); + } + + public function update(Request $request) + { + // + } + + public function destroy($id) + { + return ArticleAttributeValues::destroy($id); + } + +} diff --git a/app/Menu/Shop.php b/app/Menu/Shop.php index f880f946..7c9cf817 100644 --- a/app/Menu/Shop.php +++ b/app/Menu/Shop.php @@ -21,10 +21,10 @@ class Shop ->activeIfRoute(['Shop.Admin.Articles.*'])->order(2); $menu->addTo('shop', 'Familles d\'articles', [ 'route' => 'Shop.Admin.ArticleFamilies.index', 'permission' => 'backend_access' ]) ->activeIfRoute(['Shop.Admin.ArticleFamilies.*'])->order(3); - $menu->addTo('shop', 'Familles d\'attributs d\'articles', [ 'route' => 'Shop.Admin.ArticleAttributeFamilies.index', 'permission' => 'backend_access' ]) + $menu->addTo('shop', 'Familles d\'attributs', [ 'route' => 'Shop.Admin.ArticleAttributeFamilies.index', 'permission' => 'backend_access' ]) ->activeIfRoute(['Shop.Admin.ArticleAttributeFamilies.*'])->order(4); - $menu->addTo('shop', 'Attributs d\'articles', [ 'route' => 'Shop.Admin.ArticleAttributes.index', 'permission' => 'backend_access' ]) - ->activeIfRoute(['Shop.Admin.ArticleAttributes.*'])->order(5); + $menu->addTo('shop', 'Attributs', [ 'route' => 'Shop.Admin.ArticleAttributeValues.index', 'permission' => 'backend_access' ]) + ->activeIfRoute(['Shop.Admin.ArticleAttributeValues.*'])->order(5); $menu->addTo('shop', 'Commandes', [ 'route' => 'Shop.Admin.Orders.index', 'permission' => 'backend_access' ]) ->activeIfRoute(['Shop.Admin.Orders.*'])->order(6); diff --git a/app/Models/Shop/Article.php b/app/Models/Shop/Article.php index f60d917c..ef6cd45a 100644 --- a/app/Models/Shop/Article.php +++ b/app/Models/Shop/Article.php @@ -30,7 +30,7 @@ class Article extends Model return $this->hasMany('App\Models\Shop\ArticlePrice'); } - public function ProductAttributes() + public function ArticleAttributes() { return $this->hasMany('App\Models\Shop\ArticleAttribute'); } diff --git a/app/Models/Shop/ArticleAttribute.php b/app/Models/Shop/ArticleAttribute.php index 951a0111..3f1a09d3 100644 --- a/app/Models/Shop/ArticleAttribute.php +++ b/app/Models/Shop/ArticleAttribute.php @@ -6,13 +6,13 @@ use Illuminate\Database\Eloquent\Relations\Pivot; class ArticleAttribute extends Pivot { - public function Article() - { - return $this->belongsTo('App\Models\Shop\Article'); - } + public function article() + { + return $this->belongsTo('App\Models\Shop\Article'); + } - public function Attribute() - { - return $this->belongsTo('App\Models\Shop\ArticleAttribute'); - } + public function value() + { + return $this->belongsTo('App\Models\Shop\ArticleAttribute'); + } } \ No newline at end of file diff --git a/app/Models/Shop/ArticleAttributeFamily.php b/app/Models/Shop/ArticleAttributeFamily.php new file mode 100644 index 00000000..3d634845 --- /dev/null +++ b/app/Models/Shop/ArticleAttributeFamily.php @@ -0,0 +1,17 @@ +hasMany('App\Models\Shop\ArticleAttributeValue','attribute_family_id'); + } + +} \ No newline at end of file diff --git a/app/Models/Shop/ArticleAttributeValue.php b/app/Models/Shop/ArticleAttributeValue.php new file mode 100644 index 00000000..8450e1f4 --- /dev/null +++ b/app/Models/Shop/ArticleAttributeValue.php @@ -0,0 +1,16 @@ +belongsTo('App\Models\Shop\ArticleAttributeFamily'); + } +} \ No newline at end of file diff --git a/routes/Shop/Admin/ArticleAttributeValues.php b/routes/Shop/Admin/ArticleAttributeValues.php new file mode 100644 index 00000000..30136c47 --- /dev/null +++ b/routes/Shop/Admin/ArticleAttributeValues.php @@ -0,0 +1,4 @@ +prefix('Admin')->namespace('Admin')->name('Admin.')->group(function () { Route::get('dashboard', 'DashboardController@index')->name('dashboard'); include( __DIR__ . '/ArticleAttributeFamilies.php'); + include( __DIR__ . '/ArticleAttributeValues.php'); include( __DIR__ . '/ArticleAttributes.php'); include( __DIR__ . '/ArticleFamilies.php'); include( __DIR__ . '/ArticlePrices.php');