diff --git a/app/Datatables/Shop/ArticlesDataTable.php b/app/Datatables/Shop/ArticlesDataTable.php index 1772f6b4..23ef7257 100644 --- a/app/Datatables/Shop/ArticlesDataTable.php +++ b/app/Datatables/Shop/ArticlesDataTable.php @@ -43,6 +43,28 @@ class ArticlesDataTable extends DataTable public function modifier($datatables) { $datatables + ->editColumn('visible', function (Article $article) { + return view("components.form.toggle", [ + 'name' => 'visible', + 'value' => $article->visible, + 'on' => __('oui'), + 'off' => __('non'), + 'meta' => 'data-id=' . $article->id, + 'size' => 'sm', + 'class' => 'visible', + ]); + }) + ->editColumn('homepage', function (Article $article) { + return view("components.form.toggle", [ + 'name' => 'homepage', + 'value' => $article->homepage, + 'on' => __('oui'), + 'off' => __('non'), + 'meta' => 'data-id=' . $article->id, + 'size' => 'sm', + 'class' => 'homepage', + ]); + }) ->editColumn('thumb', function (Article $article) { $image = Articles::getFullImageByArticle($article); return ''; @@ -64,6 +86,8 @@ class ArticlesDataTable extends DataTable protected function getColumns() { return [ + Column::make('visible')->title('Visible')->searchable(false), + Column::make('homepage')->title('Accueil')->searchable(false), Column::make('article_nature.name')->title('Nature'), Column::make('thumb')->title('')->searchable(false)->orderable(false)->width(40)->class('text-center'), Column::make('name')->title('Nom'), diff --git a/app/Http/Controllers/Admin/Shop/ArticleController.php b/app/Http/Controllers/Admin/Shop/ArticleController.php index 61caef3e..23318eaa 100644 --- a/app/Http/Controllers/Admin/Shop/ArticleController.php +++ b/app/Http/Controllers/Admin/Shop/ArticleController.php @@ -89,4 +89,17 @@ class ArticleController extends Controller $index = $request->input('index'); return Articles::deleteImage($id, $index); } + + public function toggleVisible(Request $request) + { + $data = Articles::toggleVisible($request->input('id'), ($request->input('visible') == 'true') ? 1 : 0); + return response()->json(['error' => 0]); + } + + public function toggleHomepage(Request $request) + { + $data = Articles::toggleHomepage($request->input('id'), ($request->input('homepage') == 'true') ? 1 : 0); + return response()->json(['error' => 0]); + } + } diff --git a/app/Http/Controllers/Shop/BasketController.php b/app/Http/Controllers/Shop/BasketController.php index e9169dfc..29b65297 100644 --- a/app/Http/Controllers/Shop/BasketController.php +++ b/app/Http/Controllers/Shop/BasketController.php @@ -27,16 +27,17 @@ class BasketController extends Controller if (ShopCart::has($offer_id)) { $ret = ShopCart::remove($offer_id); } - $data = Offers::getBasketData($offer_id, $quantity); - $ret = ShopCart::add($data); + $data = $quantity ? Offers::getBasketData($offer_id, $quantity) : false; + $ret = $data ? ShopCart::add($data) : false; return true; } public function basket() { + $data = self::init(); $data['basket'] = Offers::getBasket(); - dump($data['basket']->toArray()); - exit; + //dump($data['basket']); + // exit; return view('Shop.Baskets.basket', $data); } diff --git a/app/Models/Shop/Article.php b/app/Models/Shop/Article.php index 37d3c294..9c0bde82 100644 --- a/app/Models/Shop/Article.php +++ b/app/Models/Shop/Article.php @@ -131,4 +131,9 @@ class Article extends Model implements HasMedia { return $query->where($this->table . '.visible', 1); } + + public function scopeHomepage($query) + { + return $query->where($this->table . '.homepage', 1); + } } diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index eb239575..b3293abf 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -133,49 +133,64 @@ class Articles $data[] = [ 'id' => $shelve->id, 'name' => $shelve->name, - 'articles' => self::getArticlesToSell($shelve->id), + 'articles' => self::getArticlesToSell([ + 'category_id' => $shelve->id, + 'homepage' => true, + ]), ]; } return $data; } - public static function getArticlesToSell($category_id = false, $tags = false) + public static function getArticlesToSell($options) { - $articles = self::getArticlesWithOffers($category_id, $tags); + $articles = self::getArticlesWithOffers($options); foreach ($articles as $article) { $price_lists = $article->offers[0]->tariff->price_lists->toArray(); // dump($price_lists); if (count($price_lists)) { if (!is_array($data[$article->name] ?? false)) { - $data[$article->name] = [ - 'id' => $article->id, - 'description' => (!empty($article->description)) ? $article->description : $article->product->description, - 'image' => self::getFullImageByArticle($article), - 'product_type' => $article->product_type, - 'product_id' => $article->product_id, - 'product_name' => $article->product->name, - 'parent_name' => trim(str_replace($article->product->name, '', $article->name)), - ]; + $data[$article->name] = self::getDataForSale($article); } $prices = $price_lists[0]['price_list_values'][0]; $article_nature_name = strtolower($article->article_nature->name); - // dump($prices); - $data[$article->name][$article_nature_name] = [ - 'article_id' => $article->id, - 'offer_id' => $article->offers[0]->id, - 'quantity' => $prices['quantity'], - 'price' => $prices['price_taxed'], - 'variation' => $article->offers[0]->variation->name, - ]; + $data[$article->name][$article_nature_name] = self::getDataPriceForSale($article, $prices); } } return $data ?? false; } - public static function getArticlesWithOffers($category_id = false, $tags = false, $sale_channel_id = false) + public static function getDataForSale($article) { - $sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID(); - return Article::byCategory($category_id)->byTags($tags)->visible()->withAvailableOffers($sale_channel_id)->with([ + return [ + 'id' => $article->id, + 'description' => (!empty($article->description)) ? $article->description : $article->product->description, + 'image' => self::getFullImageByArticle($article), + 'product_type' => $article->product_type, + 'product_id' => $article->product_id, + 'product_name' => $article->product->name, + 'parent_name' => trim(str_replace($article->product->name, '', $article->name)), + ]; + } + + public static function getDataPriceForSale($article, $prices) + { + return [ + 'article_id' => $article->id, + 'offer_id' => $article->offers[0]->id, + 'quantity' => $prices['quantity'], + 'price' => $prices['price_taxed'], + 'variation' => $article->offers[0]->variation->name, + ]; + } + + public static function getArticlesWithOffers($options = false) + { + $category_id = $options['category_id'] ?? false; + $sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID(); + $tags = $options['tags'] ?? false; + $model = ($options['homepage'] ?? false) ? Article::homepage()->visible() : Article::visible(); + return $model->byCategory($category_id)->byTags($tags)->withAvailableOffers($sale_channel_id)->with([ 'image', 'product', 'article_nature', @@ -187,6 +202,7 @@ class Articles ])->get(); } + public static function getFull($id) { $data['article'] = self::getArticleEdit($id); @@ -452,4 +468,15 @@ class Articles { return Tag::storeTags($article, $tags); } + + public static function toggleVisible($id, $visible) + { + return self::update(['visible' => $visible], $id); + } + + public static function toggleHomepage($id, $homepage) + { + return self::update(['homepage' => $homepage], $id); + } + } diff --git a/app/Repositories/Shop/Offers.php b/app/Repositories/Shop/Offers.php index ce44944c..2f735ad2 100644 --- a/app/Repositories/Shop/Offers.php +++ b/app/Repositories/Shop/Offers.php @@ -18,11 +18,22 @@ class Offers public static function getBasket() { $basket = ShopCart::getContent(); - $offers = Offer::with(['variation', 'article.article_nature'])->whereIn('id', ShopCart::keys())->get(); - dump($basket->toArray()); - dump($offers->toArray()); - exit; - return $data; + // dump($basket->toArray()); + $offers = Offer::with(['variation', 'article.article_nature', 'article.image'])->whereIn('id', ShopCart::keys())->get(); + + foreach ($basket as $item) { + $offer = $offers->where('id', $item->id)->first(); + $article_nature = strtolower($offer->article->article_nature->name); + $data[$article_nature][] = [ + 'id' => (int) $item->id, + 'name' => $item->name, + 'quantity' => (int) $item->quantity, + 'price' => $item->price, + 'variation' => $offer->variation->name, + 'image' => Articles::getPreviewSrc($offer->article->image), + ]; + } + return $data ?? false; } public static function getBasketData($id, $quantity = 1) diff --git a/resources/views/Admin/Shop/Articles/form.blade.php b/resources/views/Admin/Shop/Articles/form.blade.php index c2cee1b2..28ab643d 100644 --- a/resources/views/Admin/Shop/Articles/form.blade.php +++ b/resources/views/Admin/Shop/Articles/form.blade.php @@ -1,79 +1,6 @@
-
-
- - - -
- @include('components.form.toggle', [ - 'name' => 'visible', - 'value' => ($article['visible'] ?? null), - 'on' => __('visible'), - 'off' => __('invisible'), - 'meta' => 'data-id=' . ($article['id'] ?? null), - 'size' => 'sm', - ]) -
-
- -
-
-
- @include('Admin.Shop.Articles.partials.characteristics') -
- -
- -
- -
- @include('Admin.Shop.Articles.partials.shipping') -
- -
- @include('Admin.Shop.Articles.partials.stock') -
- -
- @include('Admin.Shop.Articles.partials.seo') -
-
- -
- -
+ @include('Admin.Shop.Articles.partials.characteristics')
diff --git a/resources/views/Admin/Shop/Articles/list.blade.php b/resources/views/Admin/Shop/Articles/list.blade.php index f925b46f..9ac78d5a 100644 --- a/resources/views/Admin/Shop/Articles/list.blade.php +++ b/resources/views/Admin/Shop/Articles/list.blade.php @@ -6,7 +6,12 @@ @section('content') @component('components.card') - @include('components.datatable', ['route' => route('Admin.Shop.Articles.index'), 'model' => 'articles', 'with_filters' => true]) + @include('components.datatable', [ + 'route' => route('Admin.Shop.Articles.index'), + 'model' => 'articles', + 'with_filters' => true, + 'callback' => 'handleArticle()', + ]) @component('components.layout.modal', ['title' => 'Filtres', 'id' => 'modal-articles-filters']) @include('Admin.Shop.Articles.partials.filters', ['model' => 'articles']) @endcomponent @@ -14,3 +19,17 @@ @endsection @include('load.form.select2') +@include('load.form.toggle') + +@push('js') + +@endpush diff --git a/resources/views/Admin/Shop/Articles/partials/characteristics.blade.php b/resources/views/Admin/Shop/Articles/partials/characteristics.blade.php index 137d27f3..ba059bdc 100644 --- a/resources/views/Admin/Shop/Articles/partials/characteristics.blade.php +++ b/resources/views/Admin/Shop/Articles/partials/characteristics.blade.php @@ -1,6 +1,5 @@
-
{{ Form::label('model', 'Familles de produit') }}
@@ -28,10 +27,32 @@
-
+
{{ Form::label('categories', __('shop.shelves.title')) }}
@include('components.form.select', ['name' => 'categories[]', 'list' => $categories_options, 'values' => $article['categories'] ?? null, 'class' => 'select2', 'multiple' => true])
+
+ {{ Form::label('visible', 'Visible') }}
+ @include('components.form.toggle', [ + 'name' => 'visible', + 'value' => ($article['visible'] ?? null), + 'on' => __('oui'), + 'off' => __('non'), + 'meta' => 'data-id=' . ($article['id'] ?? null), + 'size' => 'sm', + ]) +
+
+ {{ Form::label('homepage', __('Accueil')) }}
+ @include('components.form.toggle', [ + 'name' => 'homepage', + 'value' => ($article['homepage'] ?? null), + 'on' => __('oui'), + 'off' => __('non'), + 'meta' => 'data-id=' . ($article['id'] ?? null), + 'size' => 'sm', + ]) +
diff --git a/resources/views/Shop/Baskets/basket.blade.php b/resources/views/Shop/Baskets/basket.blade.php new file mode 100644 index 00000000..9fd6ef34 --- /dev/null +++ b/resources/views/Shop/Baskets/basket.blade.php @@ -0,0 +1,49 @@ +@extends('Shop.layout.layout', [ + 'title' => __('Panier'), +]) + +@section('content') + @if ($basket) +
+
+
+
+

Panier

+
+
+ Livraison à domicile ...
+ Commande en ligne et livraison par voie postale. Attention certains produits ne sont pas disponibles en livraison. + Les sachets disponibles en lignes sont disponibles à la livraison et uniquement quelques plants. +
+
+ @foreach ($basket as $nature => $items) +
+
+

{{ ucfirst($nature) }}

+ @foreach ($items as $item) + @include('Shop.Baskets.partials.article') + @endforeach +
+ @endforeach +
+
+ @component('components.card') + Tarif appliqué : + @endcomponent +
+
+ @endif +@endsection + +@push('js') + +@endpush \ No newline at end of file diff --git a/resources/views/Shop/Baskets/partials/article.blade.php b/resources/views/Shop/Baskets/partials/article.blade.php new file mode 100644 index 00000000..71a31188 --- /dev/null +++ b/resources/views/Shop/Baskets/partials/article.blade.php @@ -0,0 +1,27 @@ +
+
+ +
+
+

{{ $item['name'] }}

+ {{ $item['variation'] }}
+
+
+ {{ $item['price'] }} € / unité +
+
+ @include('components.form.inputs.number', [ + 'name' => 'quantity', + 'value' => $item['quantity'], + 'class' => 'basket-quantity', + ]) +
+
+ {{ $item['quantity'] * $item['price'] }} € +
+
+ +
+
+
+
\ No newline at end of file diff --git a/resources/views/Shop/Homepage/partials/sliderByShelve.blade.php b/resources/views/Shop/Homepage/partials/sliderByShelve.blade.php index b8919a0d..7508f65a 100644 --- a/resources/views/Shop/Homepage/partials/sliderByShelve.blade.php +++ b/resources/views/Shop/Homepage/partials/sliderByShelve.blade.php @@ -1,31 +1,33 @@ -
-
-
-

{{ $shelve['name'] }}

+@if ($shelve['articles']) +
+
+
+

{{ $shelve['name'] }}

+
+
-
- Découvrir la sélection - Tout voir +
+ @foreach ($shelve['articles'] as $name => $article) + + @endforeach
-
- @foreach ($shelve['articles'] as $name => $article) - - @endforeach -
-
-@push('js') - -@endpush \ No newline at end of file + @push('js') + + @endpush +@endif \ No newline at end of file diff --git a/routes/Admin/Shop/Articles.php b/routes/Admin/Shop/Articles.php index c9a01885..9a9fb5fb 100644 --- a/routes/Admin/Shop/Articles.php +++ b/routes/Admin/Shop/Articles.php @@ -1,20 +1,23 @@ name('Articles.')->group(function () { - Route::get('', 'ArticleController@index')->name('index'); - Route::get('create', 'ArticleController@create')->name('create'); - Route::delete('destroy/{id?}', 'ArticleController@destroy')->name('destroy'); - Route::post('store', 'ArticleController@store')->name('store'); - Route::get('edit/{id}', 'ArticleController@edit')->name('edit'); - - Route::any('getImages/{id?}', 'ArticleController@getImages')->name('getImages'); - Route::post('deleteImage', 'ArticleController@deleteImage')->name('deleteImage'); + Route::get('', 'ArticleController@index')->name('index'); + Route::get('create', 'ArticleController@create')->name('create'); + Route::delete('destroy/{id?}', 'ArticleController@destroy')->name('destroy'); + Route::post('store', 'ArticleController@store')->name('store'); + Route::get('edit/{id}', 'ArticleController@edit')->name('edit'); + + Route::any('getImages/{id?}', 'ArticleController@getImages')->name('getImages'); + Route::post('deleteImage', 'ArticleController@deleteImage')->name('deleteImage'); - Route::any('autocomplete/{q?}', 'ArticleController@autocomplete')->name('autocomplete'); + Route::any('autocomplete/{q?}', 'ArticleController@autocomplete')->name('autocomplete'); + + Route::get('getProductDescription/{product_id?}/{model?}', 'ArticleController@getProductDescription')->name('getProductDescription'); + Route::get('getProductTags/{product_id?}/{model?}', 'ArticleController@getProductTags')->name('getProductTags'); + Route::get('getProductImages/{product_id?}/{model?}', 'ArticleController@getProductImages')->name('getProductImages'); + Route::post('toggleVisible', 'OfferController@toggleVisible')->name('toggleVisible'); + Route::post('toggleHomepage', 'OfferController@toggleHomepage')->name('toggleHomepage'); - Route::get('getProductDescription/{product_id?}/{model?}', 'ArticleController@getProductDescription')->name('getProductDescription'); - Route::get('getProductTags/{product_id?}/{model?}', 'ArticleController@getProductTags')->name('getProductTags'); - Route::get('getProductImages/{product_id?}/{model?}', 'ArticleController@getProductImages')->name('getProductImages'); });