Skip to content

Commit

Permalink
Add thumbnail on product variant (#309)
Browse files Browse the repository at this point in the history
* docs: update config and components (media, brand and customer)

* feat: add thumbnail to varaint, and move storage config from core to media config file

* chore: refactor phpstan
  • Loading branch information
mckenziearts authored Dec 6, 2024
1 parent 782625d commit 3c65cdf
Show file tree
Hide file tree
Showing 33 changed files with 156 additions and 127 deletions.
3 changes: 2 additions & 1 deletion packages/admin/docs/content/brands.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ return [
```

### Components

By default, brands Livewire components are not published. To customize components, you must publish them.

```bash
Expand Down Expand Up @@ -160,7 +161,7 @@ class HomeController extends Controller
return view('home', [
'products' => $products,
'brands' => Brand::query()->get()->take(12), // [tl! focus]
'brands' => Brand::enabled()->get()->take(12), // [tl! focus]
]);
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/admin/docs/content/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ You can update this configuration in the `admin.php` file, or you can add the `S
:::tip
If you update this configuration, you have to republish the assets to take the new link.
The assets are dynamically loaded by a symbolic link named as the prefix.

```php
php artisan shopper:link
```
Expand Down
75 changes: 44 additions & 31 deletions packages/admin/docs/content/customers.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Customers

In e-commerce stores, customers are one if not the fundamental point for the functioning of your store.

The first page under the "Customers" menu gives you a list of all the registered users on your shop.
Expand All @@ -11,60 +12,72 @@ The first page under the "Customers" menu gives you a list of all the registered
During the [installation](/installing#update-existing-files) of Shopper, one of the first things required is to inherit to our model User the features of the model User that is in Shopper.

## Fields
The model used is `App\Models\User` which extends the `\Shopper\Framework\Models\User\User` model.

The model used is `App\Models\User` which extends the `\Shopper\Core\Models\User` model.

:::warning
During the installation of Shopper, the `name` column of the users table is removed and replaced by 2 new fields which are `first_name` and `last_name`.
:::

| Name | Type | Required | Notes |
|-------------|-----------|------------|------------|
| `id` | autoinc | | auto |
| `first_name` | string | no | Nullable |
| `last_name` | string | yes | |
| `email` | string | yes | Unique |
| `password` | string | no | Nullable |
| `email_verified_at` | timestamp | no | Nullable |
| `gender` | enum | yes | values `['male', 'female']` |
| `phone_number` | string | no | Nullable |
| `birth_date` | date | no | Nullable |
| `avatar_type` | string | no | default [ui-avatars](https://ui-avatars.com/) |
| `avatar_location` | string | no | Nullable, picture filename |
| `timezone` | string | no | Nullable |
| `opt_in` | boolean | no | default `false`, this field is for mailing subcription |
| `last_login_at` | timestamp | no | Nullable |
| `last_login_ip` | string | no | Nullable |
| Name | Type | Required | Notes |
|---------------------|-----------|----------|------------------------------------------------------------------|
| `id` | autoinc | | auto |
| `first_name` | string | no | Nullable |
| `last_name` | string | yes | |
| `email` | string | yes | Unique |
| `password` | string | no | Nullable |
| `email_verified_at` | timestamp | no | Nullable |
| `gender` | enum | yes | values `['male', 'female']` |
| `phone_number` | string | no | Nullable |
| `birth_date` | date | no | Nullable |
| `avatar_type` | string | no | default [ui-avatars](https://ui-avatars.com/) |
| `avatar_location` | string | no | Nullable, picture filename |
| `timezone` | string | no | Nullable |
| `opt_in` | boolean | no | default `false`, this field can be used for mailing subscription |
| `last_login_at` | timestamp | no | Nullable |
| `last_login_ip` | string | no | Nullable |

## Components
The components used to manage customers are found in the component configuration file `config/shopper/components.php`.

By default, brands Livewire components are not published. To customize components, you must publish them.

```bash
php artisan shopper:component:publish customer
```

This command will publish all Livewire components used for brand management (from pages to form components).
Once you've published the component, you can find it in the `customer.php` locate in the `config/shopper/components` folder.


```php
use Shopper\Framework\Http\Livewire;
use Shopper\Livewire;
use Shopper\Livewire\Components;

return [

'livewire' => [
'modals.delete-customer' => Livewire\Modals\DeleteCustomer::class,

'customers.addresses' => Livewire\Customers\Addresses::class,
'customers.browse' => Livewire\Customers\Browse::class,
'customers.create' => Livewire\Customers\Create::class,
'customers.orders' => Livewire\Customers\Orders::class,
'customers.profile' => Livewire\Customers\Profile::class,
'customers.show' => Livewire\Customers\Show::class,
'pages' => [
'customer-index' => Livewire\Pages\Customers\Index::class,
'customer-create' => Livewire\Pages\Customers\Create::class,
'customer-show' => Livewire\Pages\Customers\Show::class,
],

'tables.customers-table' => Livewire\Tables\CustomersTable::class,
];
'components' => [
'customers.addresses' => Components\Customers\Addresses::class,
'customers.orders' => Components\Customers\Orders::class,
'customers.profile' => Components\Customers\Profile::class,
],

];
```

## Manage Customers

When a new customer places an order with your store, their name and information are automatically added to your customer list. A customer profile is created when a customer interacts with your store.

Alternatively, you can add a customer to your store manually.

### Create customer

From your Shopper admin, go to Customers and click on "Add customer" button.

<div class="screenshot">
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/docs/content/media.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ For more information on what's available, see [Defining conversions](https://spa
To get an image with full url on a product, a brand or a collection

```php
$product->getFirstMediaUrl(config('shopper.core.storage.disk_name'))
$product->getFirstMediaUrl(config('shopper.media.storage.disk_name'))
```
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class="text-xs font-medium uppercase leading-4 tracking-wider text-gray-500 dark
<div class="shrink-0">
<img
class="size-8 rounded-full object-cover"
src="{{ $item->product->getFirstMediaUrl(config('shopper.core.storage.thumbnail_collection')) }}"
src="{{ $item->product->getFirstMediaUrl(config('shopper.media.storage.thumbnail_collection')) }}"
alt="{{ $item->name }}"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div class="relative">
<div class="h-70 overflow-hidden rounded-lg bg-gray-100 dark:bg-gray-800">
<img
src="{{ $relatedProduct->getFirstMediaUrl(config('shopper.core.storage.thumbnail_collection')) }}"
src="{{ $relatedProduct->getFirstMediaUrl(config('shopper.media.storage.thumbnail_collection')) }}"
alt="{{ $relatedProduct->name }} Thumbnail"
class="h-full w-full max-w-none object-cover object-center"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class="!w-20"
<div class="shrink-0">
<img
class="size-10 rounded-lg object-cover"
src="{{ $item->product->getFirstMediaUrl(config('shopper.core.storage.thumbnail_collection')) }}"
src="{{ $item->product->getFirstMediaUrl(config('shopper.media.storage.thumbnail_collection')) }}"
alt="{{ $item->name }}"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="flex items-center gap-2">
<img
class="size-8 rounded-full object-cover"
src="{{ $firstItem->product->getFirstMediaUrl(config('shopper.core.storage.thumbnail_collection')) }}"
src="{{ $firstItem->product->getFirstMediaUrl(config('shopper.media.storage.thumbnail_collection')) }}"
alt="Avatar {{ $firstItem->product->name }}"
/>

Expand Down
2 changes: 0 additions & 2 deletions packages/admin/src/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ protected function authenticate($request, array $guards): void

if (! $guard->check()) {
$this->unauthenticated($request, $guards);

return;
}

$this->auth->shouldUse($guardName);
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Livewire/Components/Account/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function form(Form $form): Form
->avatar()
->image()
->maxSize(1024)
->disk(config('shopper.core.storage.disk_name')),
->disk(config('shopper.media.storage.disk_name')),
Components\Grid::make()
->schema([
Components\TextInput::make('first_name')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function table(Table $table): Table
->columns([
Tables\Columns\SpatieMediaLibraryImageColumn::make('thumbnail')
->label(__('shopper::forms.label.thumbnail'))
->collection(config('shopper.core.storage.thumbnail_collection'))
->collection(config('shopper.media.storage.thumbnail_collection'))
->circular()
->defaultImageUrl(shopper_fallback_url()),
Tables\Columns\TextColumn::make('name'),
Expand Down
7 changes: 4 additions & 3 deletions packages/admin/src/Livewire/Components/Products/Form/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ public function form(Form $form): Form
->relationship(
relationship: 'categories',
titleAttribute: 'name',
parentAttribute: 'parent_id'
parentAttribute: 'parent_id',
modifyQueryUsing: fn (Builder $query) => $query->where('is_enabled', true)
)
->searchable()
->independent(false)
->enableBranchNode()
->grouped(false)
->searchable()
->visible(Feature::enabled('category')),
])
->visible(
Expand Down
10 changes: 5 additions & 5 deletions packages/admin/src/Livewire/Components/Products/Form/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\SpatieMediaLibraryFileUpload::make('media')
->collection(config('shopper.core.storage.collection_name'))
Forms\Components\SpatieMediaLibraryFileUpload::make('images')
->collection(config('shopper.media.storage.collection_name'))
->label(__('shopper::words.images'))
->helperText(__('shopper::pages/products.images_helpText'))
->multiple()
->panelLayout('grid')
->maxSize(config('shopper.media.max_size.images'))
->columnSpan(['lg' => 2]),

Forms\Components\SpatieMediaLibraryFileUpload::make('thumbnail')
->collection(config('shopper.core.storage.thumbnail_collection'))
->collection(config('shopper.media.storage.thumbnail_collection'))
->label(__('shopper::forms.label.thumbnail'))
->helperText(__('shopper::pages/products.thumbnail_helpText'))
->image()
->maxSize(1024)
->imageEditor()
->maxSize(config('shopper.media.max_size.thumbnail'))
->columnSpan(['lg' => 1]),
])
->columns(3)
Expand Down
14 changes: 4 additions & 10 deletions packages/admin/src/Livewire/Components/Products/Form/Variants.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,18 @@ public function table(Table $table): Table
->newQuery()
)
->columns([
Tables\Columns\SpatieMediaLibraryImageColumn::make('images')
->collection(config('shopper.core.storage.collection_name'))
->stacked()
->circular()
->wrap()
->defaultImageUrl(shopper_fallback_url()),

Tables\Columns\SpatieMediaLibraryImageColumn::make('thumbnail')
->collection(config('shopper.media.storage.thumbnail_collection'))
->label(__('shopper::forms.label.thumbnail'))
->circular(),
Tables\Columns\TextColumn::make('name')
->label(__('shopper::forms.label.name'))
->searchable()
->sortable(),

Tables\Columns\TextColumn::make('sku')
->label(__('shopper::layout.tables.sku'))
->searchable()
->sortable(),

Tables\Columns\TextColumn::make('stock')
->label(__('shopper::layout.tables.current_stock'))
->formatStateUsing(
Expand All @@ -70,7 +65,6 @@ public function table(Table $table): Table
</div>
BLADE))
),

Tables\Columns\TextColumn::make('price_amount')
->label(__('shopper::forms.label.price'))
->money(shopper_currency())
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Livewire/Modals/PaymentMethodForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function form(Form $form): Form
->avatar()
->image()
->maxSize(1024)
->disk(config('shopper.core.storage.disk_name'))
->disk(config('shopper.media.storage.disk_name'))
->columnSpan('full'),
Components\TextInput::make('title')
->label(__('shopper::forms.label.payment_method'))
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Livewire/Pages/Brand/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function table(Table $table): Table
->query((new BrandRepository)->query())
->columns([
Tables\Columns\SpatieMediaLibraryImageColumn::make('Logo')
->collection(config('shopper.core.storage.thumbnail_collection'))
->collection(config('shopper.media.storage.thumbnail_collection'))
->circular()
->defaultImageUrl(shopper_fallback_url())
->grow(false),
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Livewire/Pages/Category/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function table(Table $table): Table
)
->columns([
Tables\Columns\SpatieMediaLibraryImageColumn::make('image')
->collection(config('shopper.core.storage.thumbnail_collection'))
->collection(config('shopper.media.storage.thumbnail_collection'))
->circular()
->defaultImageUrl(shopper_fallback_url())
->grow(false),
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Livewire/Pages/Collection/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function form(Form $form): Form
->schema([
Forms\Components\SpatieMediaLibraryFileUpload::make('file')
->label(__('shopper::forms.label.image_preview'))
->collection(config('shopper.core.storage.thumbnail_collection'))
->collection(config('shopper.media.storage.thumbnail_collection'))
->image()
->maxSize(1024),

Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Livewire/Pages/Collection/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function table(Table $table): Table
)
->columns([
Tables\Columns\SpatieMediaLibraryImageColumn::make('image')
->collection(config('shopper.core.storage.thumbnail_collection'))
->collection(config('shopper.media.storage.thumbnail_collection'))
->circular()
->defaultImageUrl(shopper_fallback_url())
->grow(false),
Expand Down
15 changes: 8 additions & 7 deletions packages/admin/src/Livewire/Pages/Product/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,21 @@ public function form(Form $form): Form
Components\Wizard\StepColumn::make(__('shopper::words.media'))
->icon('untitledui-image')
->schema([
Forms\Components\SpatieMediaLibraryFileUpload::make('media')
->collection(config('shopper.core.storage.collection_name'))
Forms\Components\SpatieMediaLibraryFileUpload::make('images')
->collection(config('shopper.media.storage.collection_name'))
->label(__('shopper::words.images'))
->helperText(__('shopper::pages/products.images_helpText'))
->multiple()
->panelLayout('grid')
->maxSize(config('shopper.media.max_size.images'))
->columnSpan(['lg' => 3]),

Forms\Components\SpatieMediaLibraryFileUpload::make('thumbnail')
->collection(config('shopper.core.storage.thumbnail_collection'))
->collection(config('shopper.media.storage.thumbnail_collection'))
->label(__('shopper::forms.label.thumbnail'))
->helperText(__('shopper::pages/products.thumbnail_helpText'))
->image()
->maxSize(1024)
->imageEditor()
->maxSize(config('shopper.media.max_size.thumbnail'))
->columnSpan(['lg' => 2]),
])
->columns(5),
Expand All @@ -167,10 +167,11 @@ public function form(Form $form): Form
->relationship(
relationship: 'categories',
titleAttribute: 'name',
parentAttribute: 'parent_id'
parentAttribute: 'parent_id',
modifyQueryUsing: fn (Builder $query) => $query->where('is_enabled', true)
)
->independent(false)
->enableBranchNode()
->grouped(false)
->searchable()
->visible(Feature::enabled('category')),
])
Expand Down
Loading

0 comments on commit 3c65cdf

Please sign in to comment.