Skip to content

Commit

Permalink
style: rebase 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
mckenziearts committed Dec 7, 2024
1 parent df65a47 commit e033ae9
Show file tree
Hide file tree
Showing 35 changed files with 28,876 additions and 132 deletions.
1 change: 0 additions & 1 deletion packages/admin/config/components/setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
'inventory-create' => Pages\Settings\Inventories\Create::class,
'inventory-edit' => Pages\Settings\Inventories\Edit::class,
'legal' => Pages\Settings\LegalPage::class,
// 'analytics' => Pages\Settings\Analytics::class,
'payment' => Pages\Settings\Payment::class,
'team-index' => Pages\Settings\Team\Index::class,
'team-roles' => Pages\Settings\Team\RolePermission::class,
Expand Down
52 changes: 51 additions & 1 deletion packages/admin/docs/content/discounts.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
# Discounts

Coming Soon...
...

### Fields

The model used is `Shopper\Models\Discount`.

| Name | Type | Required | Notes |
|------------------------|----------|----------|-------------------------------------------------------------------------------------------------|
| `id` | autoinc | | auto |
| `code` | string | yes | The given code for the discount |
| `type` | string | yes | The type of discount `Shopper\Core\Enum\DiscountType` |
| `value` | int | yes | Depends on the type of discount you want to apply. It can be a percentage or a fixed amount |
| `is_active` | boolean | no | Defines the visibility of the discount for customers. |
| `apply_to` | string | yes | Defines what the discount can be applied to `Shopper\Core\Enum\DiscountApplyTo` |
| `min_required` | string | yes | Defines the conditions required to apply the discount `Shopper\Core\Enum\DiscountRequirement` |
| `min_required_value` | string | no | The minimum value required after defining the required condition, default `NULL` |
| `eligibility` | string | yes | Defines discount eligibility conditions `Shopper\Core\Enum\DiscountEligibility` |
| `usage_limit` | int | no | How many uses the discount has had |
| `usage_limit_per_user` | boolean | no | Defines whether the coupon can be used more than once by customers |
| `total_use` | int | no | The number of times the discount has been used, default `0` |
| `start_at` | datetime | yes | The datetime the discount starts |
| `end_at` | datetime | no | The datetime the discount expires, if `NULL` it won't expire |
| `metadata` | array | no | `NULL`, json column to save any data key:value |
| `zone_id` | int | no | The area in which the discount can be applied. If `NULL`, the discount can be applied anywhere. |

### Components

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

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

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

```php
use Shopper\Livewire;

return [
'pages' => [
'discount-index' => Livewire\Pages\Discount\Index::class,
],

'components' => [
'slide-overs.discount-form' => Livewire\SlideOvers\DiscountForm::class,
],
];
```

## Manage Brands
10,653 changes: 10,652 additions & 1 deletion packages/admin/public/shopper.css

Large diffs are not rendered by default.

17,712 changes: 17,700 additions & 12 deletions packages/admin/public/shopper.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,34 @@
'description' => null,
])

<form wire:submit="{{ $action }}" class="flex h-full flex-col divide-y divide-gray-200 dark:divide-white/10">
<div class="h-0 flex-1 overflow-y-auto py-6">
<header class="px-4 sm:px-6">
<div class="flex items-start justify-between">
<h2 class="text-lg font-medium text-gray-900 dark:text-white">
{{ $title }}
</h2>
<div class="ml-3 flex h-7 items-center gap-2">
<x-shopper::escape />
<button
type="button"
class="rounded-md bg-white text-gray-400 hover:text-gray-500 outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 dark:bg-gray-900 dark:text-gray-500 dark:ring-offset-gray-900 dark:hover:text-gray-300"
wire:click="$dispatch('closePanel')"
>
<span class="sr-only">Close panel</span>
<x-untitledui-x class="size-6" stroke-width="1.5" aria-hidden="true" />
</button>
</div>
<form wire:submit="{{ $action }}" class="flex h-full flex-col divide-y divide-gray-100 dark:divide-white/10">
<header class="p-4">
<div class="flex items-start justify-between">
<h2 class="text-lg font-medium text-gray-900 dark:text-white">
{{ $title }}
</h2>
<div class="ml-3 flex h-7 items-center gap-2">
<x-shopper::escape />
<button
type="button"
class="rounded-md bg-white text-gray-400 hover:text-gray-500 outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 dark:bg-gray-900 dark:text-gray-500 dark:ring-offset-gray-900 dark:hover:text-gray-300"
wire:click="$dispatch('closePanel')"
>
<span class="sr-only">Close panel</span>
<x-untitledui-x class="size-6" stroke-width="1.5" aria-hidden="true" />
</button>
</div>
@if ($description)
<div class="mt-1">
<p class="text-sm text-gray-500 dark:text-gray-400">
{{ $description }}
</p>
</div>
@endif
</header>
<div class="mt-8 flex-1 px-4 sm:px-6">
{{ $slot }}
</div>
@if ($description)
<div class="mt-1">
<p class="text-sm text-gray-500 dark:text-gray-400">
{{ $description }}
</p>
</div>
@endif
</header>
<div class="h-0 flex-1 overflow-y-auto p-4 py-6">
{{ $slot }}
</div>
<div class="flex shrink-0 justify-end space-x-4 p-4">
<x-shopper::buttons.default wire:click="$dispatch('closePanel')" type="button" class="mt-3 sm:mt-0 sm:w-auto">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
@if ($discount->type === \Shopper\Core\Enum\DiscountType::Percentage->value)
{{ $discount->value . '%' }}
@else
{{ shopper_money_format($discount->value * 100) }}
{{ shopper_money_format(amount: $discount->value * 100, currency: $discount->zone?->currency_code) }}
@endif
</div>
8 changes: 4 additions & 4 deletions packages/admin/src/Actions/Store/InitialQuantityInventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
use Shopper\Core\Models\Inventory;
use Shopper\Core\Models\Product;

