Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carrier shipping zone options #264

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/admin/config/components/setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@
'settings.team.permissions' => Components\Settings\Team\Permissions::class,
'settings.team.users' => Components\Settings\Team\UsersRole::class,
'settings.zones.detail' => Components\Settings\Zones\Detail::class,
'settings.zones.shipping-options' => Components\Settings\Zones\ZoneShippingOptions::class,

'slide-overs.create-team-member' => Livewire\SlideOvers\CreateTeamMember::class,
'slide-overs.shipping-option-form' => Livewire\SlideOvers\ShippingOptionForm::class,
'slide-overs.zone-form' => Livewire\SlideOvers\ZoneForm::class,
],

Expand Down
11 changes: 11 additions & 0 deletions packages/admin/resources/lang/en/pages/settings/zones.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
return [

'title' => 'Zones',
'single' => 'zone',
'description' => 'Zones represent the markets in which you will be operating.',
'add_action' => 'Add zone',
'empty_heading' => 'No zones',
Expand All @@ -14,4 +15,14 @@
'empty_detail_heading' => 'No zone selected',
'empty_detail_description' => "Once you've selected a zone, all its information will be available here",

'shipping_options' => [
'title' => 'Shipping Options',
'description' => 'Enter specifics about available zone shipment methods.',
'option_visibility' => 'Enable or disable the shipping option visibility in store.',
'add' => 'Add Option',
'add_heading' => 'Shipping Option for the :name zone',
'update' => 'Update option (:name)',
'empty_heading' => 'No shipping option available',
],

];
3 changes: 2 additions & 1 deletion packages/admin/resources/lang/en/words.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
'slug' => 'SEO',
'description' => 'Improve your ranking and how your :name page will appear in search engines results.',
'sub_description' => 'Here is a preview of what an search engine can display, play with it!',
'characters' => '160 characters',
'characters' => '160 characters', // to replace in blade file
],

'other' => ' other(s)',
Expand All @@ -148,5 +148,6 @@
'amount' => 'Amount',
'soon' => 'Soon',
'learn_more' => 'Learn more about',
'characters' => ':number characters',

];
12 changes: 12 additions & 0 deletions packages/admin/resources/lang/fr/pages/settings/zones.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
return [

'title' => 'Zones',
'single' => 'zone',
'description' => 'Les zones représentent les marchés sur lesquels vous allez opérer.',
'add_action' => 'Ajouter une zone',
'empty_heading' => 'Aucunes zones',
Expand All @@ -14,4 +15,15 @@
'empty_detail_heading' => 'Aucune zone sélectionner',
'empty_detail_description' => 'Une fois que vous avez sélectionné une zone, toutes ses informations seront disponible ici',

'shipping_options' => [
'title' => 'Options de livraison',
'single' => 'Option de livraison',
'description' => 'Saisir des informations sur les méthodes d\'expédition par zone disponibles.',
'option_visibility' => 'Active ou désactive la visibilité des options de livraison sur votre boutique.',
'add' => 'Ajouter une option',
'add_heading' => 'Option de livraison pour la zone :name',
'update' => 'Modifier cette option (:name)',
'empty_heading' => 'Aucune option de livraison disponible',
],

];
3 changes: 2 additions & 1 deletion packages/admin/resources/lang/fr/words.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
'slug' => 'SEO',
'description' => 'Améliorez votre classement et la façon dont votre page :name apparaîtra dans les résultats des moteurs de recherche.',
'sub_description' => 'Voici un aperçu du résultat que peut donner un moteur de recherche, jouez avec !',
'characters' => '160 caractères',
'characters' => '160 caractères', // à remplacer dans les fichiers blade
],

'other' => ' autre(s)',
Expand All @@ -148,5 +148,6 @@
'amount' => 'Montant',
'soon' => 'Bientôt',
'learn_more' => 'En savoir plus',
'characters' => ':number caractères',

];
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<div class="space-y-10">
@if ($zone)
<x-shopper::card class="divide-y divide-gray-200 dark:divide-gray-700">
<div class="flex items-center justify-between p-4 lg:p-5">
Expand All @@ -13,7 +13,7 @@
</div>
<div class="flex items-center space-x-3 pl-4">
{{ ($this->editAction)(['id' => $zone->id]) }}
{{ $this->deleteAction }}
{{ ($this->deleteAction)(['id' => $zone->id]) }}
</div>
</div>
<div class="p-4 lg:p-5">
Expand All @@ -38,7 +38,7 @@
:heading="__('shopper::pages/settings/carriers.title')"
:content="$zone->carriers_name"
/>
<div class="lg:col-span-2">
<div class="lg:col-span-2" wire:ignore>
<x-shopper::description-list.item icon="untitledui-brackets" heading="Metadata">
<x-shopper::code-preview
:code="$zone->metadata"
Expand All @@ -53,12 +53,14 @@
</div>
</div>
</x-shopper::card>

