Add plus on products

This commit is contained in:
Ludovic CANDELLIER
2022-04-25 20:02:28 +02:00
parent ee0954931f
commit 3c8fab27da
15 changed files with 263 additions and 47 deletions

View File

@@ -4,16 +4,16 @@ namespace App\Datatables\Shop;
use Yajra\DataTables\Html\Column; use Yajra\DataTables\Html\Column;
use App\Datatables\ParentDataTable as DataTable; use App\Datatables\ParentDataTable as DataTable;
use App\Models\Shop\Merchandise; use App\Models\Shop\Producer;
use App\Repositories\Shop\Merchandises; use App\Repositories\Shop\Producers;
class MerchandisesDataTable extends DataTable class ProducersDataTable extends DataTable
{ {
public $model_name = 'merchandises'; public $model_name = 'producers';
public function query(Merchandise $model) public function query(Producer $model)
{ {
$model = $model::with(['image', 'tags'])->withCount(['Articles', 'tags', 'images']); $model = $model::with(['image', 'tags'])->withCount(['Merchandises', 'tags', 'images']);
return $this->buildQuery($model); return $this->buildQuery($model);
} }
@@ -21,12 +21,12 @@ class MerchandisesDataTable extends DataTable
public function modifier($datatables) public function modifier($datatables)
{ {
$datatables $datatables
->editColumn('thumb', function (Merchandise $merchandise) { ->editColumn('thumb', function (Producer $producer) {
return Merchandises::getThumb($merchandise->image); return $producer->image ? Producers::getThumb($producer->image) : '';
}) })
->editColumn('tags2', function (Merchandise $merchandise) { ->editColumn('tags2', function (Producer $producer) {
$html = ''; $html = '';
foreach ($merchandise->tags as $tag) { foreach ($producer->tags as $tag) {
$html .= '<span class="btn btn-xs btn-secondary pb-2">' . $tag->slug . '</span> '; $html .= '<span class="btn btn-xs btn-secondary pb-2">' . $tag->slug . '</span> ';
} }
return $html; return $html;
@@ -42,7 +42,7 @@ class MerchandisesDataTable extends DataTable
Column::make('thumb')->title('')->searchable(false)->orderable(false)->width(40)->class('text-center'), Column::make('thumb')->title('')->searchable(false)->orderable(false)->width(40)->class('text-center'),
Column::make('name')->title('Nom'), Column::make('name')->title('Nom'),
Column::make('tags2')->title('Tags')->searchable(false)->orderable(false), Column::make('tags2')->title('Tags')->searchable(false)->orderable(false),
Column::make('articles_count')->title('#Art')->class('text-right')->searchable(false), Column::make('merchandises_count')->title('#Mar')->class('text-right')->searchable(false),
Column::make('tags_count')->title('#Tag')->class('text-right')->searchable(false), Column::make('tags_count')->title('#Tag')->class('text-right')->searchable(false),
Column::make('images_count')->title('#Pho')->class('text-right')->searchable(false), Column::make('images_count')->title('#Pho')->class('text-right')->searchable(false),
$this->makeColumnButtons(), $this->makeColumnButtons(),

View File

@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin\Shop;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Repositories\Shop\Merchandises; use App\Repositories\Shop\Merchandises;
use App\Repositories\Shop\Producers;
use App\Repositories\Shop\TagGroups; use App\Repositories\Shop\TagGroups;
use App\Datatables\Shop\MerchandisesDataTable; use App\Datatables\Shop\MerchandisesDataTable;
@@ -19,6 +20,7 @@ class MerchandiseController extends Controller
public function create() public function create()
{ {
$data['producers_list'] = Producers::getOptions();
$data['tags_list'] = TagGroups::getTreeTags(); $data['tags_list'] = TagGroups::getTreeTags();
return view('Admin.Shop.Merchandises.create', $data); return view('Admin.Shop.Merchandises.create', $data);
} }
@@ -38,6 +40,7 @@ class MerchandiseController extends Controller
public function edit($id) public function edit($id)
{ {
$data['merchandise'] = Merchandises::getFull($id); $data['merchandise'] = Merchandises::getFull($id);
$data['producers_list'] = Producers::getOptions();
$data['tags_list'] = TagGroups::getTreeTags(); $data['tags_list'] = TagGroups::getTreeTags();
return view('Admin.Shop.Merchandises.edit', $data); return view('Admin.Shop.Merchandises.edit', $data);
} }

View File

@@ -20,7 +20,7 @@ class LoginController extends Controller
public function showLoginForm() public function showLoginForm()
{ {
return view('Shop.auth.login', $data ?? []); return view('auth.login', $data ?? []);
} }
public function authenticated(Request $request, $user) public function authenticated(Request $request, $user)

View File

@@ -14,6 +14,10 @@ class Merchandises
$menu->addTo('merchandises', __('Marchandises'), [ $menu->addTo('merchandises', __('Marchandises'), [
'route' => 'Admin.Shop.Merchandises.index', 'route' => 'Admin.Shop.Merchandises.index',
])->activeIfRoute(['Admin.Shop.Merchandises.*'])->order(1); ])->activeIfRoute(['Admin.Shop.Merchandises.*'])->order(1);
$menu->addTo('merchandises', __('Producteurs'), [
'route' => 'Admin.Shop.Producers.index',
])->activeIfRoute(['Admin.Shop.Producers.*'])->order(1);
} }
} }

View File

@@ -10,6 +10,8 @@ use Rinvex\Tags\Traits\Taggable;
use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\HasMedia;
use App\Traits\Model\Imageable; use App\Traits\Model\Imageable;
use App\Models\Shop\Tag;
use App\Models\Shop\Article;
class Specie extends Model implements HasMedia class Specie extends Model implements HasMedia
{ {
@@ -20,7 +22,7 @@ class Specie extends Model implements HasMedia
public function tags() public function tags()
{ {
return $this->morphToMany('App\Models\Shop\Tag', 'taggable'); return $this->morphToMany(Tag::class, 'taggable');
} }
public function Genre() public function Genre()
@@ -35,7 +37,7 @@ class Specie extends Model implements HasMedia
public function Articles() public function Articles()
{ {
return $this->morphMany('App\Models\Shop\Article', 'product'); return $this->morphMany(Article::class, 'product');
} }
public function scopeByName($query, $name) public function scopeByName($query, $name)

View File

@@ -12,6 +12,9 @@ use Wildside\Userstamps\Userstamps;
use App\Traits\Model\Imageable; use App\Traits\Model\Imageable;
use App\Models\Shop\Article;
use App\Models\Shop\Tag;
class Variety extends Model implements HasMedia class Variety extends Model implements HasMedia
{ {
use Imageable, PowerJoins, SoftDeletes, Taggable, UserStamps; use Imageable, PowerJoins, SoftDeletes, Taggable, UserStamps;
@@ -21,16 +24,16 @@ class Variety extends Model implements HasMedia
public function Specie() public function Specie()
{ {
return $this->belongsTo('App\Models\Botanic\Specie'); return $this->belongsTo(Specie::class);
} }
public function Articles() public function Articles()
{ {
return $this->morphMany('App\Models\Shop\Article', 'product'); return $this->morphMany(Article::class, 'product');
} }
public function tags() public function tags()
{ {
return $this->morphToMany('App\Models\Shop\Tag', 'taggable'); return $this->morphToMany(Tag::class, 'taggable');
} }
} }

View File

@@ -19,9 +19,14 @@ class Producer extends Model implements HasMedia
protected $guarded = ['id']; protected $guarded = ['id'];
protected $table = 'shop_producers'; protected $table = 'shop_producers';
public function Articles()
{
}
public function Merchandises() public function Merchandises()
{ {
return $this->morphMany(Article::class, 'product'); return $this->hasMany(Merchandise::class);
} }
public function tags() public function tags()

View File

@@ -0,0 +1,95 @@
<?php
namespace App\Repositories\Shop;
use App\Repositories\Core\Tag;
use App\Models\Shop\Producer;
use App\Traits\Repository\Imageable;
class Producers
{
use Imageable;
public static function autocomplete($str)
{
$data = Producer::byAutocomplete($str)->orderBy('name')->limit(30)->get()->pluck('name', 'id');
$export = [];
foreach ($data as $key => $name) {
$export[] = ['value' => $key, 'text' => $name];
}
return $export;
}
public static function getTags($id)
{
return self::get($id)->tags;
}
public static function storeTags($variety, $tags)
{
return Tag::storeTags($variety, $tags);
}
public static function getOptions()
{
return Producer::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
}
public static function getAll()
{
return Producer::orderBy('name', 'asc')->get();
}
public static function get($id)
{
return Producer::find($id);
}
public static function getFull($id)
{
$producer = self::get($id);
$data = $producer->toArray();
$data['tags'] = self::getTagsByProducer($producer);
return $data;
}
public static function getTagsByProducer($producer)
{
return Tag::getTagsByModel($producer);
}
public static function storeFull($data)
{
$images = $data['images'] ?? false;
$tags = $data['tags'] ?? false;
unset($data['images']);
unset($data['tags']);
$producer = self::store($data);
self::storeImages($producer, $images);
self::storeTags($producer, $tags);
return $producer;
}
public static function store($data)
{
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
}
public static function create($data)
{
return Producer::create($data);
}
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}
public static function destroy($id)
{
return Producer::destroy($id);
}
}

View File

@@ -14,7 +14,14 @@
<div class="row mb-3"> <div class="row mb-3">
<div class="col-6"> <div class="col-6">
{{ Form::label('genre', 'Genre') }} {{ Form::label('genre', 'Genre') }}
@include('components.form.select', ['name' => 'genre_id', 'list' => $genres, 'value' => $specie['genre_id'] ?? null, 'class' => 'select2', 'with_empty' => '', 'required' => false]) @include('components.form.select', [
'name' => 'genre_id',
'list' => $genres,
'value' => $specie['genre_id'] ?? null,
'class' => 'select2',
'with_empty' => '',
'required' => false
])
</div> </div>
<div class="col-6"> <div class="col-6">
{{ Form::label('alias', 'Alias') }} {{ Form::label('alias', 'Alias') }}
@@ -25,21 +32,49 @@
<div class="row mb-3"> <div class="row mb-3">
<div class="col-12"> <div class="col-12">
{{ Form::label('tags', 'Tags') }} {{ Form::label('tags', 'Tags') }}
@include('components.form.selects.select-tree', ['name' => 'tags[]', 'list' => $tags_list, 'values' => $specie['tags'] ?? null, 'class' => 'select2 form-control', 'multiple' => true]) @include('components.form.selects.select-tree', [
'name' => 'tags[]',
'list' => $tags_list,
'values' => $specie['tags'] ?? null,
'class' => 'select2 form-control',
'multiple' => true
])
</div> </div>
</div> </div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-12"> <div class="col-12">
{{ Form::label('description', 'Description') }} {{ Form::label('description', 'Description') }}
@include('components.form.textarea', ['name' => 'description', 'value' => $specie['description'] ?? null, 'class' => 'editor', 'required' => false]) @include('components.form.textarea', [
'name' => 'description',
'value' => $specie['description'] ?? null,
'class' => 'editor',
'required' => false
])
</div>
</div>
<div class="row mb-3">
<div class="col-12">
{{ Form::label('description', 'Son +') }}
@include('components.form.textarea', [
'name' => 'plus',
'value' => $specie['plus'] ?? null,
'class' => 'editor',
'rows' => 5,
'required' => false,
])
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
@include('components.uploader.widget', ['load_url' => ($specie['id'] ?? false) ? route('Admin.Botanic.Species.getImages', ['id' => $specie['id']]) : null, 'delete_url' => route('Admin.Botanic.Species.deleteImage'), 'name' => 'images']) @include('components.uploader.widget', [
'load_url' => ($specie['id'] ?? false) ? route('Admin.Botanic.Species.getImages', ['id' => $specie['id']]) : null,
'delete_url' => route('Admin.Botanic.Species.deleteImage'),
'name' => 'images'
])
</div> </div>
</div> </div>

View File

@@ -7,35 +7,77 @@
</div> </div>
<div class="col-6"> <div class="col-6">
{{ Form::label('genre', 'Espèce') }} {{ Form::label('genre', 'Espèce') }}
@include('components.form.select', ['name' => 'specie_id', 'list' => $species, 'value' => $variety['specie_id'] ?? null, 'class' => 'select2 form-control', 'with_empty' => '', 'required' => false]) @include('components.form.select', [
'name' => 'specie_id',
'list' => $species,
'value' => $variety['specie_id'] ?? null,
'class' => 'select2 form-control',
'with_empty' => '',
'required' => false
])
</div> </div>
</div> </div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-12"> <div class="col-12">
{{ Form::label('tags', 'Tags') }} {{ Form::label('tags', 'Tags') }}
@include('components.form.selects.select-tree', ['name' => 'tags[]', 'list' => $tags_list, 'values' => $variety['tags'] ?? null, 'class' => 'select2 form-control', 'multiple' => true]) @include('components.form.selects.select-tree', [
'name' => 'tags[]',
'list' => $tags_list,
'values' => $variety['tags'] ?? null,
'class' => 'select2 form-control',
'multiple' => true
])
</div> </div>
</div> </div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-12"> <div class="col-12">
{{ Form::label('description', 'Description') }} {{ Form::label('description', 'Description') }}
@include('components.form.textarea', ['name' => 'description', 'value' => $variety['description'] ?? null, 'class' => 'editor', 'rows' => 5, 'required' => false]) @include('components.form.textarea', [
'name' => 'description',
'value' => $variety['description'] ?? null,
'class' => 'editor',
'rows' => 5,
'required' => false
])
</div> </div>
</div> </div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-12"> <div class="col-12">
{{ Form::label('memo', 'Descriptif sachet') }} {{ Form::label('memo', 'Descriptif sachet') }}
@include('components.form.textarea', ['name' => 'memo', 'value' => $variety['memo'] ?? null, 'class' => 'editor', 'rows' => 5, 'required' => false]) @include('components.form.textarea', [
'name' => 'memo',
'value' => $variety['memo'] ?? null,
'class' => 'editor',
'rows' => 5,
'required' => false
])
</div>
</div>
<div class="row mb-3">
<div class="col-12">
{{ Form::label('description', 'Son +') }}
@include('components.form.textarea', [
'name' => 'plus',
'value' => $variety['plus'] ?? null,
'class' => 'editor',
'rows' => 5,
'required' => false,
])
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
@include('components.uploader.widget', ['load_url' => route('Admin.Botanic.Varieties.getImages', ['id' => $variety['id'] ?? false]), 'delete_url' => route('Admin.Botanic.Varieties.deleteImage'), 'name' => 'images']) @include('components.uploader.widget', [
'load_url' => route('Admin.Botanic.Varieties.getImages', ['id' => $variety['id'] ?? false]),
'delete_url' => route('Admin.Botanic.Varieties.deleteImage'),
'name' => 'images'
])
</div> </div>
</div> </div>

View File

@@ -5,6 +5,16 @@
{{ Form::label('name', 'Nom') }} {{ Form::label('name', 'Nom') }}
@include('components.form.input', ['name' => 'name', 'value' => $merchandise['name'] ?? null, 'required' => true]) @include('components.form.input', ['name' => 'name', 'value' => $merchandise['name'] ?? null, 'required' => true])
</div> </div>
<div class="col-6">
{{ Form::label('producers', 'Producteur') }}
@include('components.form.select', [
'name' => 'producer_id',
'list' => $producers_list ?? [],
'value' => $merchandise['provider_id'] ?? null,
'class' => 'select2 form-control',
'with_empty' => '',
])
</div>
</div> </div>
<div class="row mb-3"> <div class="row mb-3">
@@ -33,6 +43,19 @@
</div> </div>
</div> </div>
<div class="row mb-3">
<div class="col-12">
{{ Form::label('description', 'Son +') }}
@include('components.form.textarea', [
'name' => 'plus',
'value' => $merchandise['plus'] ?? null,
'class' => 'editor',
'rows' => 5,
'required' => false,
])
</div>
</div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">

View File

@@ -1,11 +1,11 @@
@extends('layout.index', [ @extends('layout.index', [
'title' => __('shop.merchandises.title'), 'title' => __('shop.producers.title'),
'subtitle' => __('shop.merchandises.add'), 'subtitle' => __('shop.producers.add'),
'breadcrumb' => [__('shop.merchandises.title'), __('shop.merchandises.add')] 'breadcrumb' => [__('shop.producers.title'), __('shop.producers.add')]
]) ])
@section('content') @section('content')
{{ Form::open(['route' => 'Admin.Shop.Merchandises.store', 'id' => 'form', 'autocomplete' => 'off', 'files' => true]) }} {{ Form::open(['route' => 'Admin.Shop.Producers.store', 'id' => 'form', 'autocomplete' => 'off', 'files' => true]) }}
@include('Admin.Shop.Merchandises.form') @include('Admin.Shop.Producers.form')
</form> </form>
@endsection @endsection

View File

@@ -1,12 +1,12 @@
@extends('layout.index', [ @extends('layout.index', [
'title' => __('Shop.merchandises.title'), 'title' => __('Shop.producers.title'),
'subtitle' => __('Shop.merchandises.edit'), 'subtitle' => __('Shop.producers.edit'),
'breadcrumb' => [__('Shop.merchandises.title'), __('Shop.merchandises.edit')] 'breadcrumb' => [__('Shop.producers.title'), __('Shop.producers.edit')]
]) ])
@section('content') @section('content')
{{ Form::open(['route' => 'Admin.Shop.Merchandises.store', 'id' => 'form', 'autocomplete' => 'off', 'files' => true]) }} {{ Form::open(['route' => 'Admin.Shop.Producers.store', 'id' => 'form', 'autocomplete' => 'off', 'files' => true]) }}
<input type="hidden" name="id" id="id" value="{{ $merchandise['id'] }}"> <input type="hidden" name="id" id="id" value="{{ $producer['id'] }}">
@include('Admin.Shop.Merchandises.form') @include('Admin.Shop.Producers.form')
</form> </form>
@endsection @endsection

View File

@@ -3,7 +3,11 @@
<div class="row mb-3"> <div class="row mb-3">
<div class="col-6"> <div class="col-6">
{{ Form::label('name', 'Nom') }} {{ Form::label('name', 'Nom') }}
@include('components.form.input', ['name' => 'name', 'value' => $merchandise['name'] ?? null, 'required' => true]) @include('components.form.input', ['name' => 'name', 'value' => $producer['name'] ?? null, 'required' => true])
</div>
<div class="col-6">
{{ Form::label('name', 'Alias') }}
@include('components.form.input', ['name' => 'alias', 'value' => $producer['alias'] ?? null, 'required' => true])
</div> </div>
</div> </div>
@@ -13,7 +17,7 @@
@include('components.form.selects.select-tree', [ @include('components.form.selects.select-tree', [
'name' => 'tags[]', 'name' => 'tags[]',
'list' => $tags_list, 'list' => $tags_list,
'values' => $merchandise['tags'] ?? null, 'values' => $producer['tags'] ?? null,
'class' => 'select2 form-control', 'class' => 'select2 form-control',
'multiple' => true 'multiple' => true
]) ])
@@ -25,7 +29,7 @@
{{ Form::label('description', 'Description') }} {{ Form::label('description', 'Description') }}
@include('components.form.textarea', [ @include('components.form.textarea', [
'name' => 'description', 'name' => 'description',
'value' => $merchandise['description'] ?? null, 'value' => $producer['description'] ?? null,
'class' => 'editor', 'class' => 'editor',
'rows' => 5, 'rows' => 5,
'required' => false, 'required' => false,
@@ -37,7 +41,7 @@
<div class="col-md-4"> <div class="col-md-4">
@include('components.uploader.widget', [ @include('components.uploader.widget', [
'load_url' => route('Admin.Shop.Merchandises.getImages', ['id' => $merchandise['id'] ?? false]), 'load_url' => route('Admin.Shop.Merchandises.getImages', ['id' => $producer['id'] ?? false]),
'delete_url' => route('Admin.Botanic.Varieties.deleteImage'), 'delete_url' => route('Admin.Botanic.Varieties.deleteImage'),
'name' => 'images', 'name' => 'images',
]) ])

View File

@@ -1,12 +1,12 @@
@extends('layout.index', [ @extends('layout.index', [
'title' => __('Marchandises'), 'title' => __('shop.producers.title'),
'subtitle' => __('Liste de marchandises'), 'subtitle' => __('shop.producers.list'),
'breadcrumb' => [__('Shop.merchandises.title')] 'breadcrumb' => [__('Shop.producers.title')]
]) ])
@section('content') @section('content')
@component('components.card') @component('components.card')
@include('components.datatable', ['route' => route('Admin.Shop.Merchandises.index'), 'model' => 'merchandises']) @include('components.datatable', ['route' => route('Admin.Shop.Producers.index'), 'model' => 'producers'])
@endcomponent @endcomponent
@endsection @endsection