fix basket
This commit is contained in:
@@ -2,56 +2,22 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Shop;
|
namespace App\Http\Controllers\Shop;
|
||||||
|
|
||||||
use App\Datatables\Shop\CategoriesDataTable;
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Repositories\Shop\ArticleNatures;
|
use App\Repositories\Shop\ArticleNatures;
|
||||||
use App\Repositories\Shop\Articles;
|
use App\Repositories\Shop\Articles;
|
||||||
use App\Repositories\Shop\Categories;
|
use App\Repositories\Shop\Categories;
|
||||||
|
use App\Repositories\Shop\Shelves;
|
||||||
use App\Repositories\Shop\TagGroups;
|
use App\Repositories\Shop\TagGroups;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class CategoryController extends Controller
|
class CategoryController extends Controller
|
||||||
{
|
{
|
||||||
public function index(CategoriesDataTable $dataTable)
|
|
||||||
{
|
|
||||||
return $dataTable->render('Shop.Categories.list');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show(Request $request, $categoryId, $articleNatureId = false)
|
public function show(Request $request, $categoryId, $articleNatureId = false)
|
||||||
{
|
{
|
||||||
$articleNatures = Articles::getArticleNaturesWithOffers([
|
$articleNature = $request->input('article_nature') ?? false;
|
||||||
'category_id' => $categoryId,
|
$displayByRows = $request->input('display_by_rows') ?? false;
|
||||||
]);
|
$tags = $request->input('tags') ?? [];
|
||||||
|
$data = Shelves::getOffersByCategoryAndNature($categoryId, $articleNatureId, $tags, $articleNature, $displayByRows);
|
||||||
if ($articleNatureId) {
|
|
||||||
$productType = ArticleNatures::getProductType($articleNatureId);
|
|
||||||
} else {
|
|
||||||
$articleNature = $request->input('article_nature');
|
|
||||||
if (! $articleNature) {
|
|
||||||
if (count($articleNatures)) {
|
|
||||||
$articleNature = $articleNatures[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$productType = ArticleNatures::getProductTypeBySlug($articleNature);
|
|
||||||
$articleNatureId = ArticleNatures::getIdBySlug($articleNature);
|
|
||||||
}
|
|
||||||
$data = [
|
|
||||||
'category' => Categories::getFull($categoryId),
|
|
||||||
'breadcrumb' => Categories::getAncestorsByCategory($categoryId),
|
|
||||||
'display_by_rows' => $request->input('display_by_rows') ?? false,
|
|
||||||
'product_type' => $productType,
|
|
||||||
'article_nature' => $articleNature,
|
|
||||||
'article_natures' => $articleNatures ?? [],
|
|
||||||
'product_types' => $productTypes ?? [],
|
|
||||||
'tags_selected' => $request->input('tags') ?? [],
|
|
||||||
'articles' => Articles::getArticlesToSell([
|
|
||||||
'category_id' => $categoryId,
|
|
||||||
'tags' => $request->input('tags') ?? [],
|
|
||||||
'product_type' => $productType ?? false,
|
|
||||||
'article_nature_id' => $articleNatureId ?? false,
|
|
||||||
]),
|
|
||||||
'tags' => TagGroups::getWithTagsAndCountOffers($categoryId),
|
|
||||||
];
|
|
||||||
|
|
||||||
// dump($data);
|
// dump($data);
|
||||||
// exit;
|
// exit;
|
||||||
|
|||||||
50
app/Repositories/Shop/Shelves.php
Normal file
50
app/Repositories/Shop/Shelves.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repositories\Shop;
|
||||||
|
|
||||||
|
use App\Models\Shop\Category;
|
||||||
|
use App\Repositories\Core\Categories as CategoryTrees;
|
||||||
|
use App\Repositories\Core\Tag;
|
||||||
|
|
||||||
|
class Shelves
|
||||||
|
{
|
||||||
|
public static function getOffersByCategoryAndNature($categoryId, $articleNatureId = false, $tags = [], $articleNature = false, $displayByRows = false)
|
||||||
|
{
|
||||||
|
$productTypes = Articles::getProductTypesWithOffers([
|
||||||
|
'category_id' => $categoryId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$articleNatures = Articles::getArticleNaturesWithOffers([
|
||||||
|
'category_id' => $categoryId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($articleNatureId) {
|
||||||
|
$productType = ArticleNatures::getProductType($articleNatureId);
|
||||||
|
} else {
|
||||||
|
if (! $articleNature) {
|
||||||
|
if (count($articleNatures)) {
|
||||||
|
$articleNature = $articleNatures[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$productType = ArticleNatures::getProductTypeBySlug($articleNature);
|
||||||
|
$articleNatureId = ArticleNatures::getIdBySlug($articleNature);
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'category' => Categories::getFull($categoryId),
|
||||||
|
'breadcrumb' => Categories::getAncestorsByCategory($categoryId),
|
||||||
|
'display_by_rows' => $displayByRows,
|
||||||
|
'product_type' => $productType,
|
||||||
|
'article_nature' => $articleNature,
|
||||||
|
'article_natures' => $articleNatures ?? [],
|
||||||
|
'product_types' => $productTypes ?? [],
|
||||||
|
'tags_selected' => $tags,
|
||||||
|
'articles' => Articles::getArticlesToSell([
|
||||||
|
'category_id' => $categoryId,
|
||||||
|
'tags' => $tags,
|
||||||
|
'product_type' => $productType ?? false,
|
||||||
|
'article_nature_id' => $articleNatureId ?? false,
|
||||||
|
]),
|
||||||
|
'tags' => TagGroups::getWithTagsAndCountOffers($categoryId),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
<input type="hidden" name="user_id_client_assoc" id="user_id_client_assoc" value="{{ $id }}" class="form-control" />
|
<input type="hidden" name="user_id_client_assoc" id="user_id_client_assoc" value="{{ $id }}" class="form-control" />
|
||||||
<select multiple class="multi-select form-no-control" name="user_clients_list" id="user_clients_list">
|
<select multiple class="multi-select form-no-control" name="user_clients_list" id="user_clients_list">
|
||||||
@foreach ($clients as $client)
|
@foreach ($clients as $client)
|
||||||
<option value="{{ $client->id }}" {{ !($client->active) ? 'disabled' : '' }} {{ in-array($client->id, $clients_selected) ?? 'selected' : ''>
|
<option value="{{ $client->id }}" {{ !($client->active) ? 'disabled' : '' }} {{ in_array($client->id, $clients_selected) ? 'selected' : '' }}>
|
||||||
{{ $client->name }}
|
{{ $client->name }}
|
||||||
</option>
|
</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="collapse_{{ $app }}" class="collapse content-box light p-2" role="tabpanel">
|
<div id="collapse_{{ $app }}" class="collapse content-box light p-2" role="tabpanel">
|
||||||
|
|
||||||
@foreach ($modules as $module = $actions)
|
@foreach ($modules as $module => $actions)
|
||||||
<h4 class="brand">{{ $module }}</h4>
|
<h4 class="brand">{{ $module }}</h4>
|
||||||
<div class="inline-group">
|
<div class="inline-group">
|
||||||
@foreach ($actions as $permission)
|
@foreach ($actions as $permission)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
<input type="hidden" name="user_id_client_assoc" id="user_id_client_assoc" value="{{ $id }}" class="form-control" />
|
<input type="hidden" name="user_id_client_assoc" id="user_id_client_assoc" value="{{ $id }}" class="form-control" />
|
||||||
<select multiple class="multi-select form-no-control" name="user_clients_list" id="user_clients_list">
|
<select multiple class="multi-select form-no-control" name="user_clients_list" id="user_clients_list">
|
||||||
@foreach ($clients as $client)
|
@foreach ($clients as $client)
|
||||||
<option value="{{ $client->id }}" {{ !($client->active) ? 'disabled' : '' }} {{ in-array($client->id, $clients_selected) ?? 'selected' : ''>
|
<option value="{{ $client->id }}" {{ !($client->active) ? 'disabled' : '' }} {{ in_array($client->id, $clients_selected ?? []) ? 'selected' : '' }}>
|
||||||
{{ $client->name }}
|
{{ $client->name }}
|
||||||
</option>
|
</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
<input type="hidden" name="user_id_client_assoc" id="user_id_client_assoc" value="{{ $id }}" class="form-control" />
|
<input type="hidden" name="user_id_client_assoc" id="user_id_client_assoc" value="{{ $id }}" class="form-control" />
|
||||||
<select multiple class="multi-select form-no-control" name="user_clients_list" id="user_clients_list">
|
<select multiple class="multi-select form-no-control" name="user_clients_list" id="user_clients_list">
|
||||||
@foreach ($clients as $client)
|
@foreach ($clients as $client)
|
||||||
<option value="{{ $client->id }}" {{ !($client->active) ? 'disabled' : '' }} {{ in-array($client->id, $clients_selected) ?? 'selected' : ''>
|
<option value="{{ $client->id }}" {{ !($client->active) ? 'disabled' : '' }} {{ in_array($client->id, $clients_selected) ? 'selected' : '' }}>
|
||||||
{{ $client->name }}
|
{{ $client->name }}
|
||||||
</option>
|
</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|||||||
@@ -25,43 +25,11 @@
|
|||||||
])
|
])
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@include('load.basket')
|
||||||
|
|
||||||
@push('js')
|
@push('js')
|
||||||
<script>
|
<script>
|
||||||
$('.basket').click(function() {
|
initBasket();
|
||||||
var type = $(this).data('type');
|
|
||||||
var offer_id = $('#' + type + '-offer_id').find('option:selected').val();
|
|
||||||
var quantity = $('#' + type + '-quantity').val();
|
|
||||||
var data = {
|
|
||||||
'offer_id': offer_id,
|
|
||||||
'quantity': quantity,
|
|
||||||
};
|
|
||||||
|
|
||||||
var buttons = {
|
|
||||||
cancel: {
|
|
||||||
label: '{{ __('Continuer mes achats') }}',
|
|
||||||
className: 'btn-secondary'
|
|
||||||
},
|
|
||||||
confirm: {
|
|
||||||
label: '{{ __('Commander') }}',
|
|
||||||
className: 'btn-success',
|
|
||||||
callback: function() {
|
|
||||||
window.location = "{{ route('Shop.Basket.basket') }}";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
openModal(
|
|
||||||
'Ajout dans le panier',
|
|
||||||
'basket-form',
|
|
||||||
"{{ route('Shop.Basket.modalBasket') }}/" + offer_id + '/' + quantity,
|
|
||||||
"{{ route('Shop.Orders.order') }}",
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
buttons,
|
|
||||||
"refreshBasketTop()",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
function setPrice(model) {
|
function setPrice(model) {
|
||||||
var offer_id = $('#' + model + '-offer_id').find('option:selected').val();
|
var offer_id = $('#' + model + '-offer_id').find('option:selected').val();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
@component('components.card', [
|
@component('components.card', [
|
||||||
'id_card' => $model . '-basket',
|
'id_card' => $model . '-basket',
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'class' => 'mb-3 ' . ($bgClass ?? null),
|
'class' => 'mb-3 addBasket ' . ($bgClass ?? null),
|
||||||
'classTitle' => 'mb-0',
|
'classTitle' => 'mb-0',
|
||||||
'outline' => false,
|
'outline' => false,
|
||||||
])
|
])
|
||||||
@@ -10,13 +10,14 @@
|
|||||||
'name' => 'offer_id',
|
'name' => 'offer_id',
|
||||||
'id_name' => $model . '-offer_id',
|
'id_name' => $model . '-offer_id',
|
||||||
'list' => collect($data)->pluck('name', 'id')->toArray(),
|
'list' => collect($data)->pluck('name', 'id')->toArray(),
|
||||||
'class' => 'select2 mb-2',
|
'class' => 'select2 mb-2 offer_id',
|
||||||
])
|
])
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-5">
|
<div class="col-5">
|
||||||
@include('components.form.inputs.number', [
|
@include('components.form.inputs.number', [
|
||||||
'name' => 'quantity',
|
'name' => 'quantity',
|
||||||
|
'class' => 'quantity',
|
||||||
'id_name' => $model . '-quantity',
|
'id_name' => $model . '-quantity',
|
||||||
'value' => 1,
|
'value' => 1,
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -1,29 +1,41 @@
|
|||||||
@if ($article_nature == 'semences')
|
@if ($article_nature == 'semences')
|
||||||
<div class="w-100 mt-3 p-1 bg-green-light green-dark rounded-lg border text-center">
|
<div class="w-100 mt-3 p-1 bg-green-light green-dark rounded-lg border text-center addBasket">
|
||||||
<span style="font-size: 1.4em; font-weight: bold;">{{ $article['semences']['price'] ?? null }}</span> €<br>
|
<span style="font-size: 1.4em; font-weight: bold;">{{ $article['semences']['price'] ?? null }}</span> €<br>
|
||||||
{{ $article['semences']['variation'] }}
|
{{ $article['semences']['variation'] }}
|
||||||
<div>
|
<div>
|
||||||
Quantité : 1
|
Quantité :
|
||||||
|
@include('components.form.inputs.number', [
|
||||||
|
'name' => uniqid(),
|
||||||
|
'class' => 'quantity',
|
||||||
|
'value' => 1,
|
||||||
|
'style' => 'max-width: 64px; display: inline-block',
|
||||||
|
])
|
||||||
</div>
|
</div>
|
||||||
|
<input type="hidden" class="offer_id" value="{{ $article['semences']['offer_id'] ?? null }}" />
|
||||||
@include('components.form.button', [
|
@include('components.form.button', [
|
||||||
'class' => 'btn-green-dark basket semences mb-3 mt-2 shadow',
|
'class' => 'btn-green-dark basket semences mb-3 mt-2 shadow',
|
||||||
'txt' => 'Ajouter au panier',
|
'txt' => 'Ajouter au panier',
|
||||||
'data_id' => $article['semences']['offer_id'] ?? null,
|
|
||||||
])
|
])
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if ($article_nature == 'plants')
|
@if ($article_nature == 'plants')
|
||||||
<div class="w-100 mt-3 p-1 bg-green-light green-dark rounded-lg border text-center">
|
<div class="w-100 mt-3 p-1 bg-green-light green-dark rounded-lg border text-center addBasket">
|
||||||
<span style="font-size: 1.4em; font-weight: bold;">{{ $article['plants']['price'] ?? null }}</span> €<br>
|
<span style="font-size: 1.4em; font-weight: bold;">{{ $article['plants']['price'] ?? null }}</span> €<br>
|
||||||
{{ $article['plants']['variation'] }}
|
{{ $article['plants']['variation'] }}
|
||||||
<div>
|
<div>
|
||||||
Quantité : 1
|
Quantité :
|
||||||
|
@include('components.form.inputs.number', [
|
||||||
|
'name' => uniqid(),
|
||||||
|
'class' => 'quantity',
|
||||||
|
'value' => 1,
|
||||||
|
'style' => 'max-width: 64px; display: inline-block',
|
||||||
|
])
|
||||||
</div>
|
</div>
|
||||||
|
<input type="hidden" class="offer_id" value="{{ $article['plants']['offer_id'] ?? null }}" />
|
||||||
@include('components.form.button', [
|
@include('components.form.button', [
|
||||||
'class' => 'btn-success basket plants mb-3 mt-2 shadow',
|
'class' => 'btn-success basket plants mb-3 mt-2 shadow',
|
||||||
'txt' => 'Ajouter au panier',
|
'txt' => 'Ajouter au panier',
|
||||||
'data_id' => $article['plants']['offer_id'] ?? null,
|
|
||||||
])
|
])
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
@@ -47,3 +47,10 @@
|
|||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@include('load.layout.modal')
|
@include('load.layout.modal')
|
||||||
|
@include('load.basket')
|
||||||
|
|
||||||
|
@push('js')
|
||||||
|
<script>
|
||||||
|
initBasket();
|
||||||
|
</script>
|
||||||
|
@endpush
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
@component('components.layout.box-collapse', [
|
@component('components.layout.box-collapse', [
|
||||||
'title' => $group['name'],
|
'title' => $group['name'],
|
||||||
'id' => 'tag_group_' . $tag_group_id,
|
'id' => 'tag_group_' . $tag_group_id,
|
||||||
'collapsed' => App\Repositories\Shop\TagGroups::isTagGroupHaveSelected($tags_selected, $group['tags']),
|
'collapsed' => App\Repositories\Shop\TagGroups::isTagGroupHaveSelected($tags_selected ?? [], $group['tags']),
|
||||||
])
|
])
|
||||||
@foreach ($group['tags'] as $tag)
|
@foreach ($group['tags'] as $tag)
|
||||||
<div class="form-inline">
|
<div class="form-inline">
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
@include('components.form.button', ['class' => 'btn-danger ' . ($class ?? ''), 'icon' => ($icon ?? 'fa-trash)'])
|
@include('components.form.button', [
|
||||||
|
'class' => 'btn-danger ' . ($class ?? ''),
|
||||||
|
'icon' => $icon ?? 'fa-trash',
|
||||||
|
])
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
@include('components.form.label')
|
@include('components.form.label')
|
||||||
|
|
||||||
<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 ($style ?? false) style="{{ $style }}" @endif
|
||||||
@if ($required ?? false) required @endif
|
@if ($required ?? false) required @endif
|
||||||
@if ($disabled ?? false) disabled @endif
|
@if ($disabled ?? false) disabled @endif
|
||||||
@if ($readonly ?? false) readonly @endif
|
@if ($readonly ?? false) readonly @endif
|
||||||
|
|||||||
48
resources/views/load/basket.blade.php
Normal file
48
resources/views/load/basket.blade.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
@if(!defined('BASKET'))
|
||||||
|
@push('scripts')
|
||||||
|
<script>
|
||||||
|
function initBasket(sel) {
|
||||||
|
var selector = (typeof(sel) == 'undefined') ? '.basket' : sel;
|
||||||
|
|
||||||
|
$(selector).off().click(function() {
|
||||||
|
var $addBasket = $(this).closest('.addBasket');
|
||||||
|
var offerId = $addBasket.find('.offer_id').val();
|
||||||
|
var quantity = $addBasket.find('.quantity').val();
|
||||||
|
var data = {
|
||||||
|
'offer_id': offerId,
|
||||||
|
'quantity': quantity,
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
var buttons = {
|
||||||
|
cancel: {
|
||||||
|
label: '{{ __('Continuer mes achats') }}',
|
||||||
|
className: 'btn-secondary'
|
||||||
|
},
|
||||||
|
confirm: {
|
||||||
|
label: '{{ __('Commander') }}',
|
||||||
|
className: 'btn-success',
|
||||||
|
callback: function() {
|
||||||
|
window.location = "{{ route('Shop.Basket.basket') }}";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
openModal(
|
||||||
|
'Ajout dans le panier',
|
||||||
|
'basket-form',
|
||||||
|
"{{ route('Shop.Basket.modalBasket') }}/" + offerId + '/' + quantity,
|
||||||
|
"{{ route('Shop.Orders.order') }}",
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
buttons,
|
||||||
|
"refreshBasketTop()",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
@endpush
|
||||||
|
@php(define('BASKET', true))
|
||||||
|
@endif
|
||||||
Reference in New Issue
Block a user