2021-04-22 11:37:27 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-04-08 08:43:42 +00:00
|
|
|
import { getSetting, STORE_PAGES } from '@woocommerce/settings';
|
|
|
|
import { CountryData } from '@woocommerce/types';
|
2021-04-22 11:37:27 +00:00
|
|
|
|
2021-04-27 16:39:20 +00:00
|
|
|
export type WordCountType =
|
|
|
|
| 'words'
|
|
|
|
| 'characters_excluding_spaces'
|
|
|
|
| 'characters_including_spaces';
|
|
|
|
|
2024-05-24 12:13:24 +00:00
|
|
|
export interface WcBlocksConfig {
|
2021-04-22 11:37:27 +00:00
|
|
|
pluginUrl: string;
|
2024-06-05 09:20:35 +00:00
|
|
|
productCount?: number;
|
2021-06-29 14:04:24 +00:00
|
|
|
defaultAvatar: string;
|
2021-04-22 11:37:27 +00:00
|
|
|
restApiRoutes: Record< string, string[] >;
|
2021-04-27 16:39:20 +00:00
|
|
|
wordCountType: WordCountType;
|
2024-06-05 09:20:35 +00:00
|
|
|
experimentalBlocksEnabled?: boolean;
|
2021-04-22 11:37:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const blocksConfig = getSetting( 'wcBlocksConfig', {
|
|
|
|
pluginUrl: '',
|
|
|
|
productCount: 0,
|
2021-06-29 14:04:24 +00:00
|
|
|
defaultAvatar: '',
|
2021-04-22 11:37:27 +00:00
|
|
|
restApiRoutes: {},
|
|
|
|
wordCountType: 'words',
|
|
|
|
} ) as WcBlocksConfig;
|
|
|
|
|
2023-12-10 05:26:49 +00:00
|
|
|
export const WC_BLOCKS_IMAGE_URL = blocksConfig.pluginUrl + 'assets/images/';
|
2023-12-12 23:05:20 +00:00
|
|
|
export const WC_BLOCKS_BUILD_URL =
|
|
|
|
blocksConfig.pluginUrl + 'assets/client/blocks/';
|
2021-04-22 11:37:27 +00:00
|
|
|
export const SHOP_URL = STORE_PAGES.shop?.permalink;
|
2023-10-27 09:05:43 +00:00
|
|
|
export const CHECKOUT_PAGE_ID = STORE_PAGES.checkout?.id;
|
|
|
|
export const CHECKOUT_URL = STORE_PAGES.checkout?.permalink;
|
|
|
|
export const PRIVACY_URL = STORE_PAGES.privacy?.permalink;
|
|
|
|
export const PRIVACY_PAGE_NAME = STORE_PAGES.privacy?.title;
|
|
|
|
export const TERMS_URL = STORE_PAGES.terms?.permalink;
|
|
|
|
export const TERMS_PAGE_NAME = STORE_PAGES.terms?.title;
|
|
|
|
export const CART_PAGE_ID = STORE_PAGES.cart?.id;
|
|
|
|
export const CART_URL = STORE_PAGES.cart?.permalink;
|
|
|
|
export const LOGIN_URL = STORE_PAGES.myaccount?.permalink
|
2021-04-22 11:37:27 +00:00
|
|
|
? STORE_PAGES.myaccount.permalink
|
|
|
|
: getSetting( 'wpLoginUrl', '/wp-login.php' );
|
2023-05-31 09:30:44 +00:00
|
|
|
export const LOCAL_PICKUP_ENABLED = getSetting< boolean >(
|
|
|
|
'localPickupEnabled',
|
|
|
|
false
|
2021-06-17 08:35:24 +00:00
|
|
|
);
|
2023-05-31 09:30:44 +00:00
|
|
|
|
2023-12-15 12:45:38 +00:00
|
|
|
type FieldsLocations = {
|
|
|
|
address: string[];
|
|
|
|
contact: string[];
|
2024-04-23 14:47:32 +00:00
|
|
|
order: string[];
|
2023-12-15 12:45:38 +00:00
|
|
|
};
|
|
|
|
|
2023-05-31 09:30:44 +00:00
|
|
|
// Contains country names.
|
|
|
|
const countries = getSetting< Record< string, string > >( 'countries', {} );
|
|
|
|
|
|
|
|
// Contains country settings.
|
|
|
|
const countryData = getSetting< Record< string, CountryData > >(
|
|
|
|
'countryData',
|
2021-06-17 08:35:24 +00:00
|
|
|
{}
|
|
|
|
);
|
2023-05-31 09:30:44 +00:00
|
|
|
|
|
|
|
export const ALLOWED_COUNTRIES = Object.fromEntries(
|
|
|
|
Object.keys( countryData )
|
|
|
|
.filter( ( countryCode ) => {
|
|
|
|
return countryData[ countryCode ].allowBilling === true;
|
|
|
|
} )
|
|
|
|
.map( ( countryCode ) => {
|
|
|
|
return [ countryCode, countries[ countryCode ] || '' ];
|
|
|
|
} )
|
2021-06-17 08:35:24 +00:00
|
|
|
);
|
2023-05-31 09:30:44 +00:00
|
|
|
|
|
|
|
export const ALLOWED_STATES = Object.fromEntries(
|
|
|
|
Object.keys( countryData )
|
|
|
|
.filter( ( countryCode ) => {
|
|
|
|
return countryData[ countryCode ].allowBilling === true;
|
|
|
|
} )
|
|
|
|
.map( ( countryCode ) => {
|
|
|
|
return [ countryCode, countryData[ countryCode ].states || [] ];
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
|
|
|
|
export const SHIPPING_COUNTRIES = Object.fromEntries(
|
|
|
|
Object.keys( countryData )
|
|
|
|
.filter( ( countryCode ) => {
|
|
|
|
return countryData[ countryCode ].allowShipping === true;
|
|
|
|
} )
|
|
|
|
.map( ( countryCode ) => {
|
|
|
|
return [ countryCode, countries[ countryCode ] || '' ];
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
|
|
|
|
export const SHIPPING_STATES = Object.fromEntries(
|
|
|
|
Object.keys( countryData )
|
|
|
|
.filter( ( countryCode ) => {
|
|
|
|
return countryData[ countryCode ].allowShipping === true;
|
|
|
|
} )
|
|
|
|
.map( ( countryCode ) => {
|
|
|
|
return [ countryCode, countryData[ countryCode ].states || [] ];
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
|
|
|
|
export const COUNTRY_LOCALE = Object.fromEntries(
|
|
|
|
Object.keys( countryData ).map( ( countryCode ) => {
|
|
|
|
return [ countryCode, countryData[ countryCode ].locale || [] ];
|
|
|
|
} )
|
2022-12-09 09:50:08 +00:00
|
|
|
);
|
2023-12-15 12:45:38 +00:00
|
|
|
|
|
|
|
const defaultFieldsLocations: FieldsLocations = {
|
|
|
|
address: [
|
|
|
|
'first_name',
|
|
|
|
'last_name',
|
|
|
|
'company',
|
|
|
|
'address_1',
|
|
|
|
'address_2',
|
|
|
|
'city',
|
|
|
|
'postcode',
|
|
|
|
'country',
|
|
|
|
'state',
|
|
|
|
'phone',
|
|
|
|
],
|
|
|
|
contact: [ 'email' ],
|
2024-04-23 14:47:32 +00:00
|
|
|
order: [],
|
2023-12-15 12:45:38 +00:00
|
|
|
};
|
|
|
|
|
2024-01-05 17:35:28 +00:00
|
|
|
export const ADDRESS_FORM_KEYS = getSetting< FieldsLocations >(
|
2023-12-15 12:45:38 +00:00
|
|
|
'addressFieldsLocations',
|
|
|
|
defaultFieldsLocations
|
|
|
|
).address;
|
|
|
|
|
2024-01-05 17:35:28 +00:00
|
|
|
export const CONTACT_FORM_KEYS = getSetting< FieldsLocations >(
|
2023-12-15 12:45:38 +00:00
|
|
|
'addressFieldsLocations',
|
|
|
|
defaultFieldsLocations
|
|
|
|
).contact;
|
|
|
|
|
2024-04-23 14:47:32 +00:00
|
|
|
export const ORDER_FORM_KEYS = getSetting< FieldsLocations >(
|
2023-12-15 12:45:38 +00:00
|
|
|
'addressFieldsLocations',
|
|
|
|
defaultFieldsLocations
|
2024-04-23 14:47:32 +00:00
|
|
|
).order;
|
2024-01-16 13:17:28 +00:00
|
|
|
|
|
|
|
export interface CheckoutField {
|
|
|
|
label: string;
|
|
|
|
type: string;
|
|
|
|
options: { label: string; value: string }[];
|
|
|
|
}
|
|
|
|
|
2024-04-23 14:47:32 +00:00
|
|
|
export const ORDER_FORM_FIELDS = getSetting< CheckoutField[] >(
|
|
|
|
'additionalOrderFields',
|
2024-01-16 13:17:28 +00:00
|
|
|
{}
|
|
|
|
);
|
|
|
|
export const CONTACT_FORM_FIELDS = getSetting< CheckoutField[] >(
|
|
|
|
'additionalContactFields',
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
export const ADDRESS_FORM_FIELDS = getSetting< CheckoutField[] >(
|
|
|
|
'additionalAddressFields',
|
|
|
|
{}
|
|
|
|
);
|