Skip to content

Commit

Permalink
fix product prices and disable implicite lazy loading Model (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
mckenziearts authored Jan 14, 2025
1 parent 57bb692 commit 3c51a79
Show file tree
Hide file tree
Showing 43 changed files with 195 additions and 147 deletions.
2 changes: 2 additions & 0 deletions packages/admin/resources/lang/fr/pages/settings/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
'zone_description' => "Gérer l'expédition, le paiement et l'exécution dans toutes les zones",
'tax' => 'Tax',
'tax_description' => 'Gérez la façon dont votre boutique facture les taxes.',
'sales' => 'Cannaux de vente',
'sales_description' => 'Gérez les canaux en ligne et hors ligne sur lesquels vous vendez vos produits.',

];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<x-shopper::container>
<div class="grid grid-cols-1 gap-x-4 gap-y-6 sm:grid-cols-3">
@forelse ($addresses as $address)
@forelse ($this->addresses as $address)
<x-shopper::card class="relative flex items-center px-6 py-5">
<div class="min-w-0 flex-1">
<div class="focus:outline-none">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<x-shopper::container class="space-y-8">
@if ($orders->isNotEmpty())
@foreach ($orders as $order)
@if ($this->orders->isNotEmpty())
@foreach ($this->orders as $order)
@php
$total = $order->total() + (int) $order->shippingOption?->price;
@endphp
Expand Down Expand Up @@ -168,7 +168,7 @@ class="inline-flex items-center text-sm leading-5 text-primary-600 underline hov
</div>
@endforeach

{{ $orders->links() }}
{{ $this->orders->links() }}
@else
<x-shopper::card class="sm:col-span-3">
<x-shopper::empty-card
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@php
$total = $this->table->getRecords()->total();
@endphp

<x-shopper::container class="py-5">
<x-shopper::heading :title="__('shopper::pages/brands.menu')">
<x-slot name="action">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@php
$total = $this->table->getQuery()->count();
$total = $this->table->getRecords()->total();
@endphp

<x-shopper::container class="py-5">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@php
$total = $this->table->getRecords()->total();
@endphp

<x-shopper::container class="py-5">
<x-shopper::heading :title="__('shopper::pages/collections.menu')">
<x-slot name="action">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@php
$total = $this->table->getRecords()->total();
@endphp

<x-shopper::container class="py-5">
<x-shopper::heading :title="__('shopper::pages/customers.menu')">
<x-slot name="action">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ class="hidden h-0.5 w-0.5 flex-none fill-gray-300 dark:fill-gray-500 sm:block"

<div class="mt-10">
<div x-show="currentTab === 'profile'">
<livewire:shopper-customers.profile :customer="$customer" />
<livewire:shopper-customers.profile :$customer />
</div>
<div x-cloak x-show="currentTab === 'address'">
<livewire:shopper-customers.addresses :adresses="$customer->addresses" />
<livewire:shopper-customers.addresses :$customer />
</div>
<div x-cloak x-show="currentTab === 'orders'">
<livewire:shopper-customers.orders :customer="$customer" />
<livewire:shopper-customers.orders :$customer />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@php
$total = $this->table->getRecords()->total();
@endphp

<x-shopper::container class="py-5">
<x-shopper::heading :title="__('shopper::pages/discounts.menu')">
<x-slot name="action">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<div>
@php
$shippingOption = $this->order->shippingOption;
$billingAddress = $this->order->billingAddress;
$shippingAddress = $this->order->shippingAddress;
$total = $order->total() + $shippingOption?->price;
$customer = $this->customer;
@endphp

