Add merchandise, fix articletosell with src for images

This commit is contained in:
Ludovic CANDELLIER
2022-04-14 23:20:09 +02:00
parent 9c2b9cf02e
commit c2ef0c7b35
14 changed files with 69 additions and 23 deletions

View File

@@ -59,6 +59,11 @@ class Shop
$menu->addTo('shop', 'Accueil', [ $menu->addTo('shop', 'Accueil', [
'route' => 'Admin.Shop.Homepages.index', 'route' => 'Admin.Shop.Homepages.index',
])->activeIfRoute(['Admin.Shop.Homepages.*'])->order(14); ])->activeIfRoute(['Admin.Shop.Homepages.*'])->order(15);
$menu->addTo('shop', 'Marchandises', [
'route' => 'Admin.Shop.Merchandises.index',
])->activeIfRoute(['Admin.Shop.Merchandises.*'])->order(16);
} }
} }

View File

@@ -83,8 +83,8 @@ class Articles
$parents = self::getInheritedByProduct($article->product_id, $article->product_type); $parents = self::getInheritedByProduct($article->product_id, $article->product_type);
$data['description'] = self::getFullDescriptionByArticle($article); $data['description'] = self::getFullDescriptionByArticle($article);
$image = self::getFullImageByArticle($article); $image = self::getFullImageByArticle($article);
$data['image'] = self::getPreview($image); $data['image'] = self::getPreviewSrc($image);
$data['image_big'] = self::getImage($image); $data['image_big'] = self::getImageSrc($image);
$data['inherited'] = self::getInherited($id); $data['inherited'] = self::getInherited($id);
$data['categories'] = self::getCategoriesNameByArticle($article); $data['categories'] = self::getCategoriesNameByArticle($article);
$data['tags'] = self::getTagsSlugByArticle($article); $data['tags'] = self::getTagsSlugByArticle($article);
@@ -408,6 +408,10 @@ class Articles
$specie = $article->product; $specie = $article->product;
$image = $specie->image; $image = $specie->image;
break; break;
case 'App\Models\Shop\Merchandise':
$merchandise = $article->product;
$image = $merchandise->image;
break;
} }
} }
return $image; return $image;

View File

@@ -23,7 +23,7 @@ trait Imageable
public static function getThumbSrc($image) public static function getThumbSrc($image)
{ {
return Medias::getThumbSrc($image); return $image ? Medias::getThumbSrc($image) : '/img/visuel-non-disponible.jpg';
} }
public static function getPreview($image) public static function getPreview($image)

View File

@@ -42,7 +42,7 @@
label: '{{ __('Commander') }}', label: '{{ __('Commander') }}',
className: 'btn-success', className: 'btn-success',
callback: function() { callback: function() {
submitModal(form_id); // submitModal(form_id);
} }
}, },
}; };
@@ -51,11 +51,12 @@
'Ajout dans le panier', 'Ajout dans le panier',
'basket-form', 'basket-form',
"{{ route('Shop.Basket.modalBasket') }}/" + offer_id + '/' + quantity, "{{ route('Shop.Basket.modalBasket') }}/" + offer_id + '/' + quantity,
"{{ route('Shop.Basket.addBasket') }}", "{{ route('Shop.Orders.create') }}",
refreshBasketTop(), false,
false, false,
true, true,
buttons buttons,
"refreshBasketTop()",
); );
}); });

View File

@@ -10,7 +10,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-4"> <div class="col-4">
{!! $article['image_big'] !!} <img src="{{ $article['image_big'] }}" class="img-fluid border">
</div> </div>
<div class="col-5"> <div class="col-5">
{!! $article['description'] !!} {!! $article['description'] !!}

View File

