@tagadapay/plugin-sdk 2.4.8 → 2.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -63,7 +63,16 @@ export const useShippingRates = ({ onSuccess, checkout } = {}) => {
|
|
|
63
63
|
},
|
|
64
64
|
});
|
|
65
65
|
if (isMountedRef.current) {
|
|
66
|
-
|
|
66
|
+
// Order rates: free ones first, then by ascending amount
|
|
67
|
+
setShippingRates(response.rates
|
|
68
|
+
.slice()
|
|
69
|
+
.sort((a, b) => {
|
|
70
|
+
if (a.isFree && !b.isFree)
|
|
71
|
+
return -1;
|
|
72
|
+
if (!a.isFree && b.isFree)
|
|
73
|
+
return 1;
|
|
74
|
+
return (a.amount ?? 0) - (b.amount ?? 0);
|
|
75
|
+
}));
|
|
67
76
|
}
|
|
68
77
|
}
|
|
69
78
|
catch (err) {
|
|
@@ -152,6 +161,12 @@ export const useShippingRates = ({ onSuccess, checkout } = {}) => {
|
|
|
152
161
|
if (!exists) {
|
|
153
162
|
// Find the cheapest shipping rate and select it
|
|
154
163
|
const cheapest = shippingRates.reduce((min, rate) => {
|
|
164
|
+
// Prioritize isFree rates first
|
|
165
|
+
if (rate.isFree && !min.isFree)
|
|
166
|
+
return rate;
|
|
167
|
+
if (!rate.isFree && min.isFree)
|
|
168
|
+
return min;
|
|
169
|
+
// If both are free or both are not free, compare by amount
|
|
155
170
|
return rate.amount < min.amount ? rate : min;
|
|
156
171
|
}, shippingRates[0]);
|
|
157
172
|
handleSelectRate(cheapest.id);
|