final class InitialQuantityInventory
final readonly class InitialQuantityInventory
{
public function handle($quantity, Product $product): void
public function __invoke(int $quantity, Product $product): void
{
/** @var Inventory $inventory */
$inventory = Inventory::default()->first();
$inventory = Inventory::query()->scopes('default')->first();

if ($inventory) {
$product->mutateStock(
inventoryId: $inventory->id,
quantity: (int) $quantity,
quantity: $quantity,
arguments: [
'event' => __('shopper::pages/products.inventory.initial'),
'old_quantity' => $quantity,
Expand Down
38 changes: 38 additions & 0 deletions packages/admin/src/Actions/Store/SaveAndDispatchDiscountAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Shopper\Actions\Store;

use Shopper\Core\Models\Discount;
use Shopper\Jobs\DiscountCustomersJobs;
use Shopper\Jobs\DiscountProductsJob;

final readonly class SaveAndDispatchDiscountAction
{
public function __invoke(
array $values,
?int $discountId = null,
array $productsIds = [],
array $customersIds = []
): Discount {
$discount = Discount::query()->updateOrCreate(
attributes: ['id' => $discountId],
values: $values,
);

DiscountProductsJob::dispatch(
data_get($values, 'apply_to'),
$productsIds,
$discount,
);

DiscountCustomersJobs::dispatch(
data_get($values, 'eligibility'),
$customersIds,
$discount,
);

return $discount;
}
}
6 changes: 3 additions & 3 deletions packages/admin/src/Livewire/Components/Account/TwoFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use Livewire\Attributes\Computed;
use Livewire\Attributes\On;
use Livewire\Component;
use Shopper\Actions\DisableTwoFactorAuthentication;
use Shopper\Actions\EnableTwoFactorAuthentication;
use Shopper\Actions\GenerateNewRecoveryCodes;
use Shopper\Actions\Auth\DisableTwoFactorAuthentication;
use Shopper\Actions\Auth\EnableTwoFactorAuthentication;
use Shopper\Actions\Auth\GenerateNewRecoveryCodes;
use Shopper\Traits\ConfirmsPasswords;

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Livewire/Modals/ConfirmPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Contracts\View\View;
use Illuminate\Validation\ValidationException;
use Shopper\Actions\ConfirmPassword as ConfirmPasswordAction;
use Shopper\Actions\Auth\ConfirmPassword as ConfirmPasswordAction;
use Shopper\Facades\Shopper;
use Shopper\Livewire\Components\ModalComponent;

Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Livewire/Pages/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use Livewire\Attributes\Layout;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Shopper\Actions\AttemptToAuthenticate;
use Shopper\Actions\RedirectIfTwoFactorAuthenticatable;
use Shopper\Actions\Auth\AttemptToAuthenticate;
use Shopper\Actions\Auth\RedirectIfTwoFactorAuthenticatable;
use Shopper\Contracts\LoginResponse;

#[Layout('shopper::components.layouts.base')]
Expand Down
6 changes: 4 additions & 2 deletions packages/admin/src/Livewire/Pages/Category/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
use Livewire\Attributes\On;
use Shopper\Core\Repositories\CategoryRepository;
use Shopper\Livewire\Pages\AbstractPageComponent;
use Shopper\Traits\HasAuthenticated;

class Index extends AbstractPageComponent implements HasForms, HasTable
{
use HasAuthenticated;
use InteractsWithForms;
use InteractsWithTable;

Expand Down Expand Up @@ -76,7 +78,7 @@ public function table(Table $table): Table
arguments: ['categoryId' => $record->id]
)
)
->visible(auth()->user()->can('edit_categories')),
->visible($this->getUser()->can('edit_categories')),
])
->groupedBulkActions([
Tables\Actions\DeleteBulkAction::make()
Expand All @@ -94,7 +96,7 @@ public function table(Table $table): Table
->success()
->send();
})
->visible(auth()->user()->can('delete_categories'))
->visible($this->getUser()->can('delete_categories'))
->deselectRecordsAfterCompletion(),
Tables\Actions\BulkAction::make('enabled')
->label(__('shopper::forms.actions.enable'))
Expand Down
21 changes: 11 additions & 10 deletions packages/admin/src/Livewire/Pages/Discount/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
use Shopper\Core\Enum\DiscountEligibility;
use Shopper\Core\Models\Discount;
use Shopper\Livewire\Pages\AbstractPageComponent;
use Shopper\Traits\HasAuthenticated;

class Index extends AbstractPageComponent implements HasForms, HasTable
{
use HasAuthenticated;
use InteractsWithForms;
use InteractsWithTable;

Expand All @@ -34,53 +36,52 @@ public function mount(): void
public function table(Table $table): Table
{
return $table
->query(Discount::query())
->query(Discount::with('zone')->latest())
->columns([
Tables\Columns\TextColumn::make('code')
->label(__('shopper::forms.label.code'))
->badge()
->searchable()
->sortable(),

Tables\Columns\ViewColumn::make('value')
->label(__('shopper::words.amount'))
->toggleable()
->view('shopper::livewire.tables.cells.discounts.amount'),

Tables\Columns\TextColumn::make('apply_to')
->label(__('shopper::pages/discounts.applies_to'))
->toggleable()
->toggledHiddenByDefault()
->color('gray')
->badge(),

Tables\Columns\TextColumn::make('eligibility')
->label(__('shopper::pages/discounts.customer_eligibility'))
->toggleable()
->toggledHiddenByDefault()
->color('gray')
->badge(),

Tables\Columns\IconColumn::make('is_active')
->label(__('shopper::forms.label.status'))
->boolean()
->sortable(),

Tables\Columns\ViewColumn::make('start_at')
->label(__('shopper::words.date'))
->toggleable()
->view('shopper::livewire.tables.cells.discounts.date'),

Tables\Columns\TextColumn::make('usage_limit')
->label(__('shopper::pages/discounts.usage_limits'))
->alignRight()
->toggleable()
->sortable(),

Tables\Columns\TextColumn::make('total_use')
->label(__('shopper::pages/discounts.total_use'))
->alignRight()
->sortable(),
Tables\Columns\TextColumn::make('zone.name')
->label(__('shopper::pages/settings/zones.single'))
->searchable()
->sortable()
->toggleable()
->toggledHiddenByDefault(),
])
->actions([
Tables\Actions\Action::make('edit')
Expand All @@ -92,7 +93,7 @@ public function table(Table $table): Table
arguments: ['discountId' => $record->id]
)
)
->visible(auth()->user()->can('edit_discounts')),
->visible($this->getUser()->can('edit_discounts')),
])
->groupedBulkActions([
Tables\Actions\DeleteBulkAction::make()
Expand All @@ -110,7 +111,7 @@ public function table(Table $table): Table
->success()
->send();
})
->visible(auth()->user()->can('delete_discounts'))
->visible($this->getUser()->can('delete_discounts'))
->deselectRecordsAfterCompletion(),
])
->filters([
Expand Down
6 changes: 0 additions & 6 deletions packages/admin/src/Livewire/Pages/Order/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,14 @@ public function table(Table $table): Table
->searchable()
->extraAttributes(['class' => 'uppercase'])
->sortable(),

Tables\Columns\TextColumn::make('created_at')
->label(__('shopper::words.date'))
->date()
->sortable()
->toggleable(),

Tables\Columns\TextColumn::make('status')
->label(__('shopper::forms.label.status'))
->badge(),

Tables\Columns\TextColumn::make('customer.first_name')
->label(__('shopper::words.customer'))
->searchable()
Expand All @@ -62,20 +59,17 @@ public function table(Table $table): Table
['order' => $model->load('customer')]
))
->toggleable(),

Tables\Columns\TextColumn::make('id')
->label(__('shopper::words.purchased'))
->formatStateUsing(fn (Order $model): View => view(
'shopper::livewire.tables.cells.orders.purchased',
['order' => $model->load('items')]
)),

Tables\Columns\TextColumn::make('currency_code')
->label(__('shopper::forms.label.price_amount'))
->formatStateUsing(
fn ($state, Order $record): string => shopper_money_format(amount: $record->total(), currency: $state)
),

Tables\Columns\TextColumn::make('zone.name')
->label(__('shopper::pages/settings/zones.single'))
->searchable()
Expand Down
5 changes: 4 additions & 1 deletion packages/admin/src/Livewire/Pages/Product/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,10 @@ public function store(): void
$quantity = (int) $data['quantity'];

if ($quantity && $quantity > 0) {
(new InitialQuantityInventory)->handle($quantity, $product);
app()->call(InitialQuantityInventory::class, [
'quantity' => $quantity,
'product' => $product,
]);
}

Notification::make()
Expand Down
Loading

0 comments on commit e033ae9

Please sign in to comment.