From cc9672ddca4437d6fc2bca57cae661e4cc9836b3 Mon Sep 17 00:00:00 2001 From: ludo Date: Tue, 31 Oct 2023 17:05:41 +0100 Subject: [PATCH] fix basket --- .../Controllers/Shop/CategoryController.php | 44 ++-------------- app/Repositories/Shop/Shelves.php | 50 +++++++++++++++++++ .../Core/Auth/Permission/manage.blade.php | 2 +- .../Admin/Core/Auth/Role/manage.blade.php | 2 +- .../Admin/Core/Auth/Team/manage.blade.php | 2 +- .../Admin/Core/Auth/User/manage.blade.php | 2 +- .../partials/ArticleAddBasket.blade.php | 38 ++------------ .../Articles/partials/addBasket.blade.php | 5 +- .../partials/article_rows_botanic.blade.php | 24 ++++++--- resources/views/Shop/Shelves/shelve.blade.php | 7 +++ .../views/Shop/Tags/partials/filter.blade.php | 2 +- .../form/buttons/button-delete.blade.php | 5 +- .../components/form/inputs/number.blade.php | 1 + resources/views/load/basket.blade.php | 48 ++++++++++++++++++ 14 files changed, 144 insertions(+), 88 deletions(-) create mode 100644 app/Repositories/Shop/Shelves.php create mode 100644 resources/views/load/basket.blade.php diff --git a/app/Http/Controllers/Shop/CategoryController.php b/app/Http/Controllers/Shop/CategoryController.php index ff276173..4c93ebd7 100644 --- a/app/Http/Controllers/Shop/CategoryController.php +++ b/app/Http/Controllers/Shop/CategoryController.php @@ -2,56 +2,22 @@ namespace App\Http\Controllers\Shop; -use App\Datatables\Shop\CategoriesDataTable; use App\Http\Controllers\Controller; use App\Repositories\Shop\ArticleNatures; use App\Repositories\Shop\Articles; use App\Repositories\Shop\Categories; +use App\Repositories\Shop\Shelves; use App\Repositories\Shop\TagGroups; use Illuminate\Http\Request; class CategoryController extends Controller { - public function index(CategoriesDataTable $dataTable) - { - return $dataTable->render('Shop.Categories.list'); - } - public function show(Request $request, $categoryId, $articleNatureId = false) { - $articleNatures = Articles::getArticleNaturesWithOffers([ - 'category_id' => $categoryId, - ]); - - 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), - ]; + $articleNature = $request->input('article_nature') ?? false; + $displayByRows = $request->input('display_by_rows') ?? false; + $tags = $request->input('tags') ?? []; + $data = Shelves::getOffersByCategoryAndNature($categoryId, $articleNatureId, $tags, $articleNature, $displayByRows); // dump($data); // exit; diff --git a/app/Repositories/Shop/Shelves.php b/app/Repositories/Shop/Shelves.php new file mode 100644 index 00000000..245ef4ba --- /dev/null +++ b/app/Repositories/Shop/Shelves.php @@ -0,0 +1,50 @@ + $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), + ]; + } +} diff --git a/resources/views/Admin/Core/Auth/Permission/manage.blade.php b/resources/views/Admin/Core/Auth/Permission/manage.blade.php index 1b539baa..a8319931 100644 --- a/resources/views/Admin/Core/Auth/Permission/manage.blade.php +++ b/resources/views/Admin/Core/Auth/Permission/manage.blade.php @@ -39,7 +39,7 @@ + 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()", + ); + }); + } + + @endpush + @php(define('BASKET', true)) +@endif \ No newline at end of file