Skip to content

Commit 7c646f4

Browse files
authored
feat: upgrade shopper version (#34)
* feat: upgrade shopper version * feat: update shopper and fix home page
1 parent 72aa5df commit 7c646f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+679
-3247
lines changed

.env.example

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@ LOG_CHANNEL=stack
88
LOG_DEPRECATIONS_CHANNEL=null
99
LOG_LEVEL=debug
1010

11-
DB_CONNECTION=sqlite
12-
# DB_HOST=127.0.0.1
13-
# DB_PORT=3306
14-
# DB_DATABASE=shopper
15-
# DB_USERNAME=root
16-
# DB_PASSWORD=
11+
DB_CONNECTION=mysql
12+
DB_HOST=127.0.0.1
13+
DB_PORT=3306
14+
DB_DATABASE=shopper
15+
DB_USERNAME=root
16+
DB_PASSWORD=
17+
18+
SESSION_DRIVER=file
19+
SESSION_LIFETIME=120
20+
SESSION_ENCRYPT=false
21+
SESSION_PATH=/
22+
SESSION_DOMAIN=null
1723

1824
BROADCAST_DRIVER=log
19-
CACHE_DRIVER=file
2025
FILESYSTEM_DISK=local
2126
QUEUE_CONNECTION=sync
22-
SESSION_DRIVER=file
23-
SESSION_LIFETIME=120
27+
28+
CACHE_STORE=file
29+
CACHE_PREFIX=
2430

2531
MEMCACHED_HOST=127.0.0.1
2632

app/DTO/PriceData.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\DTO;
6+
7+
use Shopper\Core\Helpers\Price;
8+
9+
final class PriceData
10+
{
11+
public function __construct(
12+
public Price $amount,
13+
public ?Price $compare,
14+
public ?float $percentage,
15+
) {}
16+
}

app/Livewire/Modals/Customer/AddressForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use App\Actions\CountriesWithZone;
88
use App\Actions\ZoneSessionManager;
9-
use App\Models\Country;
109
use Filament\Notifications\Notification;
1110
use Illuminate\Contracts\View\View;
1211
use Illuminate\Support\Collection;
@@ -15,6 +14,7 @@
1514
use LivewireUI\Modal\ModalComponent;
1615
use Shopper\Core\Enum\AddressType;
1716
use Shopper\Core\Models\Address;
17+
use Shopper\Core\Models\Country;
1818

1919
final class AddressForm extends ModalComponent
2020
{

app/Livewire/Modals/ZoneSelector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function selectZone(int $countryId): void
3535

3636
if ($selectedZone->countryId !== ZoneSessionManager::getSession()?->countryId) {
3737
ZoneSessionManager::setSession($selectedZone);
38+
3839
session()->forget('checkout');
3940

4041
$this->dispatch('zoneChanged');

app/Livewire/Pages/Home.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ final class Home extends Component
1616
public function render(): View
1717
{
1818
return view('livewire.pages.home', [
19-
'products' => Product::with(['brand', 'media'])
19+
'products' => Product::query()
20+
->select('id', 'name', 'slug', 'brand_id')
21+
->with([
22+
'brand',
23+
'media',
24+
'prices' => function ($query) {
25+
$query->whereRelation('currency', 'code', current_currency());
26+
},
27+
'prices.currency',
28+
])
2029
->scopes('publish')
2130
->limit(8)
2231
->get(),

app/Livewire/Pages/SingleProduct.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,31 @@ final class SingleProduct extends Component
1717
#[Url(except: '')]
1818
public string $variant = '';
1919

20-
public function mount(Product $product): void
20+
public function mount(): void
2121
{
22-
abort_unless($product->isPublished(), 404);
22+
abort_unless($this->product->isPublished(), 404);
2323

24-
$this->product = $product->load([
24+
$this->product->load([
25+
'brand',
2526
'media',
2627
'relatedProducts',
27-
'variants',
28-
'variants.media',
28+
'prices' => function ($query) {
29+
$query->whereRelation('currency', 'code', current_currency());
30+
},
31+
'prices.currency',
2932
]);
3033
}
3134

3235
#[Computed]
33-
public function getAverageRatingProperty(): float
36+
public function averageRating(): float
3437
{
3538
return floatval($this->product->averageRating(1)->first());
3639
}
3740

3841
public function render(): View
3942
{
4043
return view('livewire.pages.single-product', [
41-
'selectedVariant' => Product::with('media')
42-
->where('slug', $this->variant)
43-
->select('name', 'slug', 'sku', 'id', 'price_amount', 'old_price_amount')
44-
->first(),
44+
'selectedVariant' => null,
4545
])
4646
->title($this->product->name);
4747
}

app/Livewire/Pages/Store.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class Store extends Component
2121

2222
public function render(): View
2323
{
24-
$query = Product::with(['media', 'attributes'])
25-
->scopes(['parent', 'publish'])
24+
$query = Product::with(['media', 'attributes', 'prices', 'prices.currency'])
25+
->scopes(['publish'])
2626
->latest();
2727

2828
if (count($this->selectedAttributes) > 0) {

app/Models/Country.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/Models/Product.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,15 @@
44

55
namespace App\Models;
66

7-
use Illuminate\Database\Eloquent\Builder;
8-
use Illuminate\Database\Eloquent\Casts\Attribute;
7+
use App\Traits\HasProductPricing;
98
use Shopper\Core\Models\Product as Model;
109

1110
final class Product extends Model
1211
{
12+
use HasProductPricing;
13+
1314
public function isPublished(): bool
1415
{
1516
return $this->is_visible && $this->published_at && $this->published_at <= now();
1617
}
17-
18-
public function discountPercentage(): Attribute
19-
{
20-
return Attribute::make(
21-
get: fn () => $this->old_price_amount > 0
22-
? round((($this->old_price_amount - $this->price_amount) / $this->old_price_amount) * 100)
23-
: 0
24-
);
25-
}
26-
27-
public function scopeParent(Builder $query): void
28-
{
29-
$query->whereNull('parent_id');
30-
}
3118
}

app/Models/ProductVariant.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Models;
6+
7+
use App\Traits\HasProductPricing;
8+
use Shopper\Core\Models\ProductVariant as Model;
9+
10+
final class ProductVariant extends Model
11+
{
12+
use HasProductPricing;
13+
}

0 commit comments

Comments
 (0)