Skip to content

Commit 18be16d

Browse files
committed
fix: Billing country missing or restricted for virtual products #934
1 parent 3826d88 commit 18be16d

3 files changed

Lines changed: 45 additions & 9 deletions

File tree

packages/evershop/src/components/frontStore/checkout/payment/BillingAddress.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export function BillingAddress({
137137
<CustomerAddressForm
138138
areaId="checkoutBillingAddressForm"
139139
fieldNamePrefix="billingAddress"
140+
countryScope="all"
140141
address={undefined} // Always start empty for different address
141142
/>
142143
{noShippingRequired && (
@@ -160,6 +161,7 @@ export function BillingAddress({
160161
<CustomerAddressForm
161162
areaId="checkoutBillingAddressForm"
162163
fieldNamePrefix="billingAddress"
164+
countryScope="all"
163165
address={undefined} // Always start empty for different address
164166
/>
165167
{noShippingRequired && (

packages/evershop/src/components/frontStore/customer/MyAddresses.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ const Address: React.FC<{
5858
setDialogOpen(false);
5959
toast.success(_('Address has been updated successfully!'));
6060
} catch (error) {
61-
toast.error(error.message);
61+
toast.error(
62+
error instanceof Error ? error.message : String(error)
63+
);
6264
}
6365
}}
6466
>
65-
<CustomerAddressForm address={address} fieldNamePrefix="" />
67+
<CustomerAddressForm
68+
address={address}
69+
fieldNamePrefix=""
70+
countryScope="all"
71+
/>
6672
<div className="mt-3">
6773
<CheckboxField
6874
label={_('Set as default')}
@@ -82,7 +88,9 @@ const Address: React.FC<{
8288
await deleteAddress(address.uuid as string);
8389
toast.success(_('Address has been deleted successfully!'));
8490
} catch (error) {
85-
toast.error(error.message);
91+
toast.error(
92+
error instanceof Error ? error.message : String(error)
93+
);
8694
}
8795
}}
8896
>
@@ -144,11 +152,17 @@ export function MyAddresses({ title }: { title?: string }) {
144152
setDialogOpen(false);
145153
toast.success(_('Address has been saved successfully!'));
146154
} catch (error) {
147-
toast.error(error.message);
155+
toast.error(
156+
error instanceof Error ? error.message : String(error)
157+
);
148158
}
149159
}}
150160
>
151-
<CustomerAddressForm address={undefined} fieldNamePrefix="" />
161+
<CustomerAddressForm
162+
address={undefined}
163+
fieldNamePrefix=""
164+
countryScope="all"
165+
/>
152166
<div className="mt-3">
153167
<CheckboxField
154168
label={_('Set as default')}

packages/evershop/src/components/frontStore/customer/address/addressForm/Index.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CustomerAddressGraphql } from '@evershop/evershop/types/customerAddress
44
import React from 'react';
55
import { useQuery } from 'urql';
66

7-
const CountriesQuery = `
7+
const AllowedCountriesQuery = `
88
query Country {
99
allowedCountries {
1010
value: code
@@ -17,19 +17,34 @@ const CountriesQuery = `
1717
}
1818
`;
1919

20+
const AllCountriesQuery = `
21+
query Country {
22+
countries {
23+
value: code
24+
label: name
25+
provinces {
26+
label: name
27+
value: code
28+
}
29+
}
30+
}
31+
`;
32+
2033
interface IndexProps {
2134
address?: CustomerAddressGraphql;
2235
areaId?: string;
2336
fieldNamePrefix?: string;
37+
countryScope?: 'allowed' | 'all';
2438
}
2539

2640
export default function Index({
2741
address = {},
2842
areaId = 'customerAddressForm',
29-
fieldNamePrefix = 'address'
43+
fieldNamePrefix = 'address',
44+
countryScope = 'allowed'
3045
}: IndexProps) {
3146
const [result] = useQuery({
32-
query: CountriesQuery
47+
query: countryScope === 'all' ? AllCountriesQuery : AllowedCountriesQuery
3348
});
3449

3550
const { data, fetching, error } = result;
@@ -39,11 +54,16 @@ export default function Index({
3954
return <p className="text-destructive">{error.message}</p>;
4055
}
4156

57+
const countries =
58+
countryScope === 'all'
59+
? data?.countries || []
60+
: data?.allowedCountries || [];
61+
4262
return (
4363
<CustomerAddressForm
4464
address={address}
4565
areaId={areaId}
46-
allowCountries={data.allowedCountries}
66+
allowCountries={countries}
4767
fieldNamePrefix={fieldNamePrefix}
4868
/>
4969
);

0 commit comments

Comments
 (0)