Attributes

This commit is contained in:
Ludovic CANDELLIER
2020-05-05 19:07:11 +02:00
parent d7917309ee
commit d0e3bb6251
11 changed files with 144 additions and 45 deletions

View File

@@ -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'),
];
}
}

View File

@@ -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'),
];
}
}

View File

@@ -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
{

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Http\Controllers\Shop\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\ArticleAttributeValues;
use App\DataTables\Shop\ArticleAttributeValuesDataTable;
class ArticleAttributeValueController extends Controller
{
public function index(ArticleAttributeValuesDataTable $dataTable)
{
return $dataTable->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);
}
}

View File

@@ -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);

View File

@@ -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');
}

View File

@@ -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');
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class ArticleAttributeFamily extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_article_attribute_families';
public function Values()
{
return $this->hasMany('App\Models\Shop\ArticleAttributeValue','attribute_family_id');
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class ArticleAttributeValue extends Model
{
protected $guarded = ['id'];
protected $table = 'shop_article_attribute_values';
public function attribute_family()
{
return $this->belongsTo('App\Models\Shop\ArticleAttributeFamily');
}
}

View File

@@ -0,0 +1,4 @@
<?php
Route::resource('ArticleAttributeValues', 'ArticleAttributeValueController');

View File

@@ -3,6 +3,7 @@
Route::middleware('auth')->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');