From 654c4a081ee74e337a6cf522cba0e8a9dcbca9cf Mon Sep 17 00:00:00 2001 From: wychoong <67364036+wychoong@users.noreply.github.com> Date: Thu, 12 Sep 2024 19:50:22 +0800 Subject: [PATCH 1/3] Update ManageShippingRates.php --- .../ShippingZoneResource/Pages/ManageShippingRates.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php b/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php index 1d80cfb149..deaac7f0b4 100644 --- a/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php +++ b/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php @@ -24,7 +24,7 @@ class ManageShippingRates extends ManageRelatedRecords protected static string $relationship = 'rates'; - public function getTitle(): string|Htmlable + public function getTitle(): string | Htmlable { return __('lunarpanel.shipping::relationmanagers.shipping_rates.title_plural'); } @@ -57,6 +57,7 @@ function () { ->label( __('lunarpanel.shipping::relationmanagers.shipping_rates.form.shipping_method_id.label') ) + ->required() ->relationship(name: 'shippingMethod', titleAttribute: 'name') ->columnSpan(2), Forms\Components\TextInput::make('price') @@ -181,9 +182,11 @@ protected static function saveShippingRate(?ShippingRate $shippingRate = null, a $shippingRate->priceBreaks()->delete(); $tiers = collect($data['prices'] ?? [])->map( - function ($price) { + function ($price) use ($currency) { $price['min_quantity'] = $price['min_quantity'] * 100; + $price['price'] = (int) ($price['price'] * $currency->factor); + return $price; } ); From 1fbe4454a7bd9fc5530195cda982d82c32825abd Mon Sep 17 00:00:00 2001 From: wychoong <67364036+wychoong@users.noreply.github.com> Date: Fri, 13 Sep 2024 17:40:53 +0800 Subject: [PATCH 2/3] Update ManageShippingRates.php --- .../ShippingZoneResource/Pages/ManageShippingRates.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php b/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php index deaac7f0b4..55b92e3ed5 100644 --- a/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php +++ b/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php @@ -24,7 +24,7 @@ class ManageShippingRates extends ManageRelatedRecords protected static string $relationship = 'rates'; - public function getTitle(): string | Htmlable + public function getTitle(): string|Htmlable { return __('lunarpanel.shipping::relationmanagers.shipping_rates.title_plural'); } @@ -183,7 +183,7 @@ protected static function saveShippingRate(?ShippingRate $shippingRate = null, a $tiers = collect($data['prices'] ?? [])->map( function ($price) use ($currency) { - $price['min_quantity'] = $price['min_quantity'] * 100; + $price['min_quantity'] = (int) ($price['min_quantity'] * $currency->factor); $price['price'] = (int) ($price['price'] * $currency->factor); From 52a50b35e1da23f616e6b9aacf0a87e916f42d2a Mon Sep 17 00:00:00 2001 From: wychoong <67364036+wychoong@users.noreply.github.com> Date: Fri, 13 Sep 2024 17:47:27 +0800 Subject: [PATCH 3/3] fix price break not using selected currency --- .../ShippingZoneResource/Pages/ManageShippingRates.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php b/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php index 55b92e3ed5..9d84b2f26f 100644 --- a/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php +++ b/packages/table-rate-shipping/src/Filament/Resources/ShippingZoneResource/Pages/ManageShippingRates.php @@ -181,8 +181,11 @@ protected static function saveShippingRate(?ShippingRate $shippingRate = null, a $shippingRate->priceBreaks()->delete(); + $currencies = Currency::all(); $tiers = collect($data['prices'] ?? [])->map( - function ($price) use ($currency) { + function ($price) use ($currencies) { + $currency = $currencies->first(fn ($currency) => $currency->id == $price['currency_id']); + $price['min_quantity'] = (int) ($price['min_quantity'] * $currency->factor); $price['price'] = (int) ($price['price'] * $currency->factor);