<livewire:shopper-settings.zones.shipping-options :$zone />
@else
<x-shopper::card>
<x-shopper::empty-card
icon="untitledui-globe-05"
:heading="__('Aucune zone sélectionner')"
:description="__('Veuillez sélectionner une zone pour avoir plus de détails')"
:heading="__('shopper::pages/settings/zones.empty_detail_heading')"
:description="__('shopper::pages/settings/zones.empty_detail_description')"
/>
</x-shopper::card>
@endif
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<div>
<x-shopper::card class="divide-y divide-gray-200 dark:divide-gray-700">
<div class="flex items-center justify-between p-4 lg:p-5">
<div class="flex items-start space-x-3">
<x-heroicon-o-truck class="h-6 w-6 text-gray-400 dark:text-gray-500" aria-hidden="true" />
<div class="space-y-1">
<x-filament::section.heading>
{{ __('shopper::pages/settings/zones.shipping_options.title') }}
</x-filament::section.heading>
<x-filament::section.description>
{{ __('shopper::pages/settings/zones.shipping_options.description') }}
</x-filament::section.description>
</div>
</div>
<div class="flex items-center space-x-3 pl-4">
<x-filament::button
wire:click="$dispatch(
'openPanel', {
component: 'shopper-slide-overs.shipping-option-form',
arguments: {{ json_encode(['zoneId' => $zone->id]) }}
})"
size="sm"
color="gray"
icon="untitledui-plus"
>
{{ __('shopper::pages/settings/zones.shipping_options.add') }}
</x-filament::button>
</div>
</div>
<div class="p-4 lg:grid lg:gap-6 lg:grid-cols-2 lg:p-5">
@forelse($zone->shippingOptions as $shippingOption)
<div class="relative flex items-start justify-between rounded-lg border border-gray-200 bg-white px-6 py-4 shadow-sm dark:bg-white/10 dark:border-gray-700">
<div class="flex flex-col flex-1 leading-6">
<p class="flex items-center gap-2">
<span class="text-gray-900 font-medium dark:text-white">
{{ $shippingOption->name }}
</span>
<x-filament::badge size="sm" :color="$shippingOption->isEnabled() ? 'success': 'gray'">
{{ $shippingOption->isEnabled() ? __('shopper::words.is_enabled') : __('shopper::words.is_disabled') }}
</x-filament::badge>
</p>
@if($shippingOption->description)
<p class="mb-2 text-sm leading-5 text-gray-500 dark:text-gray-400">
{{ $shippingOption->description }}
</p>
@endif
<span class="text-sm text-gray-500 dark:text-gray-400">
{{ __('shopper::forms.label.price') }}:
<span class="font-medium text-gray-600 dark:text-gray-300">
{{ shopper_money_format($shippingOption->price, $zone->currency->code) }}
</span>
</span>
</div>
<div class="flex items-center gap-4">
{{ ($this->editAction)(['zone_id' => $zone->id, 'option_id' => $shippingOption->id]) }}
{{ ($this->deleteAction)(['id' => $shippingOption->id]) }}
</div>
</div>
@empty
<p class="text-sm leading-5 text-gray-500 dark:text-gray-400">
{{ __('shopper::pages/settings/zones.shipping_options.empty_heading') }}
</p>
@endforelse
</div>
</x-shopper::card>

<x-filament-actions::modals />
</div>
22 changes: 10 additions & 12 deletions packages/admin/resources/views/livewire/pages/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,18 @@ class="flex h-10 w-10 items-center justify-center rounded-lg bg-primary-100 dark
{{ __('shopper::pages/dashboard.cards.product_description') }}
</div>