<x-shopper::container class="py-5">
Expand Down Expand Up @@ -396,32 +401,32 @@ class="flex size-10 items-center justify-center rounded-full bg-gray-400 ring-4
{{ __('shopper::words.customer') }}
</h3>
<div class="mt-4 space-y-4">
@if ($order->customer)
@if ($customer)
<div class="flex items-center space-x-4">
<div class="shrink-0">
<img
class="size-8 rounded-full"
src="{{ $order->customer->picture }}"
src="{{ $customer->picture }}"
alt="Customer profile"
/>
</div>
<div class="min-w-0 flex-1">
<p class="truncate text-sm font-medium text-gray-900 dark:text-white">
{{ $order->customer->full_name }}
{{ $customer->full_name }}
</p>
</div>
<div>
<x-shopper::link
href="{{ route('shopper.customers.show', $order->customer) }}"
href="{{ route('shopper.customers.show', $customer) }}"
class="inline-flex items-center rounded-full border border-gray-300 bg-white px-2.5 py-0.5 text-sm font-medium leading-5 text-gray-700 shadow-sm hover:bg-gray-50 dark:border-white/10 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700"
>
{{ __('shopper::words.view') }}
</x-shopper::link>
</div>
</div>
<p class="text-sm leading-5 text-gray-500 dark:text-gray-400">
{{ __('shopper::pages/orders.customer_date', ['date' => $order->customer->created_at->diffForHumans()]) }},
{{ __('shopper::pages/orders.customer_orders', ['number' => $order->customer->orders->count()]) }}
{{ __('shopper::pages/orders.customer_date', ['date' => $customer->created_at->diffForHumans()]) }},
{{ __('shopper::pages/orders.customer_orders', ['number' => $customer->orders_count]) }}
</p>
@else
<div
Expand All @@ -443,18 +448,19 @@ class="size-5 text-gray-400 dark:text-gray-500"
<h3 class="text-xs font-medium uppercase leading-4 tracking-wider text-gray-900 dark:text-white">
{{ __('shopper::pages/orders.customer_infos') }}
</h3>
@if ($order->customer)

@if ($customer)
<div class="space-y-1">
<p class="text-sm leading-5 text-gray-500 dark:text-gray-400">
<a
href="mailto:{{ $order->customer->email }}"
href="mailto:{{ $customer->email }}"
class="text-primary-600 underline hover:text-primary-500"
>
{{ $order->customer->email }}
{{ $customer->email }}
</a>
</p>
<p class="text-sm leading-5 text-gray-500 dark:text-gray-400">
{{ $order->customer->phone_number ?? __('shopper::words.no_phone_number') }}
{{ $customer->phone_number ?? __('shopper::words.no_phone_number') }}
</p>
</div>
@else
Expand All @@ -463,6 +469,7 @@ class="text-primary-600 underline hover:text-primary-500"
</p>
@endif
</div>

@if ($shippingAddress)
<div class="py-4">
<h3 class="text-xs font-medium uppercase leading-4 tracking-wider text-gray-900 dark:text-white">
Expand All @@ -487,11 +494,13 @@ class="text-primary-600 underline hover:text-primary-500"
@endif
</p>
</div>

@if ($billingAddress)
<div class="space-y-3 py-4">
<h3 class="text-xs font-medium uppercase leading-4 tracking-wider text-gray-900 dark:text-white">
{{ __('shopper::pages/customers.addresses.billing') }}
</h3>

