From 4aad66d2927719d924ef35f6f55aa4c0283a4b4f Mon Sep 17 00:00:00 2001 From: wychoong <67364036+wychoong@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:43:40 +0800 Subject: [PATCH] Fix price breaks not storing in correct currency factor (#1948) --- .../ShippingZoneResource/Pages/ManageShippingRates.php | 10 ++++++++-- 1 file changed, 8 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..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 @@ -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') @@ -180,9 +181,14 @@ protected static function saveShippingRate(?ShippingRate $shippingRate = null, a $shippingRate->priceBreaks()->delete(); + $currencies = Currency::all(); $tiers = collect($data['prices'] ?? [])->map( - function ($price) { - $price['min_quantity'] = $price['min_quantity'] * 100; + 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); return $price; }