@if (\Shopper\Feature::enabled('product'))
@can('add_products')
<x-shopper::link href="{{ route('shopper.products.create') }}" class="group">
<div class="mt-3 flex items-center text-sm font-medium text-primary-500">
<span>{{ __('shopper::pages/dashboard.cards.product_link') }}</span>
<span
class="ml-1 translate-x-0 transform text-primary-500 transition duration-200 ease-in-out group-hover:translate-x-1"
>
@can('add_products')
<x-shopper::link href="{{ route('shopper.products.create') }}" class="group">
<div class="mt-3 flex items-center text-sm font-medium text-primary-500">
<span>{{ __('shopper::pages/dashboard.cards.product_link') }}</span>
<span
class="ml-1 translate-x-0 transform text-primary-500 transition duration-200 ease-in-out group-hover:translate-x-1"
>
<x-untitledui-arrow-right class="h-5 w-5" aria-hidden="true" />
</span>
</div>
</x-shopper::link>
@endcan
@endif
</div>
</x-shopper::link>
@endcan
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class="relative text-gray-400 hover:text-gray-500 focus:outline-none dark:text-g
<x-filament::input.radio
name="zone"
value="{{ $zone->id }}"
wire:model.live.debounce.350ms="currentZoneId"
wire:model.live="currentZoneId"
class="mt-0.5"
aria-labelledby="zone-{{ $zone->id }}-label"
aria-describedby="zone-{{ $zone->id }}-description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ class Detail extends Component implements HasActions, HasForms

public ?Zone $zone = null;

#[On('zoneRefresh')]
#[On('refresh-zone')]
public function mount(?int $currentZoneId = null): void
{
$this->zone = Zone::with([
'countries',
'currency',
'carriers',
'paymentMethods',
'shippingOptions',
])->find($currentZoneId);
}

Expand All @@ -41,11 +42,11 @@ public function deleteAction(): Action
->record($this->zone)
->icon('untitledui-trash-03')
->iconButton()
->successNotificationTitle(__('shopper::notifications.actions.remove', ['item' => 'zone']))
->successNotificationTitle(__('shopper::notifications.delete', ['item' => __('shopper::pages/settings/zones.single')]))
->after(function (): void {
$this->reset('zone');

$this->dispatch('refreshZones');
$this->dispatch('refresh-zones');
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Shopper\Livewire\Components\Settings\Zones;

use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Notifications\Notification;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Lazy;
use Livewire\Component;
use Shopper\Core\Models\CarrierOption;
use Shopper\Core\Models\Zone;

#[Lazy]
class ZoneShippingOptions extends Component implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;

public ?Zone $zone = null;

public function deleteAction(): Action
{
return Action::make('delete')
->requiresConfirmation()
->icon('untitledui-trash-03')
->color('danger')
->iconButton()
->action(function (array $arguments): void {
CarrierOption::query()->find($arguments['id'])->delete();

Notification::make()
->title(__('shopper::notifications.delete', ['item' => __('shopper::pages/settings/zones.shipping_options.single')]))
->success()
->send();

$this->dispatch('$refresh');
});
}

public function editAction(): Action
{
return Action::make('edit')
->iconButton()
->icon('untitledui-edit-03')
->action(fn (array $arguments) => $this->dispatch(
'openPanel',
component: 'shopper-slide-overs.shipping-option-form',
arguments: ['zoneId' => $arguments['zone_id'], 'optionId' => $arguments['option_id']]
));
}

public function render(): View
{
return view('shopper::livewire.components.settings.zones.shipping-options');
}
}
8 changes: 6 additions & 2 deletions packages/admin/src/Livewire/Pages/Settings/Zones.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Layout;
use Livewire\Attributes\On;
use Livewire\Attributes\Url;
use Livewire\Component;
use Shopper\Core\Models\Zone;

#[Layout('shopper::components.layouts.setting')]
class Zones extends Component
{
#[Url(as: 'zone-id', except: '')]
public ?int $currentZoneId = null;

public function updatedCurrentZoneId(int $value): void
{
$this->dispatch('zoneRefresh', currentZoneId: $value);
$this->currentZoneId = $value;

$this->dispatch('refresh-zone', currentZoneId: $value);
}

#[On('refreshZones')]
#[On('refresh-zones')]
public function render(): View
{
return view('shopper::livewire.pages.settings.zones', [
Expand Down
Loading
Loading