[WIP] begin of new display for article, shelves

This commit is contained in:
Ludovic CANDELLIER
2022-06-13 23:29:05 +02:00
parent e31978b1e3
commit b37321daf8
13 changed files with 163 additions and 98 deletions

View File

@@ -20,16 +20,19 @@ class CategoryController extends Controller
return $dataTable->render('Shop.Categories.list'); return $dataTable->render('Shop.Categories.list');
} }
public function show($category_id, $by_rows = false) public function show(Request $request, $category_id)
{ {
$data = self::init(); $data = self::init();
$data['display_by_rows'] = $by_rows;
$data['category'] = Categories::getFull($category_id); $data['category'] = Categories::getFull($category_id);
$data['breadcrumb'] = Categories::getAncestorsByCategory($category_id); $data['breadcrumb'] = Categories::getAncestorsByCategory($category_id);
$data['tags_selected'] = request()->input('tags') ?? []; $data['display_by_rows'] = $request->input('display_by_rows') ?? false;
$data['product_type'] = $request->input('product_type') ?? 'botanic';
$data['tags_selected'] = $request->input('tags') ?? [];
$data['articles'] = Articles::getArticlesToSell([ $data['articles'] = Articles::getArticlesToSell([
'category_id' => $category_id, 'category_id' => $category_id,
'tags' => $data['tags_selected'], 'tags' => $data['tags_selected'],
'product_type' => $data['product_type'],
]); ]);
// dump($data['articles']); // dump($data['articles']);
// exit; // exit;

View File

@@ -17,7 +17,7 @@ class HomeController extends Controller
$data = self::init(); $data = self::init();
$data['display_by_rows'] = $input['by_rows'] ?? false; $data['display_by_rows'] = $input['by_rows'] ?? false;
$data['shelves'] = Articles::getArticlesByHomepage(); $data['shelves'] = Articles::getArticlesByHomepage();
$data['text'] = Homepages::getLast(); $data['text'] = Homepages::getHomepage();
// dump($data['shelves']); // dump($data['shelves']);
// exit; // exit;
$data['tags'] = TagGroups::getWithTagsAndCountOffers(); $data['tags'] = TagGroups::getWithTagsAndCountOffers();

View File

@@ -16,6 +16,9 @@ use Staudenmeir\EloquentHasManyDeep\HasRelationships;
use App\Traits\Model\HasComments; use App\Traits\Model\HasComments;
use App\Traits\Model\Imageable; use App\Traits\Model\Imageable;
use App\Models\Botanic\Variety;
use App\Models\Botanic\Specie;
class Article extends Model implements HasMedia class Article extends Model implements HasMedia
{ {
use Categorizable, EloquentJoin, HasComments, HasRelationships, Imageable, Powerjoins, Taggable, SoftDeletes, UserStamps; use Categorizable, EloquentJoin, HasComments, HasRelationships, Imageable, Powerjoins, Taggable, SoftDeletes, UserStamps;
@@ -99,6 +102,11 @@ class Article extends Model implements HasMedia
return $query->where($this->table . '.article_nature_id', $id); return $query->where($this->table . '.article_nature_id', $id);
} }
public function scopeByArticleNatures($query, $ids)
{
return $query->whereIn($this->table . '.article_nature_id', $ids);
}
public function scopeByCategories($query, $categories_id) public function scopeByCategories($query, $categories_id)
{ {
return $categories_id ? $query->whereHas('categories', function ($query) use ($categories_id) { return $categories_id ? $query->whereHas('categories', function ($query) use ($categories_id) {
@@ -121,6 +129,16 @@ class Article extends Model implements HasMedia
}) : $query; }) : $query;
} }
public function scopeBotanic($query)
{
return $query->whereIn($this->table . '.product_type', [Variety::class, Specie::class]);
}
public function scopeMerchandise($query)
{
return $query->byProduct(Merchandise::class);
}
public function scopeByProduct($query, $model) public function scopeByProduct($query, $model)
{ {
return $query->where($this->table . '.product_type', $model); return $query->where($this->table . '.product_type', $model);

View File

@@ -219,12 +219,16 @@ class Articles
$search = $options['search'] ?? false; $search = $options['search'] ?? false;
$tags = $options['tags'] ?? false; $tags = $options['tags'] ?? false;
$article_nature_id = $options['article_nature_id'] ?? false; $article_nature_id = $options['article_nature_id'] ?? false;
$article_nature_ids = $options['article_nature_ids'] ?? false;
$product_type = $options['product_type'] ?? false;
$model = ($options['homepage'] ?? false) ? Article::homepage()->visible() : Article::visible(); $model = ($options['homepage'] ?? false) ? Article::homepage()->visible() : Article::visible();
$model = $category_id ? $model->byCategoryParent($category_id) : $model; $model = $category_id ? $model->byCategoryParent($category_id) : $model;
$model = $tags ? $model->byTagsSelected($tags) : $model; $model = $tags ? $model->byTagsSelected($tags) : $model;
$model = $search ? $model->search($search) : $model; $model = $search ? $model->search($search) : $model;
$model = $article_nature_id ? $model->byArticleNature($article_nature_id) : $model; $model = $article_nature_id ? $model->byArticleNature($article_nature_id) : $model;
$model = $article_nature_ids ? $model->byArticleNatures($article_nature_ids) : $model;
$model = ($product_type == 'botanic') ? $model->botanic() : $model->merchandise();
return $model; return $model;
} }
@@ -453,19 +457,19 @@ class Articles
switch ($article->product_type) { switch ($article->product_type) {
case 'App\Models\Botanic\Variety': case 'App\Models\Botanic\Variety':
$variety = $article->product; $variety = $article->product;
$image = $variety->image; $image = $variety->image ?? false;
if (!$image) { if (!$image) {
$specie = $variety->specie; $specie = $variety->specie;
$image = $specie->image; $image = $specie->image ?? false;
} }
break; break;
case 'App\Models\Botanic\Specie': case 'App\Models\Botanic\Specie':
$specie = $article->product; $specie = $article->product;
$image = $specie->image; $image = $specie->image ?? false;
break; break;
case 'App\Models\Shop\Merchandise': case 'App\Models\Shop\Merchandise':
$merchandise = $article->product; $merchandise = $article->product;
$image = $merchandise->image; $image = $merchandise->image ?? false;
break; break;
} }
} }

