Skip to content

Commit c1ea792

Browse files
Merge pull request #32 from shopperlabs/feature/sho-63-ameliorations-page-produits-categorie-et-correction-des-bugs
Feature/sho 63 ameliorations page produits categorie et correction des bugs
2 parents 405e708 + 2110973 commit c1ea792

File tree

9 files changed

+288
-8
lines changed

9 files changed

+288
-8
lines changed

app/Livewire/Pages/Category/CategoryProducts.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
namespace App\Livewire\Pages\Category;
66

7-
use App\Models\Category;
87
use App\Models\Product;
98
use Illuminate\Contracts\View\View;
10-
use Illuminate\Database\Eloquent\Builder;
119
use Livewire\Component;
10+
use Shopper\Core\Models\Category;
1211

1312
final class CategoryProducts extends Component
1413
{

app/Livewire/Pages/Store.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function render(): View
3333

3434
return view('livewire.pages.store', [
3535
'products' => $query->paginate(12),
36-
'attributes' => Attribute::with('values')->enabled()->get(),
36+
'attributes' => Attribute::with('values')->scopes(['enabled', 'isFilterable'])->get(),
3737
]);
3838
}
3939
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"require": {
88
"php": "^8.2",
99
"darryldecode/cart": "^4.2",
10+
"diglactic/laravel-breadcrumbs": "^9.0",
1011
"guzzlehttp/guzzle": "^7.2",
1112
"laravel/framework": "^11.0",
1213
"laravel/tinker": "^2.8",

composer.lock

Lines changed: 125 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/breadcrumbs.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
7+
/*
8+
|--------------------------------------------------------------------------
9+
| View Name
10+
|--------------------------------------------------------------------------
11+
|
12+
| Choose a view to display when Breadcrumbs::render() is called.
13+
| Built in templates are:
14+
|
15+
| - 'breadcrumbs::bootstrap5' - Bootstrap 5
16+
| - 'breadcrumbs::bootstrap4' - Bootstrap 4
17+
| - 'breadcrumbs::bulma' - Bulma
18+
| - 'breadcrumbs::foundation6' - Foundation 6
19+
| - 'breadcrumbs::json-ld' - JSON-LD Structured Data
20+
| - 'breadcrumbs::materialize' - Materialize
21+
| - 'breadcrumbs::tailwind' - Tailwind CSS
22+
| - 'breadcrumbs::uikit' - UIkit
23+
|
24+
| Or a custom view, e.g. '_partials/breadcrumbs'.
25+
|
26+
*/
27+
28+
'view' => 'breadcrumbs::tailwind',
29+
30+
/*
31+
|--------------------------------------------------------------------------
32+
| Breadcrumbs File(s)
33+
|--------------------------------------------------------------------------
34+
|
35+
| The file(s) where breadcrumbs are defined. e.g.
36+
|
37+
| - base_path('routes/breadcrumbs.php')
38+
| - glob(base_path('breadcrumbs/*.php'))
39+
|
40+
*/
41+
42+
'files' => base_path('routes/breadcrumbs/breadcrumbs.php'),
43+
44+
/*
45+
|--------------------------------------------------------------------------
46+
| Exceptions
47+
|--------------------------------------------------------------------------
48+
|
49+
| Determine when to throw an exception.
50+
|
51+
*/
52+
53+
// When route-bound breadcrumbs are used but the current route doesn't have a name (UnnamedRouteException)
54+
'unnamed-route-exception' => true,
55+
56+
// When route-bound breadcrumbs are used and the matching breadcrumb doesn't exist (InvalidBreadcrumbException)
57+
'missing-route-bound-breadcrumb-exception' => true,
58+
59+
// When a named breadcrumb is used but doesn't exist (InvalidBreadcrumbException)
60+
'invalid-named-breadcrumb-exception' => true,
61+
62+
/*
63+
|--------------------------------------------------------------------------
64+
| Classes
65+
|--------------------------------------------------------------------------
66+
|
67+
| Subclass the default classes for more advanced customisations.
68+
|
69+
*/
70+
71+
// Manager
72+
'manager-class' => Diglactic\Breadcrumbs\Manager::class,
73+
74+
// Generator
75+
'generator-class' => Diglactic\Breadcrumbs\Generator::class,
76+
77+
];

