Fix on preview mode

This commit is contained in:
Ludovic CANDELLIER
2021-08-23 23:56:46 +02:00
parent 9ca510086b
commit 9e2226a776
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
{
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_id'] = $model_id;

View File

@@ -5,7 +5,10 @@ namespace App\Http\Controllers\Admin\Shop;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\Articles;
use App\Repositories\Shop\Offers;
use App\Repositories\Shop\Tariffs;
use App\Repositories\Shop\Variations;
use App\Datatables\Shop\OffersDataTable;
class OfferController extends Controller
@@ -17,7 +20,10 @@ class OfferController extends Controller
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)
@@ -44,4 +50,22 @@ class OfferController extends Controller
{
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();
}
public static function getCommentsByModel($model, $model_id)
{
$class = self::getClass($model);
return self::getCommentsByClass($class, $model_id);
}
public static function getCommentsByClass($class, $id)
{
return self::getByModel(self::getModel($class, $id));
@@ -29,17 +35,17 @@ class Comments
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)
{
return $model ? $model->comments : false;
return $model ? $model->comments->sortByDesc('updated_at')->toArray() : false;
}
public static function storeComments($model, $comments)

View File

@@ -23,29 +23,45 @@ class Articles
return $export;
}
public static function getOptions()
{
return Article::orderBy('name','asc')->pluck('name','id')->toArray();
}
public static function getAll()
{
return Article::orderBy('name', 'asc')->get();
}
public static function getFull($id)
public static function getArticle($id)
{
$article = Article::with('product.tags')->findOrFail($id);
$data['article'] = $article->toArray();
$data['article']['inherited'] = self::getInherited($id);
// dump($data);
// exit;
$data['article']['categories'] = self::getCategoriesByArticle($article);
$data['article']['tags'] = self::getTagsByArticle($article);
// $data['article']['prices'] = self::getPricesByArticle($article);
// $data['datatables']['comments'] = Comments::getDatatable();
$data['article']['comments'] = $article->comments;
$data = $article->toArray();
$data['inherited'] = self::getInherited($id);
$data['categories'] = self::getCategoriesNameByArticle($article);
$data['tags'] = self::getTagsNameByArticle($article);
$data['comments'] = Comments::getByModel($article);
return $data;
}
public static function getFull($id)
{
$data = self::getArticleEdit($id);
self::getMeta($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)
{
$article = Article::with('product.tags')->findOrFail($id);
@@ -86,11 +102,21 @@ class Articles
return $article->categories->pluck('id')->toArray();
}
public static function getCategoriesNameByArticle($article)
{
return $article->categories->pluck('name', 'id')->toArray();
}
public static function getTagsByArticle($article)
{
return $article->tags->pluck('id')->toArray();
}
public static function getTagsNameByArticle($article)
{
return $article->tags->pluck('name', 'id')->toArray();
}
public static function getPricesByArticle($article)
{
return Prices::getByArticle($article->id);

View File

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

View File

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

View File

@@ -16,6 +16,11 @@ class Tariffs
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()
{
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')])
@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
<button type="button" class="btn btn-xs btn-primary" id="add-comment">
{{ __('comment_add') }}
<i class="fa fa-plus"></i>
</button>
@include('Admin.Core.Comments.partials.list-comments')
@endcomponent
@push('js')
<script>
function handleAddComment() {
$('#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 () {
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="col-8">
<div class="col-3">
<div class="row mb-3">
<div class="col-8">
<div class="col-12">
{{ 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 class="row mb-3">
<div class="col-8">
<div class="col-12">
{{ 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 class="row mb-3">
<div class="col-8">
<div class="col-12">
{{ 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 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é'])
<div class="row mb-3">
<div class="col-6">
@@ -55,11 +62,44 @@
@include('components.save')
@include('load.form.autocomplete')
@include('load.layout.chevron')
@include('load.form.save')
@include('load.form.select2')
@push('js')
<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();
initSelect2();
</script>
@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

@@ -7,4 +7,7 @@ Route::prefix('Offers')->name('Offers.')->group(function () {
Route::post('update', 'OfferController@update')->name('update');
Route::post('store', 'OfferController@store')->name('store');
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');
});