@payloadcms/storage-r2 0.0.1-beta.0
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.
- package/.prettierignore +12 -0
- package/.swcrc +24 -0
- package/LICENSE.md +22 -0
- package/README.md +3 -0
- package/eslint.config.js +18 -0
- package/package.json +4 -0
- package/src/addresses/addressesCollection.ts +76 -0
- package/src/addresses/defaultAddressFields.ts +83 -0
- package/src/addresses/defaultCountries.ts +50 -0
- package/src/carts/beforeChange.ts +51 -0
- package/src/carts/cartsCollection.ts +146 -0
- package/src/currencies/index.ts +29 -0
- package/src/endpoints/confirmOrder.ts +312 -0
- package/src/endpoints/initiatePayment.ts +322 -0
- package/src/exports/addresses.ts +2 -0
- package/src/exports/currencies.ts +1 -0
- package/src/exports/fields.ts +5 -0
- package/src/exports/orders.ts +1 -0
- package/src/exports/payments/stripe.ts +1 -0
- package/src/exports/plugin.ts +1 -0
- package/src/exports/products.ts +1 -0
- package/src/exports/react.ts +8 -0
- package/src/exports/transactions.ts +1 -0
- package/src/exports/translations.ts +1 -0
- package/src/exports/types.ts +7 -0
- package/src/exports/ui.ts +3 -0
- package/src/exports/variants.ts +5 -0
- package/src/fields/amountField.ts +43 -0
- package/src/fields/cartItemsField.ts +84 -0
- package/src/fields/currencyField.ts +39 -0
- package/src/fields/inventoryField.ts +22 -0
- package/src/fields/pricesField.ts +65 -0
- package/src/fields/statusField.ts +57 -0
- package/src/fields/variantsFields.ts +56 -0
- package/src/index.ts +275 -0
- package/src/orders/ordersCollection.ts +157 -0
- package/src/payments/adapters/stripe/confirmOrder.ts +123 -0
- package/src/payments/adapters/stripe/endpoints/webhooks.ts +69 -0
- package/src/payments/adapters/stripe/index.ts +135 -0
- package/src/payments/adapters/stripe/initiatePayment.ts +131 -0
- package/src/products/productsCollection.ts +78 -0
- package/src/react/provider/index.tsx +893 -0
- package/src/react/provider/types.ts +184 -0
- package/src/react/provider/utilities.ts +22 -0
- package/src/transactions/transactionsCollection.ts +166 -0
- package/src/translations/en.ts +64 -0
- package/src/translations/index.ts +11 -0
- package/src/translations/translation-schema.json +35 -0
- package/src/types.ts +403 -0
- package/src/ui/PriceInput/FormattedInput.tsx +134 -0
- package/src/ui/PriceInput/index.scss +28 -0
- package/src/ui/PriceInput/index.tsx +43 -0
- package/src/ui/PriceInput/utilities.ts +46 -0
- package/src/ui/PriceRowLabel/index.css +13 -0
- package/src/ui/PriceRowLabel/index.tsx +56 -0
- package/src/ui/VariantOptionsSelector/ErrorBox.tsx +27 -0
- package/src/ui/VariantOptionsSelector/OptionsSelect.tsx +78 -0
- package/src/ui/VariantOptionsSelector/index.css +37 -0
- package/src/ui/VariantOptionsSelector/index.tsx +83 -0
- package/src/utilities/defaultProductsValidation.ts +42 -0
- package/src/utilities/errorCodes.ts +14 -0
- package/src/utilities/getCollectionSlugMap.ts +84 -0
- package/src/utilities/sanitizePluginConfig.ts +80 -0
- package/src/variants/variantOptionsCollection.ts +59 -0
- package/src/variants/variantTypesCollection.ts +55 -0
- package/src/variants/variantsCollection/hooks/beforeChange.ts +47 -0
- package/src/variants/variantsCollection/hooks/validateOptions.ts +72 -0
- package/src/variants/variantsCollection/index.ts +119 -0
- package/tsconfig.json +7 -0
- package/tsconfig.tsbuildinfo +1 -0
package/.prettierignore
ADDED
package/.swcrc
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/swcrc",
|
|
3
|
+
"sourceMaps": true,
|
|
4
|
+
"jsc": {
|
|
5
|
+
"target": "esnext",
|
|
6
|
+
"parser": {
|
|
7
|
+
"syntax": "typescript",
|
|
8
|
+
"tsx": true,
|
|
9
|
+
"dts": true
|
|
10
|
+
},
|
|
11
|
+
"transform": {
|
|
12
|
+
"react": {
|
|
13
|
+
"runtime": "automatic",
|
|
14
|
+
"pragmaFrag": "React.Fragment",
|
|
15
|
+
"throwIfNamespace": true,
|
|
16
|
+
"development": false,
|
|
17
|
+
"useBuiltins": true
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"module": {
|
|
22
|
+
"type": "es6"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018-2025 Payload CMS, Inc. <info@payloadcms.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
package/eslint.config.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { rootEslintConfig, rootParserOptions } from '../../eslint.config.js'
|
|
2
|
+
|
|
3
|
+
/** @typedef {import('eslint').Linter.Config} Config */
|
|
4
|
+
|
|
5
|
+
/** @type {Config[]} */
|
|
6
|
+
export const index = [
|
|
7
|
+
...rootEslintConfig,
|
|
8
|
+
{
|
|
9
|
+
languageOptions: {
|
|
10
|
+
parserOptions: {
|
|
11
|
+
...rootParserOptions,
|
|
12
|
+
tsconfigRootDir: import.meta.dirname,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
export default index
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { CollectionConfig, Field } from 'payload'
|
|
2
|
+
|
|
3
|
+
import type { CountryType, FieldsOverride } from '../types.js'
|
|
4
|
+
|
|
5
|
+
import { defaultCountries } from './defaultCountries.js'
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
/**
|
|
9
|
+
* Array of fields used for capturing the address data. Use this over overrides to customise the fields here as it's reused across the plugin.
|
|
10
|
+
*/
|
|
11
|
+
addressFields: Field[]
|
|
12
|
+
/**
|
|
13
|
+
* Slug of the customers collection, defaults to 'users'.
|
|
14
|
+
*/
|
|
15
|
+
customersSlug?: string
|
|
16
|
+
overrides?: { fields?: FieldsOverride } & Partial<Omit<CollectionConfig, 'fields'>>
|
|
17
|
+
supportedCountries?: CountryType[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const addressesCollection: (props: Props) => CollectionConfig = (props) => {
|
|
21
|
+
const { addressFields, customersSlug = 'users', overrides } = props || {}
|
|
22
|
+
const fieldsOverride = overrides?.fields
|
|
23
|
+
|
|
24
|
+
const { supportedCountries: supportedCountriesFromProps } = props || {}
|
|
25
|
+
const supportedCountries = supportedCountriesFromProps || defaultCountries
|
|
26
|
+
const hasOnlyOneCountry = supportedCountries && supportedCountries.length === 1
|
|
27
|
+
|
|
28
|
+
const defaultFields: Field[] = [
|
|
29
|
+
{
|
|
30
|
+
name: 'customer',
|
|
31
|
+
type: 'relationship',
|
|
32
|
+
label: ({ t }) =>
|
|
33
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
34
|
+
t('plugin-ecommerce:customer'),
|
|
35
|
+
relationTo: customersSlug,
|
|
36
|
+
},
|
|
37
|
+
...addressFields.map((field) => {
|
|
38
|
+
if ('name' in field && field.name === 'country') {
|
|
39
|
+
return {
|
|
40
|
+
name: 'country',
|
|
41
|
+
type: 'select',
|
|
42
|
+
label: ({ t }) =>
|
|
43
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
44
|
+
t('plugin-ecommerce:addressCountry'),
|
|
45
|
+
options: supportedCountries || defaultCountries,
|
|
46
|
+
required: true,
|
|
47
|
+
...(supportedCountries && supportedCountries?.[0] && hasOnlyOneCountry
|
|
48
|
+
? {
|
|
49
|
+
defaultValue: supportedCountries?.[0].value,
|
|
50
|
+
}
|
|
51
|
+
: {}),
|
|
52
|
+
} as Field
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return field
|
|
56
|
+
}),
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
const fields =
|
|
60
|
+
fieldsOverride && typeof fieldsOverride === 'function'
|
|
61
|
+
? fieldsOverride({ defaultFields })
|
|
62
|
+
: defaultFields
|
|
63
|
+
|
|
64
|
+
const baseConfig: CollectionConfig = {
|
|
65
|
+
slug: 'addresses',
|
|
66
|
+
timestamps: true,
|
|
67
|
+
...overrides,
|
|
68
|
+
admin: {
|
|
69
|
+
useAsTitle: 'createdAt',
|
|
70
|
+
...overrides?.admin,
|
|
71
|
+
},
|
|
72
|
+
fields,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { ...baseConfig }
|
|
76
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Field } from 'payload'
|
|
2
|
+
|
|
3
|
+
export const defaultAddressFields: () => Field[] = () => {
|
|
4
|
+
return [
|
|
5
|
+
{
|
|
6
|
+
name: 'title',
|
|
7
|
+
type: 'text',
|
|
8
|
+
label: ({ t }) =>
|
|
9
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
10
|
+
t('plugin-ecommerce:addressTitle'),
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'firstName',
|
|
14
|
+
type: 'text',
|
|
15
|
+
label: ({ t }) =>
|
|
16
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
17
|
+
t('plugin-ecommerce:addressFirstName'),
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'lastName',
|
|
21
|
+
type: 'text',
|
|
22
|
+
label: ({ t }) =>
|
|
23
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
24
|
+
t('plugin-ecommerce:addressLastName'),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'company',
|
|
28
|
+
type: 'text',
|
|
29
|
+
label: ({ t }) =>
|
|
30
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
31
|
+
t('plugin-ecommerce:addressCompany'),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'addressLine1',
|
|
35
|
+
type: 'text',
|
|
36
|
+
label: ({ t }) =>
|
|
37
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
38
|
+
t('plugin-ecommerce:addressLine1'),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'addressLine2',
|
|
42
|
+
type: 'text',
|
|
43
|
+
label: ({ t }) =>
|
|
44
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
45
|
+
t('plugin-ecommerce:addressLine2'),
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'city',
|
|
49
|
+
type: 'text',
|
|
50
|
+
label: ({ t }) =>
|
|
51
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
52
|
+
t('plugin-ecommerce:addressCity'),
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'state',
|
|
56
|
+
type: 'text',
|
|
57
|
+
label: ({ t }) =>
|
|
58
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
59
|
+
t('plugin-ecommerce:addressState'),
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'postalCode',
|
|
63
|
+
type: 'text',
|
|
64
|
+
label: ({ t }) =>
|
|
65
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
66
|
+
t('plugin-ecommerce:addressPostalCode'),
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'country',
|
|
70
|
+
type: 'text',
|
|
71
|
+
label: ({ t }) =>
|
|
72
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
73
|
+
t('plugin-ecommerce:addressCountry'),
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'phone',
|
|
77
|
+
type: 'text',
|
|
78
|
+
label: ({ t }) =>
|
|
79
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
80
|
+
t('plugin-ecommerce:addressPhone'),
|
|
81
|
+
},
|
|
82
|
+
]
|
|
83
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CountryType } from '../types.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Default list of countries supported for forms and payments.
|
|
5
|
+
* This can be overriden or reused in other parts of the application.
|
|
6
|
+
*
|
|
7
|
+
* The label is the human-readable name of the country, and the value is the ISO 3166-1 alpha-2 code.
|
|
8
|
+
*/
|
|
9
|
+
export const defaultCountries: CountryType[] = [
|
|
10
|
+
{ label: 'United States', value: 'US' },
|
|
11
|
+
{ label: 'United Kingdom', value: 'GB' },
|
|
12
|
+
{ label: 'Canada', value: 'CA' },
|
|
13
|
+
{ label: 'Australia', value: 'AU' },
|
|
14
|
+
{ label: 'Austria', value: 'AT' },
|
|
15
|
+
{ label: 'Belgium', value: 'BE' },
|
|
16
|
+
{ label: 'Brazil', value: 'BR' },
|
|
17
|
+
{ label: 'Bulgaria', value: 'BG' },
|
|
18
|
+
{ label: 'Cyprus', value: 'CY' },
|
|
19
|
+
{ label: 'Czech Republic', value: 'CZ' },
|
|
20
|
+
{ label: 'Denmark', value: 'DK' },
|
|
21
|
+
{ label: 'Estonia', value: 'EE' },
|
|
22
|
+
{ label: 'Finland', value: 'FI' },
|
|
23
|
+
{ label: 'France', value: 'FR' },
|
|
24
|
+
{ label: 'Germany', value: 'DE' },
|
|
25
|
+
{ label: 'Greece', value: 'GR' },
|
|
26
|
+
{ label: 'Hong Kong', value: 'HK' },
|
|
27
|
+
{ label: 'Hungary', value: 'HU' },
|
|
28
|
+
{ label: 'India', value: 'IN' },
|
|
29
|
+
{ label: 'Ireland', value: 'IE' },
|
|
30
|
+
{ label: 'Italy', value: 'IT' },
|
|
31
|
+
{ label: 'Japan', value: 'JP' },
|
|
32
|
+
{ label: 'Latvia', value: 'LV' },
|
|
33
|
+
{ label: 'Lithuania', value: 'LT' },
|
|
34
|
+
{ label: 'Luxembourg', value: 'LU' },
|
|
35
|
+
{ label: 'Malaysia', value: 'MY' },
|
|
36
|
+
{ label: 'Malta', value: 'MT' },
|
|
37
|
+
{ label: 'Mexico', value: 'MX' },
|
|
38
|
+
{ label: 'Netherlands', value: 'NL' },
|
|
39
|
+
{ label: 'New Zealand', value: 'NZ' },
|
|
40
|
+
{ label: 'Norway', value: 'NO' },
|
|
41
|
+
{ label: 'Poland', value: 'PL' },
|
|
42
|
+
{ label: 'Portugal', value: 'PT' },
|
|
43
|
+
{ label: 'Romania', value: 'RO' },
|
|
44
|
+
{ label: 'Singapore', value: 'SG' },
|
|
45
|
+
{ label: 'Slovakia', value: 'SK' },
|
|
46
|
+
{ label: 'Slovenia', value: 'SI' },
|
|
47
|
+
{ label: 'Spain', value: 'ES' },
|
|
48
|
+
{ label: 'Sweden', value: 'SE' },
|
|
49
|
+
{ label: 'Switzerland', value: 'CH' },
|
|
50
|
+
]
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { CollectionBeforeChangeHook } from 'payload'
|
|
2
|
+
|
|
3
|
+
type Props = {
|
|
4
|
+
productsSlug: string
|
|
5
|
+
variantsSlug: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const beforeChangeCart: (args: Props) => CollectionBeforeChangeHook =
|
|
9
|
+
({ productsSlug, variantsSlug }) =>
|
|
10
|
+
async ({ data, req }) => {
|
|
11
|
+
// Update subtotal based on items in the cart
|
|
12
|
+
if (data.items && Array.isArray(data.items)) {
|
|
13
|
+
const priceField = `priceIn${data.currency}`
|
|
14
|
+
|
|
15
|
+
let subtotal = 0
|
|
16
|
+
|
|
17
|
+
for (const item of data.items) {
|
|
18
|
+
if (item.variant) {
|
|
19
|
+
const id = typeof item.variant === 'object' ? item.variant.id : item.variant
|
|
20
|
+
|
|
21
|
+
const variant = await req.payload.findByID({
|
|
22
|
+
id,
|
|
23
|
+
collection: variantsSlug,
|
|
24
|
+
depth: 0,
|
|
25
|
+
select: {
|
|
26
|
+
[priceField]: true,
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
subtotal += variant[priceField] * item.quantity
|
|
31
|
+
} else {
|
|
32
|
+
const id = typeof item.product === 'object' ? item.product.id : item.product
|
|
33
|
+
|
|
34
|
+
const product = await req.payload.findByID({
|
|
35
|
+
id,
|
|
36
|
+
collection: productsSlug,
|
|
37
|
+
depth: 0,
|
|
38
|
+
select: {
|
|
39
|
+
[priceField]: true,
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
subtotal += product[priceField] * item.quantity
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
data.subtotal = subtotal
|
|
48
|
+
} else {
|
|
49
|
+
data.subtotal = 0
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { CollectionConfig, Field } from 'payload'
|
|
2
|
+
|
|
3
|
+
import type { CurrenciesConfig, FieldsOverride } from '../types.js'
|
|
4
|
+
|
|
5
|
+
import { amountField } from '../fields/amountField.js'
|
|
6
|
+
import { cartItemsField } from '../fields/cartItemsField.js'
|
|
7
|
+
import { currencyField } from '../fields/currencyField.js'
|
|
8
|
+
import { beforeChangeCart } from './beforeChange.js'
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
currenciesConfig?: CurrenciesConfig
|
|
12
|
+
/**
|
|
13
|
+
* Slug of the customers collection, defaults to 'users'.
|
|
14
|
+
*/
|
|
15
|
+
customersSlug?: string
|
|
16
|
+
/**
|
|
17
|
+
* Enables support for variants in the cart.
|
|
18
|
+
* Defaults to false.
|
|
19
|
+
*/
|
|
20
|
+
enableVariants?: boolean
|
|
21
|
+
overrides?: { fields?: FieldsOverride } & Partial<Omit<CollectionConfig, 'fields'>>
|
|
22
|
+
/**
|
|
23
|
+
* Slug of the products collection, defaults to 'products'.
|
|
24
|
+
*/
|
|
25
|
+
productsSlug?: string
|
|
26
|
+
/**
|
|
27
|
+
* Slug of the variants collection, defaults to 'variants'.
|
|
28
|
+
*/
|
|
29
|
+
variantsSlug?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const cartsCollection: (props?: Props) => CollectionConfig = (props) => {
|
|
33
|
+
const {
|
|
34
|
+
currenciesConfig,
|
|
35
|
+
customersSlug = 'users',
|
|
36
|
+
enableVariants = false,
|
|
37
|
+
overrides,
|
|
38
|
+
productsSlug = 'products',
|
|
39
|
+
variantsSlug = 'variants',
|
|
40
|
+
} = props || {}
|
|
41
|
+
const fieldsOverride = overrides?.fields
|
|
42
|
+
|
|
43
|
+
const defaultFields: Field[] = [
|
|
44
|
+
{
|
|
45
|
+
name: 'customer',
|
|
46
|
+
type: 'relationship',
|
|
47
|
+
label: ({ t }) =>
|
|
48
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
49
|
+
t('plugin-ecommerce:customer'),
|
|
50
|
+
relationTo: customersSlug,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'purchasedAt',
|
|
54
|
+
type: 'date',
|
|
55
|
+
label: ({ t }) =>
|
|
56
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
57
|
+
t('plugin-ecommerce:purchasedAt'),
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'status',
|
|
61
|
+
type: 'select',
|
|
62
|
+
defaultValue: 'open',
|
|
63
|
+
interfaceName: 'CartStatus',
|
|
64
|
+
label: ({ t }) =>
|
|
65
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
66
|
+
t('plugin-ecommerce:status'),
|
|
67
|
+
options: [
|
|
68
|
+
{
|
|
69
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
70
|
+
label: ({ t }) => t('plugin-ecommerce:open'),
|
|
71
|
+
value: 'open',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
75
|
+
label: ({ t }) => t('plugin-ecommerce:abandoned'),
|
|
76
|
+
value: 'abandoned',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
80
|
+
label: ({ t }) => t('plugin-ecommerce:completed'),
|
|
81
|
+
value: 'completed',
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
...(currenciesConfig
|
|
86
|
+
? [
|
|
87
|
+
currencyField({
|
|
88
|
+
currenciesConfig,
|
|
89
|
+
}),
|
|
90
|
+
amountField({
|
|
91
|
+
currenciesConfig,
|
|
92
|
+
overrides: {
|
|
93
|
+
name: 'subtotal',
|
|
94
|
+
label: ({ t }) =>
|
|
95
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
96
|
+
t('plugin-ecommerce:subtotal'),
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
99
|
+
]
|
|
100
|
+
: []),
|
|
101
|
+
cartItemsField({
|
|
102
|
+
enableVariants,
|
|
103
|
+
overrides: {
|
|
104
|
+
label: ({ t }) =>
|
|
105
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
106
|
+
t('plugin-ecommerce:items'),
|
|
107
|
+
labels: {
|
|
108
|
+
plural: ({ t }) =>
|
|
109
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
110
|
+
t('plugin-ecommerce:items'),
|
|
111
|
+
singular: ({ t }) =>
|
|
112
|
+
// @ts-expect-error - translations are not typed in plugins yet
|
|
113
|
+
t('plugin-ecommerce:item'),
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
productsSlug,
|
|
117
|
+
variantsSlug,
|
|
118
|
+
}),
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
const fields =
|
|
122
|
+
fieldsOverride && typeof fieldsOverride === 'function'
|
|
123
|
+
? fieldsOverride({ defaultFields })
|
|
124
|
+
: defaultFields
|
|
125
|
+
|
|
126
|
+
const baseConfig: CollectionConfig = {
|
|
127
|
+
slug: 'carts',
|
|
128
|
+
timestamps: true,
|
|
129
|
+
...overrides,
|
|
130
|
+
admin: {
|
|
131
|
+
useAsTitle: 'createdAt',
|
|
132
|
+
...overrides?.admin,
|
|
133
|
+
},
|
|
134
|
+
fields,
|
|
135
|
+
hooks: {
|
|
136
|
+
beforeChange: [
|
|
137
|
+
// This hook can be used to update the subtotal before saving the cart
|
|
138
|
+
beforeChangeCart({ productsSlug, variantsSlug }),
|
|
139
|
+
...(overrides?.hooks?.beforeChange || []),
|
|
140
|
+
],
|
|
141
|
+
...overrides?.hooks,
|
|
142
|
+
},
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return { ...baseConfig }
|
|
146
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Currency } from '../types.js'
|
|
2
|
+
|
|
3
|
+
export const EUR: Currency = {
|
|
4
|
+
code: 'EUR',
|
|
5
|
+
decimals: 2,
|
|
6
|
+
label: 'Euro',
|
|
7
|
+
symbol: '€',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const USD: Currency = {
|
|
11
|
+
code: 'USD',
|
|
12
|
+
decimals: 2,
|
|
13
|
+
label: 'US Dollar',
|
|
14
|
+
symbol: '$',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const GBP: Currency = {
|
|
18
|
+
code: 'GBP',
|
|
19
|
+
decimals: 2,
|
|
20
|
+
label: 'British Pound',
|
|
21
|
+
symbol: '£',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const JPY: Currency = {
|
|
25
|
+
code: 'JPY',
|
|
26
|
+
decimals: 0,
|
|
27
|
+
label: 'Japanese Yen',
|
|
28
|
+
symbol: '¥',
|
|
29
|
+
}
|