resources/views/livewire/category/category-products.blade.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,23 @@
1010
@forelse($products as $product)
1111
<x-products.card :product="$product" />
1212
@empty
13-
<p class="col-span-3 text-center text-gray-500">
14-
{{ __('This is an example of a category product. it does not contain any products.') }}
15-
</p>
13+
<div class="col-span-3 ml-32 space-y-4">
14+
<p class="text-gray-500">{{ __('This is an example of a category product. it does not contain any products.') }}</p>
15+
@if($category->children->isNotEmpty())
16+
<div class="flex flex-col">
17+
@foreach($category->children->filter(function($child) {
18+
return $child->is_enabled;
19+
}) as $child)
20+
<x-link class="flex items-center font-heading text-primary-600 text-md hover:text-primary-800" :href="route('category.products',['category'=> $child->slug])">
21+
{{ $child->name }}
22+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="ml-1 size-4">
23+
<path stroke-linecap="round" stroke-linejoin="round" d="m4.5 19.5 15-15m0 0H8.25m11.25 0v11.25" />
24+
</svg>
25+
</x-link>
26+
@endforeach
27+
</div>
28+
@endif
29+
</div>
1630
@endforelse
1731
</div>
1832
</div>

resources/views/livewire/pages/single-product.blade.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<div class="bg-white">
2+
<div class="py-3 bg-white border-b border-gray-200 bg-opacity-80">
3+
<x-container class="flex items-center justify-between px-4">
4+
{{ Breadcrumbs::render('product', $selectedVariant ?? $product) }}
5+
</x-container>
6+
</div>
7+
28
<div class="pt-10 pb-16 sm:pb-24">
39
<x-container class="max-w-2xl mt-8">
4-
<!-- Product -->
10+
<!-- Product -->
511
<div class="lg:grid lg:grid-cols-2 lg:items-start lg:gap-x-8">
612
<!-- Image gallery -->
713
<div class="flex flex-col">
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<nav class="flex" aria-label="Breadcrumb">
2+
@unless ($breadcrumbs->isEmpty())
3+
<ol role="list" class="flex items-center space-x-4">
4+
@foreach ($breadcrumbs as $breadcrumb)
5+
@if($loop->first)
6+
<li>
7+
<div>
8+
<x-link :href="$breadcrumb->url" class="text-gray-400 hover:text-gray-500">
9+
<svg class="size-5 shrink-0" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" data-slot="icon">
10+
<path fill-rule="evenodd" d="M9.293 2.293a1 1 0 0 1 1.414 0l7 7A1 1 0 0 1 17 11h-1v6a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1v-3a1 1 0 0 0-1-1H9a1 1 0 0 0-1 1v3a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-6H3a1 1 0 0 1-.707-1.707l7-7Z" clip-rule="evenodd" />
11+
</svg>
12+
<span class="sr-only">{{ $breadcrumb->title }}</span>
13+
</x-link>
14+
</div>
15+
</li>
16+
@else
17+
<li>
18+
<div class="flex items-center">
19+
<svg class="size-5 shrink-0 text-gray-300" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true">
20+
<path d="M5.555 17.776l8-16 .894.448-8 16-.894-.448z" />
21+
</svg>
22+
<x-link :href="$breadcrumb->url" class="ml-4 text-sm font-medium text-gray-500 hover:text-gray-700">{{ $breadcrumb->title }}</x-link>
23+
</div>
24+
</li>
25+
@endif
26+
@endforeach
27+
</ol>
28+
@endunless
29+
</nav>

routes/breadcrumbs/breadcrumbs.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Diglactic\Breadcrumbs\Breadcrumbs;
6+
use Diglactic\Breadcrumbs\Generator;
7+
8+
Breadcrumbs::for('home', function (Generator $trail) {
9+
$trail->push('Home', route('home'));
10+
});
11+
12+
Breadcrumbs::for('store', function (Generator $trail) {
13+
$trail->parent('home');
14+
$trail->push('store', route('store.products'));
15+
});
16+
17+
Breadcrumbs::for('category', function (Generator $trail, $category) {
18+
$trail->parent('home');
19+
$trail->push($category->slug, route('category.products', $category));
20+
});
21+
22+
Breadcrumbs::for('collection', function (Generator $trail, $collection) {
23+
$trail->parent('home');
24+
$trail->push($collection->slug, route('collection.products', $collection));
25+
});
26+
27+
Breadcrumbs::for('product', function (Generator $trail, $product) {
28+
$trail->parent('store');
29+
$trail->push($product->slug, route('single-product', $product));
30+
});

0 commit comments

Comments
 (0)