Fix on preview mode

This commit is contained in:
Ludovic CANDELLIER
2021-08-23 23:56:46 +02:00
parent 81fbec892c
commit 24fffce7a1
15 changed files with 289 additions and 102 deletions

View File

@@ -9,7 +9,13 @@ use App\Datatables\Admin\Core\CommentsDataTable;
class CommentController extends Controller class CommentController extends Controller
{ {
public function index(CommentsDataTable $dataTable, $model, $model_id) public function index($model, $model_id)
{
$data['comments'] = Comments::getCommentsByModel($model, $model_id);
return view('Admin.Core.Comments.partials.list-comments', $data);
}
public function list(CommentsDataTable $dataTable, $model, $model_id)
{ {
$data['model'] = $model; $data['model'] = $model;
$data['model_id'] = $model_id; $data['model_id'] = $model_id;

View File

@@ -5,7 +5,10 @@ namespace App\Http\Controllers\Admin\Shop;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Repositories\Shop\Articles;
use App\Repositories\Shop\Offers; use App\Repositories\Shop\Offers;
use App\Repositories\Shop\Tariffs;
use App\Repositories\Shop\Variations;
use App\Datatables\Shop\OffersDataTable; use App\Datatables\Shop\OffersDataTable;
class OfferController extends Controller class OfferController extends Controller
@@ -17,7 +20,10 @@ class OfferController extends Controller
public function create() public function create()
{ {
return view('Admin.Shop.Offers.create'); $data['articles'] = Articles::getOptions();
$data['tariffs'] = Tariffs::getOptions();
$data['variations'] = Variations::getOptions();
return view('Admin.Shop.Offers.create', $data);
} }
public function store(Request $request) public function store(Request $request)
@@ -44,4 +50,22 @@ class OfferController extends Controller
{ {
return Offers::destroy($id); return Offers::destroy($id);
} }
public function previewArticle($id)
{
$data['article'] = Articles::getArticle($id);
return view('Admin.Shop.Offers.partials.article', $data);
}
public function previewVariation($id)
{
$data['variation'] = Variations::get($id)->toArray();
return view('Admin.Shop.Offers.partials.variation', $data);
}
public function previewTariff($id)
{
$data['tariff'] = Tariffs::getPrices($id);
return view('Admin.Shop.Offers.partials.tariff', $data);
}
} }

View File

@@ -22,6 +22,12 @@ class Comments
return $model->html(); return $model->html();
} }
public static function getCommentsByModel($model, $model_id)
{
$class = self::getClass($model);
return self::getCommentsByClass($class, $model_id);
}
public static function getCommentsByClass($class, $id) public static function getCommentsByClass($class, $id)
{ {
return self::getByModel(self::getModel($class, $id)); return self::getByModel(self::getModel($class, $id));
@@ -29,17 +35,17 @@ class Comments
public static function getModel($class, $id) public static function getModel($class, $id)
{ {
return $$class::find($id); return $class::find($id);
} }
public static function getClass($class) public static function getClass($model)
{ {
return 'App\Models\\' . str_replace('.','\\', $class); return 'App\Models\\' . str_replace('.','\\', $model);
} }
public static function getByModel($model) public static function getByModel($model)
{ {
return $model ? $model->comments : false; return $model ? $model->comments->sortByDesc('updated_at')->toArray() : false;
} }
public static function storeComments($model, $comments) public static function storeComments($model, $comments)

View File

@@ -23,44 +23,60 @@ class Articles
return $export; return $export;
} }
public static function getOptions()
{
return Article::orderBy('name','asc')->pluck('name','id')->toArray();
}
public static function getAll() public static function getAll()
{ {
return Article::orderBy('name', 'asc')->get(); return Article::orderBy('name', 'asc')->get();
} }
public static function getFull($id) public static function getArticle($id)
{ {
$article = Article::with('product.tags')->findOrFail($id); $article = Article::with('product.tags')->findOrFail($id);
$data['article'] = $article->toArray(); $data = $article->toArray();
$data['article']['inherited'] = self::getInherited($id); $data['inherited'] = self::getInherited($id);
// dump($data); $data['categories'] = self::getCategoriesNameByArticle($article);
// exit; $data['tags'] = self::getTagsNameByArticle($article);
$data['article']['categories'] = self::getCategoriesByArticle($article); $data['comments'] = Comments::getByModel($article);
$data['article']['tags'] = self::getTagsByArticle($article); return $data;
// $data['article']['prices'] = self::getPricesByArticle($article); }
// $data['datatables']['comments'] = Comments::getDatatable();
$data['article']['comments'] = $article->comments;
public static function getFull($id)
{
$data = self::getArticleEdit($id);
self::getMeta($data); self::getMeta($data);
return $data; return $data;
} }
public static function getArticleEdit($id)
{
$article = Article::with('product.tags')->findOrFail($id);
$data = $article->toArray();
$data['inherited'] = self::getInherited($id);
$data['categories'] = self::getCategoriesByArticle($article);
$data['tags'] = self::getTagsByArticle($article);
$data['comments'] = Comments::getByModel($article);
return $data;
}
public static function getInherited($id) public static function getInherited($id)
{ {
$article = Article::with('product.tags')->findOrFail($id); $article = Article::with('product.tags')->findOrFail($id);
$product_type = $article->product_type; $product_type = $article->product_type;
switch ($product_type) { switch ($product_type) {
case 'App\Models\Botanic\Variety': case 'App\Models\Botanic\Variety':
$data[] = ['name' => 'Espèces', 'description' => Species::getDescription($article->product->specie_id), 'tags' => Species::getTags($article->product->specie_id)]; $data[] = ['name' => 'Espèces', 'description' => Species::getDescription($article->product->specie_id), 'tags' => Species::getTags($article->product->specie_id)];
$data[] = ['name' => 'Variétés', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()]; $data[] = ['name' => 'Variétés', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()];
break; break;
case 'App\Models\Botanic\Specie': case 'App\Models\Botanic\Specie':
$data[] = ['name' => 'Espèces', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()]; $data[] = ['name' => 'Espèces', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()];
break; break;
case 'App\Models\Shop\Merchandise': case 'App\Models\Shop\Merchandise':
$data[] = ['name' => 'Marchandise', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()]; $data[] = ['name' => 'Marchandise', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()];
break; break;
} }
return $data; return $data;
} }
@@ -86,11 +102,21 @@ class Articles
return $article->categories->pluck('id')->toArray(); return $article->categories->pluck('id')->toArray();
} }
public static function getCategoriesNameByArticle($article)
{
return $article->categories->pluck('name', 'id')->toArray();
}
public static function getTagsByArticle($article) public static function getTagsByArticle($article)
{ {
return $article->tags->pluck('id')->toArray(); return $article->tags->pluck('id')->toArray();
} }
public static function getTagsNameByArticle($article)
{
return $article->tags->pluck('name', 'id')->toArray();
}
public static function getPricesByArticle($article) public static function getPricesByArticle($article)
{ {
return Prices::getByArticle($article->id); return Prices::getByArticle($article->id);

View File

@@ -32,11 +32,13 @@ class PriceListValues
return PriceListValue::find($id); return PriceListValue::find($id);
} }
public static function storePrices($generic_id, $values) public static function storePrices($price_list_id, $values)
{ {
foreach ($values as $value) { foreach ($values as $value) {
$value['price_generic_id'] = $generic_id; $value['price_list_id'] = $price_list_id;
self::store($value); if ($value['price']) {
self::store($value);
}
} }
} }
@@ -44,7 +46,7 @@ class PriceListValues
{ {
$id = isset($data['id']) ? $data['id'] : false; $id = isset($data['id']) ? $data['id'] : false;
$price = $id ? self::update($data) : self::create($data); $price = $id ? self::update($data) : self::create($data);
return $price->id; return $price;
} }
public static function create($data) public static function create($data)