@if ($billingAddress->is($shippingAddress))
<p class="text-sm text-gray-500 dark:text-gray-400">
{{ __('shopper::words.same_address') }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@php
$total = $this->table->getRecords()->total();
@endphp

<x-shopper::container class="py-5">
<x-shopper::heading :title="__('shopper::pages/orders.menu')" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@php
$total = $this->table->getRecords()->total();
@endphp

<x-shopper::container class="py-5">
<x-shopper::heading :title="__('shopper::pages/products.menu')">
<x-slot name="action">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@php
$total = $this->table->getRecords()->total();
@endphp

<x-shopper::container class="py-5">
<x-shopper::heading :title="__('shopper::pages/reviews.menu')" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ class="mt-1 flex items-center space-x-4 text-sm leading-5 text-gray-500 dark:tex
@if ($review->reviewrateable->sku)
<span>{{ $review->reviewrateable->sku }} -</span>
@endif

<span class="border-b border-dashed border-primary-500 pb-0 text-primary-500">
{{ $review->reviewrateable->getPriceAmount()?->formatted ?? __('N/A') }}
</span>
</p>
</dd>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div>
@if($record->attribute_value_id)
@php
$attributeValue = \Shopper\Core\Models\AttributeValue::with('attribute')->find($record->attribute_value_id);
$attributeValue = $record->value;
@endphp

<span class="inline-flex items-center text-sm leading-6 gap-2 text-gray-500 dark:text-gray-400">
Expand Down
13 changes: 9 additions & 4 deletions packages/admin/src/Livewire/Components/Customers/Addresses.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
namespace Shopper\Livewire\Components\Customers;

use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Collection;
use Livewire\Attributes\Computed;
use Livewire\Component;
use Shopper\Core\Models\Address;

class Addresses extends Component
{
public Collection $addresses;
public $customer;

public function mount($adresses): void
#[Computed(persist: true)]
public function addresses(): Collection
{
$this->addresses = $adresses;
return Address::with('country')
->whereBelongsTo($this->customer)
->get();
}

public function render(): View
Expand Down
25 changes: 17 additions & 8 deletions packages/admin/src/Livewire/Components/Customers/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@

namespace Shopper\Livewire\Components\Customers;

use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Computed;
use Livewire\Component;
use Shopper\Core\Models\Order;

class Orders extends Component
{
public $customer;

public function mount($customer): void
#[Computed(persist: true)]
public function orders(): Paginator
{
$this->customer = $customer->load(['orders']);
return Order::with([
'items',
'items.product',
'items.product.media',
'shippingAddress',
'paymentMethod',
'shippingOption',
])
->whereBelongsTo($this->customer, 'customer')
->latest()
->simplePaginate(3);
}

public function render(): View
{
return view('shopper::livewire.components.customers.orders', [
'orders' => $this->customer->orders()
->with(['items', 'shippingAddress', 'paymentMethod', 'shippingOption'])
->latest()
->simplePaginate(3),
]);
return view('shopper::livewire.components.customers.orders');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function table(Table $table): Table
{
return $table
->query(
AttributeProduct::with(['attribute', 'value'])
AttributeProduct::with(['attribute', 'value', 'value.attribute'])
->where('product_id', $this->product->id)
)
->columns([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RelatedProducts extends Component implements HasActions, HasForms

public function mount($product): void
{
$this->product = $product;
$this->product->load('relatedProducts');
}

public function placeholder(): View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public function table(Table $table): Table
fn ($record) => $this->redirectRoute(
name: 'shopper.products.variant',
parameters: ['productId' => $this->product->id, 'variantId' => $record->id],
navigate: true
),
),
Tables\Actions\DeleteAction::make()
Expand Down
7 changes: 2 additions & 5 deletions packages/admin/src/Livewire/Pages/Brand/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Filament\Tables\Table;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
use Livewire\Attributes\On;
use Shopper\Core\Repositories\BrandRepository;
use Shopper\Facades\Shopper;
use Shopper\Livewire\Pages\AbstractPageComponent;
Expand Down Expand Up @@ -127,11 +126,9 @@ public function table(Table $table): Table
->persistFiltersInSession();
}

#[On('brand-save')]
public function render(): View
{
return view('shopper::livewire.pages.brand.index', [
'total' => (new BrandRepository)->count(),
])->title(__('shopper::pages/brands.menu'));
return view('shopper::livewire.pages.brand.index')
->title(__('shopper::pages/brands.menu'));
}
}
4 changes: 1 addition & 3 deletions packages/admin/src/Livewire/Pages/Category/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Filament\Tables\Table;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
use Livewire\Attributes\On;
use Shopper\Core\Repositories\CategoryRepository;
use Shopper\Livewire\Pages\AbstractPageComponent;
use Shopper\Traits\HasAuthenticated;
Expand All @@ -34,8 +33,8 @@ public function table(Table $table): Table
return $table
->query(
(new CategoryRepository)
->with('parent:id,name')
->query()
->with('parent')
->latest()
)
->columns([
Expand Down Expand Up @@ -148,7 +147,6 @@ public function table(Table $table): Table
]);
}

#[On('category-save')]
public function render(): View
{
return view('shopper::livewire.pages.category.index')
Expand Down
6 changes: 2 additions & 4 deletions packages/admin/src/Livewire/Pages/Collection/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function table(Table $table): Table
return $table
->query(
(new CollectionRepository)
->with('rules')
->query()
->with('rules')
)
->columns([
Tables\Columns\SpatieMediaLibraryImageColumn::make('image')
Expand Down Expand Up @@ -76,9 +76,7 @@ public function table(Table $table): Table

public function render(): View
{
return view('shopper::livewire.pages.collections.browse', [
'total' => (new CollectionRepository)->count(),
])
return view('shopper::livewire.pages.collections.browse')
->title(__('shopper::pages/collections.menu'));
}
}
Loading

0 comments on commit 3c51a79

Please sign in to comment.