@@ -4,7 +4,7 @@
@section('content') @section('content')
@if ($basket) @if ($basket)
<div class="row m-0"> <div class="row">
<div class="col-8"> <div class="col-8">
<div class="row mb-3"> <div class="row mb-3">
<div class="col-4"> <div class="col-4">
@@ -17,7 +17,7 @@
</div> </div>
</div> </div>
@foreach ($basket as $nature => $items) @foreach ($basket as $nature => $items)
<div class="row mb-3 p-2 bg-green-light"> <div class="row mb-3 p-2 bg-green-light border">
<div class="col-12"> <div class="col-12">
<h2 style="font-size: 1.6em;">{{ ucfirst($nature) }}</h2> <h2 style="font-size: 1.6em;">{{ ucfirst($nature) }}</h2>
@foreach ($items as $item) @foreach ($items as $item)
@@ -73,19 +73,28 @@
calculateTotal(); calculateTotal();
$('.basket-quantity').change(function() { $('.basket-quantity').change(function() {
var offer_id = $(this).data('id');
quantity = $('.basket-quantity').value;
addBasket(offer_id, quantity, function() {
calculatePrice($(this).parents('.basket-row')); calculatePrice($(this).parents('.basket-row'));
calculateTotal();
});
}); });
$('.basket-delete').click(function() { $('.basket-delete').click(function() {
var offer_id = $(this).data('id'); var offer_id = $(this).data('id');
var data = {offer_id: offer_id, quantity: 0}; addBasket(offer_id, 0, function() {
$.post("{{ route('Shop.Basket.addBasket') }}", data, function() {
$('#basket_offer-' + offer_id).remove(); $('#basket_offer-' + offer_id).remove();
calculateTotal(); calculateTotal();
}); });
}); });
} }
function addBasket(offer_id, quantity, callback) {
var data = {offer_id: offer_id, quantity: 0};
$.post("{{ route('Shop.Basket.addBasket') }}", data, callback);
}
function calculatePrice($that) { function calculatePrice($that) {
var quantity = $that.find('.basket-quantity').val(); var quantity = $that.find('.basket-quantity').val();
var price = $that.find('.basket-price').text(); var price = $that.find('.basket-price').text();
@@ -103,6 +112,7 @@
}); });
$('#basket-total').html(fixNumber(total)); $('#basket-total').html(fixNumber(total));
calculateTotalShipped(); calculateTotalShipped();
refreshBasketTop();
return total; return total;
} }

View File