View File

@@ -38,6 +38,11 @@ class PriceLists
return PriceList::find($id); return PriceList::find($id);
} }
public static function getPrices($id)
{
return PriceList::with('price_list_values')->find($id);
}
public static function getFull($id) public static function getFull($id)
{ {
return PriceList::with(['price_list_values'])->find($id); return PriceList::with(['price_list_values'])->find($id);

View File

@@ -16,6 +16,11 @@ class Tariffs
return $export; return $export;
} }
public static function getPrices($id)
{
return Tariff::with(['price_lists.price_list_values','price_lists.sale_channel'])->find($id);
}
public static function getOptions() public static function getOptions()
{ {
return Tariff::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray(); return Tariff::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();

View File

@@ -1,32 +1,22 @@
@component('components.layout.box-collapse', ['id' => 'comments', 'title' => __('comments')]) @component('components.layout.box-collapse', ['id' => 'comments', 'title' => __('comments')])
@if (!empty($comments)) @include('Admin.Core.Comments.partials.list-comments')
@foreach ($comments as $comment)
<div class="row">
<div class="col-6">
<strong>{{ App\Repositories\Core\Auth\Users::getName($comment->user_id) }}</strong>
</div>
<div class="col-6 text-right"><i>{{ App\Repositories\Core\DateTime::DateToLocale($comment->updated_at) }}</i></div>
<div class="col-12">
{!! $comment->comment !!}
</div>
</div>
@endforeach
@endif
<button type="button" class="btn btn-xs btn-primary" id="add-comment">
{{ __('comment_add') }}
<i class="fa fa-plus"></i>
</button>
@endcomponent @endcomponent
@push('js') @push('js')
<script> <script>
function handleAddComment() { function handleAddComment() {
$('#add-comment').click(function() { $('#add-comment').click(function() {
openModal('{{ __('comment_add') }}', '#comment-form', '{{ route('Admin.Core.Comments.create', ['model' => $model, 'model_id' => $model_id]) }}', '{{ route('Admin.Core.Comments.store') }}' ); openModal('{{ __('comment_add') }}', '#comment-form', '{{ route('Admin.Core.Comments.create', ['model' => $model, 'model_id' => $model_id]) }}', '{{ route('Admin.Core.Comments.store') }}', 'refreshComments()' );
}); });
} }
function refreshComments() {
var url = '{{ route('Admin.Core.Comments.index') }}/{{ $model }}/{{ $model_id }}';
console.log('refresh');
console.log(url);
$("#comments").load(url);
}
$(document).ready(function () { $(document).ready(function () {
handleAddComment(); handleAddComment();
}); });

View File

@@ -0,0 +1,20 @@
@if (!empty($comments))
@foreach ($comments as $comment)
<div class="row">
<div class="col-6">
<strong>{{ App\Repositories\Core\Auth\Users::getName($comment['user_id']) }}</strong>
</div>
<div class="col-6 text-right"><i>{{ App\Repositories\Core\DateTime::DateToLocale($comment['updated_at']) }}</i></div>
<div class="col-12">
{!! $comment['comment'] !!}
</div>
</div>
@endforeach
@endif
@if ($with_add ?? true)
<button type="button" class="btn btn-xs btn-primary" id="add-comment">
{{ __('comment_add') }}
<i class="fa fa-plus"></i>
</button>
@endif

View File

@@ -1,36 +0,0 @@
@extends('layout.index', [
'title' => __('products.title'),
'subtitle' => __('products.title'),
'breadcrumb' => [__('products.title')]
])
@section('content')
<form action="{{ route('Shop.Products') }}" method="GET">
<div class="row">
<div class="col-md-offset-2 col-md-8">
<div class="box box-info">
<div class="box-body">
<div class="col-md-6">
<h3>{{ name }}</h3>
<h4>
{{ $product.section.name }}<br>
</h4>
</div>
<div class="col-md-6 text-right">
<h2>{{ $prix_total }} </h2>
<h4>{{ $residence['type_produit']['name'] }}</h4>
</div>
<div class="col-md-12">
@include('Hestimmo.modules.Lot.partials.carousel')
</div>
</div>
</div>
</div>
</div>
</form>
@endsection

View File

@@ -1,27 +1,34 @@
<div class="row mb-3"> <div class="row mb-3">
<div class="col-8"> <div class="col-3">
<div class="row mb-3"> <div class="row mb-3">
<div class="col-8"> <div class="col-12">
{{ Form::label('article_id', 'Article') }} {{ Form::label('article_id', 'Article') }}
@include('components.form.autocomplete', ['name' => 'article', 'data' => $offer ?? null, 'url' => route('Admin.Shop.Articles.autocomplete')]) @include('components.select', ['name' => 'article_id', 'id_name' => 'article_id', 'list' => $articles ?? null, 'value' => $offer['article_id'] ?? null, 'with_empty' => '', 'class' => 'select2 select_article'])
</div> </div>
</div> </div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-8"> <div class="col-12">
{{ Form::label('variation_id', 'Déclinaison') }} {{ Form::label('variation_id', 'Déclinaison') }}
@include('components.form.autocomplete', ['name' => 'variation', 'data' => $offer ?? null, 'url' => route('Admin.Shop.Variations.autocomplete')]) @include('components.select', ['name' => 'variation_id', 'id_name' => 'variation_id', 'list' => $variations ?? null, 'value' => $offer['variation_id'] ?? null, 'with_empty' => '', 'class' => 'select2 select_variation'])
</div> </div>
</div> </div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-8"> <div class="col-12">
{{ Form::label('tariff_id', 'Tarif') }} {{ Form::label('tariff_id', 'Tarif') }}
@include('components.form.autocomplete', ['name' => 'tariff', 'data' => $offer ?? null, 'url' => route('Admin.Shop.Tariffs.autocomplete')]) @include('components.select', ['name' => 'tariff_id', 'id_name' => 'tariff_id', 'list' => $tariffs ?? null, 'value' => $offer['tariff_id'] ?? null, 'with_empty' => '', 'class' => 'select2 select_tariffs'])
</div> </div>
</div> </div>
</div> </div>
<div class="col-4"> <div class="col-6">
@component('components.card', ['title' => 'Previsualisation'])
<div id="preview-article"></div>
<div id="preview-variation"></div>
<div id="preview-tariff"></div>
@endcomponent
</div>
<div class="col-3">
@component('components.card', ['title' => 'Disponibilité']) @component('components.card', ['title' => 'Disponibilité'])
<div class="row mb-3"> <div class="row mb-3">
<div class="col-6"> <div class="col-6">
@@ -55,11 +62,44 @@
@include('components.save') @include('components.save')
@include('load.form.autocomplete') @include('load.layout.chevron')
@include('load.form.save')
@include('load.form.select2')
@push('js') @push('js')
<script> <script>
initAutocomplete(); function handleArticle() {
$('.select_article').change(function() {
var url = '{{ route('Admin.Shop.Offers.previewArticle') }}/' + $(this).val();
$('#preview-article').load(url, function() {
initChevron();
});
})
}
function handleVariation() {
$('.select_variation').change(function() {
var url = '{{ route('Admin.Shop.Offers.previewVariation') }}/' + $(this).val();
$('#preview-variation').load(url, function() {
initChevron();
});
})
}
function handleTariff() {
$('.select_tariffs').change(function() {
var url = '{{ route('Admin.Shop.Offers.previewTariff') }}/' + $(this).val();
$('#preview-tariff').load(url, function() {
initChevron();
});
})
}
handleArticle();
handleVariation();
handleTariff();
initChevron();
initSaveForm(); initSaveForm();
initSelect2();
</script> </script>
@endpush @endpush

View File

@@ -0,0 +1,54 @@
<div class="row">
<div class="col-12">
<div class="row mb-3">
<div class="col-4">
{{ Form::label('ref', 'Référence') }}<br>
{{ $article['ref'] ?? null }}
</div>
<div class="col-8">
{{ Form::label('name', 'Nom') }}<br>
{{ $article['name'] ?? null }}
</div>
</div>
<div class="row mb-3">
<div class="col-12">
{{ Form::label('categories', __('Shop.shelves.title')) }}<br>
@foreach (($article['categories'] ?? null) as $category)
{{ $category }}
@endforeach
</div>
</div>
<div class="row mb-3">
<div class="col-12">
{{ Form::label('tags', 'Tags') }}<br>
@foreach (($article['tags'] ?? null) as $tag)
{{ $tag }}
@endforeach
</div>
</div>
<div class="row mb-3">
<div class="col-12">
@include('Admin.Shop.Articles.partials.product.description')
</div>
</div>
<div class="row mb-3">
<div class="col-12">
{{ Form::label('description', 'Description') }}
{{ $article['description'] ?? null }}
</div>
</div>
<div class="row mb-3">
<div class="col-12">
@include('Admin.Core.Comments.partials.comments', ['model' => 'Shop.Article', 'model_id' => $article['id'] ?? false, 'comments' => $article['comments'], 'with_add' => false])
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,34 @@
<div class="row">
<div class="col-4">
{{ $tariff['ref'] ?? null }}
</div>
<div class="col-8">
{{ $tariff['name'] ?? null }}
</div>
</div>
<div class="row">
<div class="col-12">
@foreach (($tariff['price_lists'] ?? []) as $price_list)
{{ $price_list['sale_channel']['name'] }}
{{ $price_list['name'] }}
@if ($price_list['price_list_values'] ?? false)
<table class="table table-bordered table-hover table-striped w-100">
<thead>
<tr>
<th>Seuil</th>
<th>Prix</th>
</tr>
</thead>
@foreach (($price_list['price_list_values'] ?? []) as $price_value)
<tr>
<td>{{ $price_value['quantity'] }}</td>
<td class="text-right">{{ $price_value['price'] }}</td>
</tr>
@endforeach
</table>
@endif
@endforeach
</div>
</div>

View File

@@ -0,0 +1,8 @@
<div class="row">
<div class="col-12">
{{ $variation['name'] }}
</div>
</div>

View File

@@ -1,10 +1,13 @@
<?php <?php
Route::prefix('Offers')->name('Offers.')->group(function () { Route::prefix('Offers')->name('Offers.')->group(function () {
Route::get('', 'OfferController@index')->name('index'); Route::get('', 'OfferController@index')->name('index');
Route::get('create', 'OfferController@create')->name('create'); Route::get('create', 'OfferController@create')->name('create');
Route::delete('destroy/{id?}', 'OfferController@destroy')->name('destroy'); Route::delete('destroy/{id?}', 'OfferController@destroy')->name('destroy');
Route::post('update', 'OfferController@update')->name('update'); Route::post('update', 'OfferController@update')->name('update');
Route::post('store', 'OfferController@store')->name('store'); Route::post('store', 'OfferController@store')->name('store');
Route::get('edit/{id}', 'OfferController@edit')->name('edit'); Route::get('edit/{id}', 'OfferController@edit')->name('edit');
Route::get('previewArticle/{id?}', 'OfferController@previewArticle')->name('previewArticle');
Route::get('previewVariation/{id?}', 'OfferController@previewVariation')->name('previewVariation');
Route::get('previewTariff/{id?}', 'OfferController@previewTariff')->name('previewTariff');
}); });