Add plus on products
This commit is contained in:
@@ -4,16 +4,16 @@ namespace App\Datatables\Shop;
|
||||
|
||||
use Yajra\DataTables\Html\Column;
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Merchandise;
|
||||
use App\Repositories\Shop\Merchandises;
|
||||
use App\Models\Shop\Producer;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ class MerchandisesDataTable extends DataTable
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('thumb', function (Merchandise $merchandise) {
|
||||
return Merchandises::getThumb($merchandise->image);
|
||||
->editColumn('thumb', function (Producer $producer) {
|
||||
return $producer->image ? Producers::getThumb($producer->image) : '';
|
||||
})
|
||||
->editColumn('tags2', function (Merchandise $merchandise) {
|
||||
->editColumn('tags2', function (Producer $producer) {
|
||||
$html = '';
|
||||
foreach ($merchandise->tags as $tag) {
|
||||
foreach ($producer->tags as $tag) {
|
||||
$html .= '<span class="btn btn-xs btn-secondary pb-2">' . $tag->slug . '</span> ';
|
||||
}
|
||||
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('name')->title('Nom'),
|
||||
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('images_count')->title('#Pho')->class('text-right')->searchable(false),
|
||||
$this->makeColumnButtons(),
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin\Shop;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Repositories\Shop\Merchandises;
|
||||
use App\Repositories\Shop\Producers;
|
||||
use App\Repositories\Shop\TagGroups;
|
||||
use App\Datatables\Shop\MerchandisesDataTable;
|
||||
|
||||
@@ -19,6 +20,7 @@ class MerchandiseController extends Controller
|
||||
|
||||
public function create()
|
||||
{
|
||||
$data['producers_list'] = Producers::getOptions();
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
return view('Admin.Shop.Merchandises.create', $data);
|
||||
}
|
||||
@@ -38,6 +40,7 @@ class MerchandiseController extends Controller
|
||||
public function edit($id)
|
||||
{
|
||||
$data['merchandise'] = Merchandises::getFull($id);
|
||||
$data['producers_list'] = Producers::getOptions();
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
return view('Admin.Shop.Merchandises.edit', $data);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class LoginController extends Controller
|
||||
|
||||
public function showLoginForm()
|
||||
{
|
||||
return view('Shop.auth.login', $data ?? []);
|
||||
return view('auth.login', $data ?? []);
|
||||
}
|
||||
|
||||
public function authenticated(Request $request, $user)
|
||||
|
||||
@@ -15,5 +15,9 @@ class Merchandises
|
||||
$menu->addTo('merchandises', __('Marchandises'), [
|
||||
'route' => 'Admin.Shop.Merchandises.index',
|
||||
])->activeIfRoute(['Admin.Shop.Merchandises.*'])->order(1);
|
||||
|
||||
$menu->addTo('merchandises', __('Producteurs'), [
|
||||
'route' => 'Admin.Shop.Producers.index',
|
||||
])->activeIfRoute(['Admin.Shop.Producers.*'])->order(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ use Rinvex\Tags\Traits\Taggable;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
|
||||
use App\Traits\Model\Imageable;
|
||||
use App\Models\Shop\Tag;
|
||||
use App\Models\Shop\Article;
|
||||
|
||||
class Specie extends Model implements HasMedia
|
||||
{
|
||||
@@ -20,7 +22,7 @@ class Specie extends Model implements HasMedia
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->morphToMany('App\Models\Shop\Tag', 'taggable');
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
|
||||
public function Genre()
|
||||
@@ -35,7 +37,7 @@ class Specie extends Model implements HasMedia
|
||||
|
||||
public function Articles()
|
||||
{
|
||||
return $this->morphMany('App\Models\Shop\Article', 'product');
|
||||
return $this->morphMany(Article::class, 'product');
|
||||
}
|
||||
|
||||
public function scopeByName($query, $name)
|
||||
|
||||
@@ -12,6 +12,9 @@ use Wildside\Userstamps\Userstamps;
|
||||
|
||||
use App\Traits\Model\Imageable;
|
||||
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Shop\Tag;
|
||||
|
||||
class Variety extends Model implements HasMedia
|
||||
{
|
||||
use Imageable, PowerJoins, SoftDeletes, Taggable, UserStamps;
|
||||
@@ -21,16 +24,16 @@ class Variety extends Model implements HasMedia
|
||||
|
||||
public function Specie()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Botanic\Specie');
|
||||
return $this->belongsTo(Specie::class);
|
||||
}
|
||||
|
||||
public function Articles()
|
||||
{
|
||||
return $this->morphMany('App\Models\Shop\Article', 'product');
|
||||
return $this->morphMany(Article::class, 'product');
|
||||
}
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->morphToMany('App\Models\Shop\Tag', 'taggable');
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,14 @@ class Producer extends Model implements HasMedia
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_producers';
|
||||
|
||||
public function Articles()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function Merchandises()
|
||||
{
|
||||
return $this->morphMany(Article::class, 'product');
|
||||
return $this->hasMany(Merchandise::class);
|
||||
}
|
||||
|
||||
public function tags()
|
||||
|
||||
95
app/Repositories/Shop/Producers.php
Normal file
95
app/Repositories/Shop/Producers.php
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,14 @@
|
||||
<div class="row mb-3">
|
||||
<div class="col-6">
|
||||
{{ 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 class="col-6">
|
||||
{{ Form::label('alias', 'Alias') }}
|
||||
@@ -25,21 +32,49 @@
|
||||
<div class="row mb-3">
|
||||
<div class="col-12">
|
||||
{{ 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 class="row mb-3">
|
||||
<div class="col-12">
|
||||
{{ 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 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>
|
||||
|
||||
|
||||
@@ -7,35 +7,77 @@
|
||||
</div>
|
||||
<div class="col-6">
|
||||
{{ 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 class="row mb-3">
|
||||
<div class="col-12">
|
||||
{{ 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 class="row mb-3">
|
||||
<div class="col-12">
|
||||
{{ 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 class="row mb-3">
|
||||
<div class="col-12">
|
||||
{{ 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 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>
|
||||
|
||||
@@ -5,6 +5,16 @@
|
||||
{{ Form::label('name', 'Nom') }}
|
||||
@include('components.form.input', ['name' => 'name', 'value' => $merchandise['name'] ?? null, 'required' => true])
|
||||
</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 class="row mb-3">
|
||||
@@ -33,6 +43,19 @@
|
||||
</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 class="col-md-4">
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
@extends('layout.index', [
|
||||
'title' => __('shop.merchandises.title'),
|
||||
'subtitle' => __('shop.merchandises.add'),
|
||||
'breadcrumb' => [__('shop.merchandises.title'), __('shop.merchandises.add')]
|
||||
'title' => __('shop.producers.title'),
|
||||
'subtitle' => __('shop.producers.add'),
|
||||
'breadcrumb' => [__('shop.producers.title'), __('shop.producers.add')]
|
||||
])
|
||||
|
||||
@section('content')
|
||||
{{ Form::open(['route' => 'Admin.Shop.Merchandises.store', 'id' => 'form', 'autocomplete' => 'off', 'files' => true]) }}
|
||||
@include('Admin.Shop.Merchandises.form')
|
||||
{{ Form::open(['route' => 'Admin.Shop.Producers.store', 'id' => 'form', 'autocomplete' => 'off', 'files' => true]) }}
|
||||
@include('Admin.Shop.Producers.form')
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
@extends('layout.index', [
|
||||
'title' => __('Shop.merchandises.title'),
|
||||
'subtitle' => __('Shop.merchandises.edit'),
|
||||
'breadcrumb' => [__('Shop.merchandises.title'), __('Shop.merchandises.edit')]
|
||||
'title' => __('Shop.producers.title'),
|
||||
'subtitle' => __('Shop.producers.edit'),
|
||||
'breadcrumb' => [__('Shop.producers.title'), __('Shop.producers.edit')]
|
||||
])
|
||||
|
||||
@section('content')
|
||||
{{ Form::open(['route' => 'Admin.Shop.Merchandises.store', 'id' => 'form', 'autocomplete' => 'off', 'files' => true]) }}
|
||||
<input type="hidden" name="id" id="id" value="{{ $merchandise['id'] }}">
|
||||
@include('Admin.Shop.Merchandises.form')
|
||||
{{ Form::open(['route' => 'Admin.Shop.Producers.store', 'id' => 'form', 'autocomplete' => 'off', 'files' => true]) }}
|
||||
<input type="hidden" name="id" id="id" value="{{ $producer['id'] }}">
|
||||
@include('Admin.Shop.Producers.form')
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
<div class="row mb-3">
|
||||
<div class="col-6">
|
||||
{{ 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>
|
||||
|
||||
@@ -13,7 +17,7 @@
|
||||
@include('components.form.selects.select-tree', [
|
||||
'name' => 'tags[]',
|
||||
'list' => $tags_list,
|
||||
'values' => $merchandise['tags'] ?? null,
|
||||
'values' => $producer['tags'] ?? null,
|
||||
'class' => 'select2 form-control',
|
||||
'multiple' => true
|
||||
])
|
||||
@@ -25,7 +29,7 @@
|
||||
{{ Form::label('description', 'Description') }}
|
||||
@include('components.form.textarea', [
|
||||
'name' => 'description',
|
||||
'value' => $merchandise['description'] ?? null,
|
||||
'value' => $producer['description'] ?? null,
|
||||
'class' => 'editor',
|
||||
'rows' => 5,
|
||||
'required' => false,
|
||||
@@ -37,7 +41,7 @@
|
||||
|
||||
<div class="col-md-4">
|
||||
@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'),
|
||||
'name' => 'images',
|
||||
])
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
@extends('layout.index', [
|
||||
'title' => __('Marchandises'),
|
||||
'subtitle' => __('Liste de marchandises'),
|
||||
'breadcrumb' => [__('Shop.merchandises.title')]
|
||||
'title' => __('shop.producers.title'),
|
||||
'subtitle' => __('shop.producers.list'),
|
||||
'breadcrumb' => [__('Shop.producers.title')]
|
||||
])
|
||||
|
||||
@section('content')
|
||||
@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
|
||||
@endsection
|
||||
|
||||
|
||||
Reference in New Issue
Block a user