View File

@@ -13,6 +13,11 @@ class Homepages
return $model ? $model->text : ''; return $model ? $model->text : '';
} }
public static function getHomepage()
{
return self::get(1)->text;
}
public static function get($id) public static function get($id)
{ {
return Homepage::find($id); return Homepage::find($id);

View File

@@ -1,5 +1,5 @@
<a href="{{ route('Shop.Articles.show', ['id' => $article['semences']['article_id'] ?? false ]) }}" class="green-dark"> <a href="{{ route('Shop.Articles.show', ['id' => $article['semences']['article_id'] ?? false ]) }}" class="{{ ($product_type == 'botanic') ? 'green-dark' : 'green-dark' }}">
<div class="card bg-green-light"> <div class="card {{ ($product_type == 'botanic') ? 'bg-yellow' : 'bg-green-light' }}">
<img src="{{ App\Repositories\Shop\Articles::getPreviewSrc($article['image'] ?? false) }}" class="card-img-top" alt="{{ $product_name }}"> <img src="{{ App\Repositories\Shop\Articles::getPreviewSrc($article['image'] ?? false) }}" class="card-img-top" alt="{{ $product_name }}">
<div class="card-body"> <div class="card-body">
<div class="row card-title"> <div class="row card-title">
@@ -11,29 +11,7 @@
<div class="text-truncate">{{ $article['product_name'] }}</div> <div class="text-truncate">{{ $article['product_name'] }}</div>
</div> </div>
</div> </div>
@include('Shop.Articles.partials.article_' . $product_type)
<div class="row">
<div class="col-6">
<span style="font-size: 1.4em">
@if ($article['semences'] ?? false)
{{ $article['semences']['price'] ?? null }}</span>
@else
-
@endif
</span><br/>
<strong>Semence</strong>
</div>
<div class="col-6">
<span style="font-size: 1.4em">
@if ($article['plants'] ?? false)
{{ $article['plants']['price'] }}</span>
@else
-
@endif
</span><br/>
<strong>Plant</strong>
</div>
</div>
</div> </div>
</div> </div>
</a> </a>

View File

@@ -0,0 +1,22 @@
<div class="row">
<div class="col-6">
<span style="font-size: 1.4em">
@if ($article['semences'] ?? false)
{{ $article['semences']['price'] ?? null }}</span>
@else
-
@endif
</span><br/>
<strong>Semence</strong>
</div>
<div class="col-6">
<span style="font-size: 1.4em">
@if ($article['plants'] ?? false)
{{ $article['plants']['price'] }}</span>
@else
-
@endif
</span><br/>
<strong>Plant</strong>
</div>
</div>

View File

@@ -0,0 +1,12 @@
<div class="row">
<div class="col-12">
<span style="font-size: 1.4em">
@if ($article['merchandises'] ?? false)
{{ $article['merchandises']['price'] ?? null }}</span>
@else
-
@endif
</span><br/>
<strong>Marchandise</strong>
</div>
</div>

View File

@@ -1,5 +1,5 @@
<div class="row pb-3 bg-light"> <div class="row pb-3 bg-light">
<div class="col-8"> <div class="col-9">
<div class="row pt-2"> <div class="row pt-2">
<div class="col-10"> <div class="col-10">
<a href="{{ route('Shop.Articles.show', ['id' => $article['id'] ?? false ]) }}" class="green-dark"> <a href="{{ route('Shop.Articles.show', ['id' => $article['id'] ?? false ]) }}" class="green-dark">
@@ -25,37 +25,10 @@
</div> </div>
</a> </a>
</div> </div>
<div class="col-4"> <div class="col-3">
<div class="row h-100"> <div class="row h-100">
<div class="col-6"> <div class="col-12">
@if ($article['semences'] ?? false) @include('Shop.Articles.partials.article_rows_' . $product_type)
<div class="w-100 mt-3 p-1 bg-green-light green-dark rounded-lg border border-success text-center">
<span style="font-size: 1.4em; font-weight: bold;">{{ $article['semences']['price'] ?? null }}</span> <br>
{{ $article['semences']['variation'] }}
<div>
Quantité : 1
</div>
@include('components.form.button', [
'class' => 'btn-green-dark basket semences mb-3 mt-2 shadow',
'txt' => 'Ajouter au panier',
])
</div>
@endif
</div>
<div class="col-6">
@if ($article['plants'] ?? false)
<div class="w-100 mt-3 p-1 bg-yellow-light yellow-dark border border-warning text-center">
<span style="font-size: 1.4em; font-weight: bold;">{{ $article['plants']['price'] ?? null }}</span> <br>
{{ $article['plants']['variation'] }}
<div>
Quantité : 1
</div>
@include('components.form.button', [
'class' => 'btn-success basket semences mb-3 mt-2 shadow',
'txt' => 'Ajouter au panier',
])
</div>
@endif
</div> </div>
</div> </div>
</div> </div>

View File

@@ -0,0 +1,26 @@
@if ($article['semences'] ?? false)
<div class="w-100 mt-3 p-1 bg-green-light green-dark rounded-lg border border-success text-center">
<span style="font-size: 1.4em; font-weight: bold;">{{ $article['semences']['price'] ?? null }}</span> <br>
{{ $article['semences']['variation'] }}
<div>
Quantité : 1
</div>
@include('components.form.button', [
'class' => 'btn-green-dark basket semences mb-3 mt-2 shadow',
'txt' => 'Ajouter au panier',
])
</div>
@endif
@if ($article['plants'] ?? false)
<div class="w-100 mt-3 p-1 bg-yellow-light yellow-dark border border-warning text-center">
<span style="font-size: 1.4em; font-weight: bold;">{{ $article['plants']['price'] ?? null }}</span> <br>
{{ $article['plants']['variation'] }}
<div>
Quantité : 1
</div>
@include('components.form.button', [
'class' => 'btn-success basket semences mb-3 mt-2 shadow',
'txt' => 'Ajouter au panier',
])
</div>
@endif

View File

@@ -0,0 +1,13 @@
@if ($article['merchandises'] ?? false)
<div class="w-100 mt-3 p-1 bg-yellow-light yellow-dark border border-warning text-center">
<span style="font-size: 1.4em; font-weight: bold;">{{ $article['merchandises']['price'] ?? null }}</span> <br>
{{ $article['merchandises']['variation'] }}
<div>
Quantité : 1
</div>
@include('components.form.button', [
'class' => 'btn-success basket merchandises mb-3 mt-2 shadow',
'txt' => 'Ajouter au panier',
])
</div>
@endif

View File

@@ -6,8 +6,8 @@
@include('components.form.button', ['id' => 'by_rows', 'icon' => 'fa-list', 'class' => 'btn-secondary']) @include('components.form.button', ['id' => 'by_rows', 'icon' => 'fa-list', 'class' => 'btn-secondary'])
@endif @endif
@include('components.form.button', ['id' => 'semences', 'icon' => 'fa-leaf', 'class' => 'bg-yellow yellow-dark']) @include('components.form.button', ['data_id' => 'botanic', 'icon' => 'fa-leaf', 'class' => 'products bg-yellow yellow-dark'])
@include('components.form.button', ['id' => 'plants', 'icon' => 'fa-seedling', 'class' => 'bg-green text-white']) @include('components.form.button', ['data_id' => 'merchandise', 'icon' => 'fa-seedling', 'class' => 'products bg-green text-white'])
</div> </div>
</div> </div>
@@ -15,12 +15,16 @@
@push('js') @push('js')
<script> <script>
$('#by_rows').click(function() { $('#by_rows').click(function() {
var url = "{{ route('Shop.Categories.show', ['id' => $category['id'], 'by_rows' => true]) }}"; $('#display_by_rows').val(1);
window.location = url; $('#category-form').submit();
}) });
$('#by_cards').click(function() { $('#by_cards').click(function() {
var url = "{{ route('Shop.Categories.show', ['id' => $category['id']]) }}"; $('#display_by_rows').val(0);
window.location = url; $('#category-form').submit();
}) });
$('.products').click(function() {
$('#product_type').val($(this).data('id'));
$('#category-form').submit();
});
</script> </script>
@endpush @endpush

View File

@@ -3,6 +3,11 @@
]) ])
@section('content') @section('content')
{{ Form::open(['id' => 'category-form', 'autocomplete' => 'off']) }}
<input type="hidden" id="display_by_rows" name="display_by_rows" value="{{ $display_by_rows ?? false }}">
<input type="hidden" id="product_type" name="product_type" value="{{ $product_type ?? false }}">
<div class="row mb-3"> <div class="row mb-3">
<div class="col-3"> <div class="col-3">
@include('Shop._partials.display_filters') @include('Shop._partials.display_filters')
@@ -30,4 +35,6 @@
@else @else
@include('Shop.Shelves.partials.category_articles') @include('Shop.Shelves.partials.category_articles')
@endif @endif
</form>
@endsection @endsection