@@ -14,13 +14,12 @@
'name' => 'quantity', 'name' => 'quantity',
'value' => $item['quantity'], 'value' => $item['quantity'],
'class' => 'basket-quantity', 'class' => 'basket-quantity',
'data_id' => $item['id'],
]) ])
</div> </div>
<div class="col-3 text-right" style="font-size: 2em;" id="basket_total-{{ $item['id'] }}"> <div class="col-4 text-right" style="font-size: 2em;" id="basket_total-{{ $item['id'] }}">
<span class="basket-total-row">{{ $item['quantity'] * $item['price'] }}</span> <span class="basket-total-row">{{ $item['quantity'] * $item['price'] }}</span>
</div> <i class="btn btn-success fa fa-trash basket-delete ml-3 mb-2" data-id={{ $item['id'] }}></i>
<div class="col-1 text-center">
<i class="btn fa fa-fw fa-trash basket-delete" style="font-size: 1.6em;" data-id={{ $item['id'] }}></i>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -56,11 +56,10 @@
</script> </script>
@endif @endif
@stack('js')
<script> <script>
function refreshBasketTop() { function refreshBasketTop() {
$.get("{{ route('Shop.Basket.getSummary') }}", function(response) { $.get("{{ route('Shop.Basket.getSummary') }}", function(response) {
console.log("refreshBasketTop()");
console.log(response); console.log(response);
$('#count-basket').html(response.data.quantity); $('#count-basket').html(response.data.quantity);
$('#total-basket').html(response.data.total); $('#total-basket').html(response.data.total);
@@ -68,6 +67,8 @@
} }
</script> </script>
@stack('js')
</body> </body>
</html> </html>

View File

@@ -1,7 +1,7 @@
<div class="row"> <div class="row">
<div class="col-12 text-right p-2"> <div class="col-12 text-right p-2">
<a href="{{ route('Shop.Basket.basket') }}" style="color: white;"> <a href="{{ route('Shop.Basket.basket') }}" style="color: white;">
<button type="button" class="btn bg-green-dark basket light"> <button type="button" class="btn bg-green-dark light">
<i class="fa fa-2x fa-fw fa-shopping-basket mr-2"></i> <i class="fa fa-2x fa-fw fa-shopping-basket mr-2"></i>
<span class="ml-2 badge bg-yellow green-dark"> <span class="ml-2 badge bg-yellow green-dark">
<span id="count-basket">{{ \App\Repositories\Core\User\ShopCart::getTotalQuantity() }}</span> <span id="count-basket">{{ \App\Repositories\Core\User\ShopCart::getTotalQuantity() }}</span>

View File

@@ -1,6 +1,6 @@
<div class="row bg-green"> <div class="row bg-green">
<div class="col-3 form-inline pl-4"> <div class="col-3 form-inline">
<a href="/"><img src="/img/logo.jpg" class="img-responvive"></a> <a href="/"><img src="/img/logo.jpg" class="img-responvive"></a>
<a id="filters" href="#" class="text-white pl-3"><i class="fa fa-2x fa-bars"></i></a> <a id="filters" href="#" class="text-white pl-3"><i class="fa fa-2x fa-bars"></i></a>
</div> </div>

View File

@@ -1,4 +1,7 @@
<input type="number" name="{{ $name }}" id="{{ $id_name ?? str_slug($name,'-') }}" class="form-control {{ $class ?? ''}}" value="{{ $value ?? ''}}" <input type="number" name="{{ $name }}" id="{{ $id_name ?? str_slug($name,'-') }}" class="form-control {{ $class ?? ''}}" value="{{ $value ?? ''}}"
@if (isset($data_id))
data-id="{{ $data_id }}"
@endif
@if (isset($required)) @if (isset($required))
required="required" required="required"
@endif @endif

View File

@@ -3,7 +3,7 @@
@push('js') @push('js')
<script> <script>
function openModal(title, form_id, url_open, url_save, callback, size, no_confirm, buttons) { function openModal(title, form_id, url_open, url_save, callback, size, no_confirm, buttons, callback_after_loaded) {
var status = 0; var status = 0;
var dialog = bootbox.dialog({ var dialog = bootbox.dialog({
title: title, title: title,
@@ -18,7 +18,11 @@
dialog.init(function() { dialog.init(function() {
$.get(url_open, function(data) { $.get(url_open, function(data) {
console.log("OpenModal init");
dialog.find('.bootbox-body').html(data); dialog.find('.bootbox-body').html(data);
if (callback_after_loaded) {
eval(callback_after_loaded);
}
// if ( typeOf(url_save) !== 'undefined') { // if ( typeOf(url_save) !== 'undefined') {
handlePostModal(form_id,url_save, callback); handlePostModal(form_id,url_save, callback);
// } // }

View File

@@ -0,0 +1,18 @@
<?php
Route::prefix('Merchandises')->name('Merchandises.')->group(function () {
Route::get('', 'MerchandiseController@index')->name('index');
Route::get('getDataTable', 'MerchandiseController@getDataTable')->name('getDataTable');
Route::get('create', 'MerchandiseController@create')->name('create');
Route::delete('destroy/{id?}', 'MerchandiseController@destroy')->name('destroy');
Route::post('update', 'MerchandiseController@update')->name('update');
Route::post('store', 'MerchandiseController@store')->name('store');
Route::get('edit/{id}', 'MerchandiseController@edit')->name('edit');
Route::post('getSelect', 'MerchandiseController@getOptionsWithSpecie')->name('getSelect');
Route::post('deleteImage', 'MerchandiseController@deleteImage')->name('deleteImage');
Route::any('getImages/{id?}/{can_edit?}', 'MerchandiseController@getImages')->name('getImages');
Route::any('exportExcel', 'MerchandiseController@exportExcel')->name('exportExcel');
});

View File

@@ -10,6 +10,7 @@ Route::middleware('auth')->prefix('Shop')->namespace('Shop')->name('Shop.')->gro
include __DIR__ . '/Homepages.php'; include __DIR__ . '/Homepages.php';
include __DIR__ . '/InvoiceItems.php'; include __DIR__ . '/InvoiceItems.php';
include __DIR__ . '/Invoices.php'; include __DIR__ . '/Invoices.php';
include __DIR__ . '/Merchandises.php';
include __DIR__ . '/Offers.php'; include __DIR__ . '/Offers.php';
include __DIR__ . '/OrderPayments.php'; include __DIR__ . '/OrderPayments.php';
include __DIR__ . '/Orders.php'; include __DIR__ . '/Orders.php';