@payloadcms/plugin-ecommerce 0.0.1-beta.0 → 3.57.0-internal.46327a6
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/dist/collections/addresses/createAddressesCollection.d.ts +21 -0
- package/dist/collections/addresses/createAddressesCollection.d.ts.map +1 -0
- package/dist/collections/addresses/createAddressesCollection.js +71 -0
- package/dist/collections/addresses/createAddressesCollection.js.map +1 -0
- package/dist/collections/addresses/defaultAddressFields.d.ts +3 -0
- package/dist/collections/addresses/defaultAddressFields.d.ts.map +1 -0
- package/dist/collections/addresses/defaultAddressFields.js +72 -0
- package/dist/collections/addresses/defaultAddressFields.js.map +1 -0
- package/dist/collections/addresses/defaultCountries.d.ts +9 -0
- package/dist/collections/addresses/defaultCountries.d.ts.map +1 -0
- package/dist/collections/addresses/defaultCountries.js +169 -0
- package/dist/collections/addresses/defaultCountries.js.map +1 -0
- package/dist/collections/addresses/hooks/beforeChange.d.ts +8 -0
- package/dist/collections/addresses/hooks/beforeChange.d.ts.map +1 -0
- package/dist/collections/addresses/hooks/beforeChange.js +12 -0
- package/dist/collections/addresses/hooks/beforeChange.js.map +1 -0
- package/dist/collections/carts/beforeChange.d.ts +8 -0
- package/dist/collections/carts/beforeChange.d.ts.map +1 -0
- package/dist/collections/carts/beforeChange.js +37 -0
- package/dist/collections/carts/beforeChange.js.map +1 -0
- package/dist/collections/carts/createCartsCollection.d.ts +29 -0
- package/dist/collections/carts/createCartsCollection.d.ts.map +1 -0
- package/dist/collections/carts/createCartsCollection.js +138 -0
- package/dist/collections/carts/createCartsCollection.js.map +1 -0
- package/dist/collections/carts/statusBeforeRead.d.ts +3 -0
- package/dist/collections/carts/statusBeforeRead.d.ts.map +1 -0
- package/dist/collections/carts/statusBeforeRead.js +18 -0
- package/dist/collections/carts/statusBeforeRead.js.map +1 -0
- package/dist/collections/orders/createOrdersCollection.d.ts +34 -0
- package/dist/collections/orders/createOrdersCollection.d.ts.map +1 -0
- package/dist/collections/orders/createOrdersCollection.js +162 -0
- package/dist/collections/orders/createOrdersCollection.js.map +1 -0
- package/dist/collections/products/createProductsCollection.d.ts +26 -0
- package/dist/collections/products/createProductsCollection.d.ts.map +1 -0
- package/dist/collections/products/createProductsCollection.js +62 -0
- package/dist/collections/products/createProductsCollection.js.map +1 -0
- package/dist/collections/transactions/createTransactionsCollection.d.ts +40 -0
- package/dist/collections/transactions/createTransactionsCollection.d.ts.map +1 -0
- package/dist/collections/transactions/createTransactionsCollection.js +157 -0
- package/dist/collections/transactions/createTransactionsCollection.js.map +1 -0
- package/dist/collections/variants/createVariantOptionsCollection.d.ts +15 -0
- package/dist/collections/variants/createVariantOptionsCollection.d.ts.map +1 -0
- package/dist/collections/variants/createVariantOptionsCollection.js +53 -0
- package/dist/collections/variants/createVariantOptionsCollection.js.map +1 -0
- package/dist/collections/variants/createVariantTypesCollection.d.ts +15 -0
- package/dist/collections/variants/createVariantTypesCollection.d.ts.map +1 -0
- package/dist/collections/variants/createVariantTypesCollection.js +49 -0
- package/dist/collections/variants/createVariantTypesCollection.js.map +1 -0
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.d.ts +8 -0
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.d.ts.map +1 -0
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js +38 -0
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js.map +1 -0
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.d.ts +7 -0
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.d.ts.map +1 -0
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js +53 -0
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js.map +1 -0
- package/dist/collections/variants/createVariantsCollection/index.d.ts +24 -0
- package/dist/collections/variants/createVariantsCollection/index.d.ts.map +1 -0
- package/dist/collections/variants/createVariantsCollection/index.js +101 -0
- package/dist/collections/variants/createVariantsCollection/index.js.map +1 -0
- package/dist/currencies/index.d.ts +5 -0
- package/dist/currencies/index.d.ts.map +1 -0
- package/dist/currencies/index.js +20 -0
- package/dist/currencies/index.js.map +1 -0
- package/dist/endpoints/confirmOrder.d.ts +42 -0
- package/dist/endpoints/confirmOrder.d.ts.map +1 -0
- package/dist/endpoints/confirmOrder.js +143 -0
- package/dist/endpoints/confirmOrder.js.map +1 -0
- package/dist/endpoints/initiatePayment.d.ts +43 -0
- package/dist/endpoints/initiatePayment.d.ts.map +1 -0
- package/dist/endpoints/initiatePayment.js +220 -0
- package/dist/endpoints/initiatePayment.js.map +1 -0
- package/dist/exports/client/index.d.ts +3 -0
- package/dist/exports/client/index.d.ts.map +1 -0
- package/dist/exports/client/index.js +4 -0
- package/dist/exports/client/index.js.map +1 -0
- package/dist/exports/client/react.d.ts +4 -0
- package/dist/exports/client/react.d.ts.map +1 -0
- package/dist/exports/client/react.js +5 -0
- package/dist/exports/client/react.js.map +1 -0
- package/dist/exports/payments/stripe.d.ts +2 -0
- package/dist/exports/payments/stripe.d.ts.map +1 -0
- package/dist/exports/payments/stripe.js +3 -0
- package/dist/exports/payments/stripe.js.map +1 -0
- package/dist/exports/rsc.d.ts +3 -0
- package/dist/exports/rsc.d.ts.map +1 -0
- package/dist/exports/rsc.js +4 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/exports/translations.d.ts +2 -0
- package/dist/exports/translations.d.ts.map +1 -0
- package/dist/exports/translations.js +3 -0
- package/dist/exports/translations.js.map +1 -0
- package/dist/exports/types.d.ts +2 -0
- package/dist/exports/types.d.ts.map +1 -0
- package/dist/exports/types.js +3 -0
- package/dist/exports/types.js.map +1 -0
- package/dist/fields/amountField.d.ts +13 -0
- package/dist/fields/amountField.d.ts.map +1 -0
- package/dist/fields/amountField.js +33 -0
- package/dist/fields/amountField.js.map +1 -0
- package/dist/fields/cartItemsField.d.ts +26 -0
- package/dist/fields/cartItemsField.d.ts.map +1 -0
- package/dist/fields/cartItemsField.js +55 -0
- package/dist/fields/cartItemsField.js.map +1 -0
- package/dist/fields/currencyField.d.ts +9 -0
- package/dist/fields/currencyField.d.ts.map +1 -0
- package/dist/fields/currencyField.js +29 -0
- package/dist/fields/currencyField.js.map +1 -0
- package/dist/fields/inventoryField.d.ts +7 -0
- package/dist/fields/inventoryField.d.ts.map +1 -0
- package/dist/fields/inventoryField.js +16 -0
- package/dist/fields/inventoryField.js.map +1 -0
- package/dist/fields/pricesField.d.ts +12 -0
- package/dist/fields/pricesField.d.ts.map +1 -0
- package/dist/fields/pricesField.js +54 -0
- package/dist/fields/pricesField.js.map +1 -0
- package/dist/fields/statusField.d.ts +8 -0
- package/dist/fields/statusField.d.ts.map +1 -0
- package/dist/fields/statusField.js +49 -0
- package/dist/fields/statusField.js.map +1 -0
- package/dist/fields/variantsFields.d.ts +14 -0
- package/dist/fields/variantsFields.d.ts.map +1 -0
- package/dist/fields/variantsFields.js +48 -0
- package/dist/fields/variantsFields.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +238 -0
- package/dist/index.js.map +1 -0
- package/dist/payments/adapters/stripe/confirmOrder.d.ts +11 -0
- package/dist/payments/adapters/stripe/confirmOrder.d.ts.map +1 -0
- package/dist/payments/adapters/stripe/confirmOrder.js +101 -0
- package/dist/payments/adapters/stripe/confirmOrder.js.map +1 -0
- package/dist/payments/adapters/stripe/endpoints/webhooks.d.ts +13 -0
- package/dist/payments/adapters/stripe/endpoints/webhooks.d.ts.map +1 -0
- package/dist/payments/adapters/stripe/endpoints/webhooks.js +53 -0
- package/dist/payments/adapters/stripe/endpoints/webhooks.js.map +1 -0
- package/dist/payments/adapters/stripe/index.d.ts +60 -0
- package/dist/payments/adapters/stripe/index.d.ts.map +1 -0
- package/dist/payments/adapters/stripe/index.js +68 -0
- package/dist/payments/adapters/stripe/index.js.map +1 -0
- package/dist/payments/adapters/stripe/initiatePayment.d.ts +11 -0
- package/dist/payments/adapters/stripe/initiatePayment.d.ts.map +1 -0
- package/dist/payments/adapters/stripe/initiatePayment.js +102 -0
- package/dist/payments/adapters/stripe/initiatePayment.js.map +1 -0
- package/dist/react/provider/index.d.ts +41 -0
- package/dist/react/provider/index.d.ts.map +1 -0
- package/dist/react/provider/index.js +791 -0
- package/dist/react/provider/index.js.map +1 -0
- package/dist/react/provider/types.d.ts +171 -0
- package/dist/react/provider/types.d.ts.map +1 -0
- package/dist/react/provider/types.js +3 -0
- package/dist/react/provider/types.js.map +1 -0
- package/dist/react/provider/utilities.d.ts +9 -0
- package/dist/react/provider/utilities.d.ts.map +1 -0
- package/dist/react/provider/utilities.js +13 -0
- package/dist/react/provider/utilities.js.map +1 -0
- package/dist/translations/en.d.ts +3 -0
- package/dist/translations/en.d.ts.map +1 -0
- package/dist/translations/en.js +86 -0
- package/dist/translations/en.js.map +1 -0
- package/dist/translations/index.d.ts +7 -0
- package/dist/translations/index.d.ts.map +1 -0
- package/dist/translations/index.js +6 -0
- package/dist/translations/index.js.map +1 -0
- package/dist/types.d.ts +658 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/PriceCell/index.d.ts +12 -0
- package/dist/ui/PriceCell/index.d.ts.map +1 -0
- package/dist/ui/PriceCell/index.js +38 -0
- package/dist/ui/PriceCell/index.js.map +1 -0
- package/dist/ui/PriceInput/FormattedInput.d.ts +17 -0
- package/dist/ui/PriceInput/FormattedInput.d.ts.map +1 -0
- package/dist/ui/PriceInput/FormattedInput.js +146 -0
- package/dist/ui/PriceInput/FormattedInput.js.map +1 -0
- package/{src/ui/PriceInput/index.scss → dist/ui/PriceInput/index.css} +7 -0
- package/dist/ui/PriceInput/index.d.ts +11 -0
- package/dist/ui/PriceInput/index.d.ts.map +1 -0
- package/dist/ui/PriceInput/index.js +20 -0
- package/dist/ui/PriceInput/index.js.map +1 -0
- package/dist/ui/PriceRowLabel/index.d.ts +8 -0
- package/dist/ui/PriceRowLabel/index.d.ts.map +1 -0
- package/dist/ui/PriceRowLabel/index.js +66 -0
- package/dist/ui/PriceRowLabel/index.js.map +1 -0
- package/dist/ui/VariantOptionsSelector/ErrorBox.d.ts +8 -0
- package/dist/ui/VariantOptionsSelector/ErrorBox.d.ts.map +1 -0
- package/dist/ui/VariantOptionsSelector/ErrorBox.js +28 -0
- package/dist/ui/VariantOptionsSelector/ErrorBox.js.map +1 -0
- package/dist/ui/VariantOptionsSelector/OptionsSelect.d.ts +13 -0
- package/dist/ui/VariantOptionsSelector/OptionsSelect.d.ts.map +1 -0
- package/dist/ui/VariantOptionsSelector/OptionsSelect.js +71 -0
- package/dist/ui/VariantOptionsSelector/OptionsSelect.js.map +1 -0
- package/dist/ui/VariantOptionsSelector/index.d.ts +6 -0
- package/dist/ui/VariantOptionsSelector/index.d.ts.map +1 -0
- package/dist/ui/VariantOptionsSelector/index.js +78 -0
- package/dist/ui/VariantOptionsSelector/index.js.map +1 -0
- package/dist/ui/utilities.d.ts +16 -0
- package/dist/ui/utilities.d.ts.map +1 -0
- package/dist/ui/utilities.js +26 -0
- package/dist/ui/utilities.js.map +1 -0
- package/dist/utilities/defaultProductsValidation.d.ts +3 -0
- package/dist/utilities/defaultProductsValidation.d.ts.map +1 -0
- package/dist/utilities/defaultProductsValidation.js +40 -0
- package/dist/utilities/defaultProductsValidation.js.map +1 -0
- package/dist/utilities/errorCodes.d.ts +3 -0
- package/dist/utilities/errorCodes.d.ts.map +1 -0
- package/dist/utilities/errorCodes.js +4 -0
- package/dist/utilities/errorCodes.js.map +1 -0
- package/dist/utilities/getCollectionSlugMap.d.ts +11 -0
- package/dist/utilities/getCollectionSlugMap.d.ts.map +1 -0
- package/dist/utilities/getCollectionSlugMap.js +25 -0
- package/dist/utilities/getCollectionSlugMap.js.map +1 -0
- package/dist/utilities/sanitizePluginConfig.d.ts +7 -0
- package/dist/utilities/sanitizePluginConfig.d.ts.map +1 -0
- package/dist/utilities/sanitizePluginConfig.js +67 -0
- package/dist/utilities/sanitizePluginConfig.js.map +1 -0
- package/package.json +98 -1
- package/.prettierignore +0 -12
- package/.swcrc +0 -24
- package/eslint.config.js +0 -18
- package/src/addresses/addressesCollection.ts +0 -76
- package/src/addresses/defaultAddressFields.ts +0 -83
- package/src/addresses/defaultCountries.ts +0 -50
- package/src/carts/beforeChange.ts +0 -51
- package/src/carts/cartsCollection.ts +0 -146
- package/src/currencies/index.ts +0 -29
- package/src/endpoints/confirmOrder.ts +0 -312
- package/src/endpoints/initiatePayment.ts +0 -322
- package/src/exports/addresses.ts +0 -2
- package/src/exports/currencies.ts +0 -1
- package/src/exports/fields.ts +0 -5
- package/src/exports/orders.ts +0 -1
- package/src/exports/payments/stripe.ts +0 -1
- package/src/exports/plugin.ts +0 -1
- package/src/exports/products.ts +0 -1
- package/src/exports/react.ts +0 -8
- package/src/exports/transactions.ts +0 -1
- package/src/exports/translations.ts +0 -1
- package/src/exports/types.ts +0 -7
- package/src/exports/ui.ts +0 -3
- package/src/exports/variants.ts +0 -5
- package/src/fields/amountField.ts +0 -43
- package/src/fields/cartItemsField.ts +0 -84
- package/src/fields/currencyField.ts +0 -39
- package/src/fields/inventoryField.ts +0 -22
- package/src/fields/pricesField.ts +0 -65
- package/src/fields/statusField.ts +0 -57
- package/src/fields/variantsFields.ts +0 -56
- package/src/index.ts +0 -275
- package/src/orders/ordersCollection.ts +0 -157
- package/src/payments/adapters/stripe/confirmOrder.ts +0 -123
- package/src/payments/adapters/stripe/endpoints/webhooks.ts +0 -69
- package/src/payments/adapters/stripe/index.ts +0 -135
- package/src/payments/adapters/stripe/initiatePayment.ts +0 -131
- package/src/products/productsCollection.ts +0 -78
- package/src/react/provider/index.tsx +0 -893
- package/src/react/provider/types.ts +0 -184
- package/src/react/provider/utilities.ts +0 -22
- package/src/transactions/transactionsCollection.ts +0 -166
- package/src/translations/en.ts +0 -64
- package/src/translations/index.ts +0 -11
- package/src/types.ts +0 -403
- package/src/ui/PriceInput/FormattedInput.tsx +0 -134
- package/src/ui/PriceInput/index.tsx +0 -43
- package/src/ui/PriceInput/utilities.ts +0 -46
- package/src/ui/PriceRowLabel/index.tsx +0 -56
- package/src/ui/VariantOptionsSelector/ErrorBox.tsx +0 -27
- package/src/ui/VariantOptionsSelector/OptionsSelect.tsx +0 -78
- package/src/ui/VariantOptionsSelector/index.tsx +0 -83
- package/src/utilities/defaultProductsValidation.ts +0 -42
- package/src/utilities/errorCodes.ts +0 -14
- package/src/utilities/getCollectionSlugMap.ts +0 -84
- package/src/utilities/sanitizePluginConfig.ts +0 -80
- package/src/variants/variantOptionsCollection.ts +0 -59
- package/src/variants/variantTypesCollection.ts +0 -55
- package/src/variants/variantsCollection/hooks/beforeChange.ts +0 -47
- package/src/variants/variantsCollection/hooks/validateOptions.ts +0 -72
- package/src/variants/variantsCollection/index.ts +0 -119
- package/tsconfig.json +0 -7
- package/tsconfig.tsbuildinfo +0 -1
- /package/{src → dist}/translations/translation-schema.json +0 -0
- /package/{src → dist}/ui/PriceRowLabel/index.css +0 -0
- /package/{src → dist}/ui/VariantOptionsSelector/index.css +0 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { amountField } from '../../fields/amountField.js';
|
|
2
|
+
import { cartItemsField } from '../../fields/cartItemsField.js';
|
|
3
|
+
import { currencyField } from '../../fields/currencyField.js';
|
|
4
|
+
import { statusField } from '../../fields/statusField.js';
|
|
5
|
+
export const createTransactionsCollection = (props)=>{
|
|
6
|
+
const { access: { adminOnly }, addressFields, cartsSlug = 'carts', currenciesConfig, customersSlug = 'users', enableVariants = false, ordersSlug = 'orders', paymentMethods, productsSlug = 'products', variantsSlug = 'variants' } = props || {};
|
|
7
|
+
const fields = [
|
|
8
|
+
{
|
|
9
|
+
type: 'tabs',
|
|
10
|
+
tabs: [
|
|
11
|
+
{
|
|
12
|
+
fields: [
|
|
13
|
+
cartItemsField({
|
|
14
|
+
enableVariants,
|
|
15
|
+
overrides: {
|
|
16
|
+
name: 'items',
|
|
17
|
+
label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
18
|
+
t('plugin-ecommerce:items'),
|
|
19
|
+
labels: {
|
|
20
|
+
plural: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
21
|
+
t('plugin-ecommerce:items'),
|
|
22
|
+
singular: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
23
|
+
t('plugin-ecommerce:item')
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
productsSlug,
|
|
27
|
+
variantsSlug
|
|
28
|
+
}),
|
|
29
|
+
...paymentMethods?.length && paymentMethods.length > 0 ? [
|
|
30
|
+
{
|
|
31
|
+
name: 'paymentMethod',
|
|
32
|
+
type: 'select',
|
|
33
|
+
label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
34
|
+
t('plugin-ecommerce:paymentMethod'),
|
|
35
|
+
options: paymentMethods.map((method)=>({
|
|
36
|
+
label: method.label ?? method.name,
|
|
37
|
+
value: method.name
|
|
38
|
+
}))
|
|
39
|
+
},
|
|
40
|
+
...paymentMethods.map((method)=>method.group) || []
|
|
41
|
+
] : []
|
|
42
|
+
],
|
|
43
|
+
label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
44
|
+
t('plugin-ecommerce:transactionDetails')
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
fields: [
|
|
48
|
+
...addressFields ? [
|
|
49
|
+
{
|
|
50
|
+
name: 'billingAddress',
|
|
51
|
+
type: 'group',
|
|
52
|
+
fields: addressFields,
|
|
53
|
+
label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
54
|
+
t('plugin-ecommerce:billingAddress')
|
|
55
|
+
}
|
|
56
|
+
] : []
|
|
57
|
+
],
|
|
58
|
+
label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
59
|
+
t('plugin-ecommerce:billing')
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
statusField({
|
|
64
|
+
overrides: {
|
|
65
|
+
admin: {
|
|
66
|
+
position: 'sidebar'
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}),
|
|
70
|
+
{
|
|
71
|
+
name: 'customer',
|
|
72
|
+
type: 'relationship',
|
|
73
|
+
admin: {
|
|
74
|
+
position: 'sidebar'
|
|
75
|
+
},
|
|
76
|
+
label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
77
|
+
t('plugin-ecommerce:customer'),
|
|
78
|
+
relationTo: customersSlug
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'customerEmail',
|
|
82
|
+
type: 'email',
|
|
83
|
+
admin: {
|
|
84
|
+
position: 'sidebar'
|
|
85
|
+
},
|
|
86
|
+
label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
87
|
+
t('plugin-ecommerce:customerEmail')
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'order',
|
|
91
|
+
type: 'relationship',
|
|
92
|
+
admin: {
|
|
93
|
+
position: 'sidebar'
|
|
94
|
+
},
|
|
95
|
+
label: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
96
|
+
t('plugin-ecommerce:order'),
|
|
97
|
+
relationTo: ordersSlug
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'cart',
|
|
101
|
+
type: 'relationship',
|
|
102
|
+
admin: {
|
|
103
|
+
position: 'sidebar'
|
|
104
|
+
},
|
|
105
|
+
relationTo: cartsSlug
|
|
106
|
+
},
|
|
107
|
+
...currenciesConfig ? [
|
|
108
|
+
{
|
|
109
|
+
type: 'row',
|
|
110
|
+
admin: {
|
|
111
|
+
position: 'sidebar'
|
|
112
|
+
},
|
|
113
|
+
fields: [
|
|
114
|
+
amountField({
|
|
115
|
+
currenciesConfig
|
|
116
|
+
}),
|
|
117
|
+
currencyField({
|
|
118
|
+
currenciesConfig
|
|
119
|
+
})
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
] : []
|
|
123
|
+
];
|
|
124
|
+
const baseConfig = {
|
|
125
|
+
slug: 'transactions',
|
|
126
|
+
access: {
|
|
127
|
+
create: adminOnly,
|
|
128
|
+
delete: adminOnly,
|
|
129
|
+
read: adminOnly,
|
|
130
|
+
update: adminOnly
|
|
131
|
+
},
|
|
132
|
+
admin: {
|
|
133
|
+
defaultColumns: [
|
|
134
|
+
'createdAt',
|
|
135
|
+
'customer',
|
|
136
|
+
'order',
|
|
137
|
+
'amount',
|
|
138
|
+
'status'
|
|
139
|
+
],
|
|
140
|
+
description: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
141
|
+
t('plugin-ecommerce:transactionsCollectionDescription'),
|
|
142
|
+
group: 'Ecommerce'
|
|
143
|
+
},
|
|
144
|
+
fields,
|
|
145
|
+
labels: {
|
|
146
|
+
plural: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
147
|
+
t('plugin-ecommerce:transactions'),
|
|
148
|
+
singular: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
149
|
+
t('plugin-ecommerce:transaction')
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
...baseConfig
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
//# sourceMappingURL=createTransactionsCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/transactions/createTransactionsCollection.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { AccessConfig, CurrenciesConfig, PaymentAdapter } from '../../types.js'\n\nimport { amountField } from '../../fields/amountField.js'\nimport { cartItemsField } from '../../fields/cartItemsField.js'\nimport { currencyField } from '../../fields/currencyField.js'\nimport { statusField } from '../../fields/statusField.js'\n\ntype Props = {\n access: {\n adminOnly: NonNullable<AccessConfig['adminOnly']>\n }\n /**\n * Array of fields used for capturing the billing address.\n */\n addressFields?: Field[]\n /**\n * Slug of the carts collection, defaults to 'carts'.\n */\n cartsSlug?: string\n currenciesConfig?: CurrenciesConfig\n /**\n * Slug of the customers collection, defaults to 'users'.\n */\n customersSlug?: string\n /**\n * Enable variants in the transactions collection.\n */\n enableVariants?: boolean\n /**\n * Slug of the orders collection, defaults to 'orders'.\n */\n ordersSlug?: string\n paymentMethods?: PaymentAdapter[]\n /**\n * Slug of the products collection, defaults to 'products'.\n */\n productsSlug?: string\n /**\n * Slug of the variants collection, defaults to 'variants'.\n */\n variantsSlug?: string\n}\n\nexport const createTransactionsCollection: (props: Props) => CollectionConfig = (props) => {\n const {\n access: { adminOnly },\n addressFields,\n cartsSlug = 'carts',\n currenciesConfig,\n customersSlug = 'users',\n enableVariants = false,\n ordersSlug = 'orders',\n paymentMethods,\n productsSlug = 'products',\n variantsSlug = 'variants',\n } = props || {}\n\n const fields: Field[] = [\n {\n type: 'tabs',\n tabs: [\n {\n fields: [\n cartItemsField({\n enableVariants,\n overrides: {\n name: 'items',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:items'),\n labels: {\n plural: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:items'),\n singular: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:item'),\n },\n },\n productsSlug,\n variantsSlug,\n }),\n ...(paymentMethods?.length && paymentMethods.length > 0\n ? [\n {\n name: 'paymentMethod',\n type: 'select',\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:paymentMethod'),\n options: paymentMethods.map((method) => ({\n label: method.label ?? method.name,\n value: method.name,\n })),\n } as Field,\n ...(paymentMethods.map((method) => method.group) || []),\n ]\n : []),\n ],\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:transactionDetails'),\n },\n {\n fields: [\n ...(addressFields\n ? [\n {\n name: 'billingAddress',\n type: 'group',\n fields: addressFields,\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:billingAddress'),\n } as Field,\n ]\n : []),\n ],\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:billing'),\n },\n ],\n },\n statusField({\n overrides: {\n admin: {\n position: 'sidebar',\n },\n },\n }),\n {\n name: 'customer',\n type: 'relationship',\n admin: {\n position: 'sidebar',\n },\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:customer'),\n relationTo: customersSlug,\n },\n {\n name: 'customerEmail',\n type: 'email',\n admin: {\n position: 'sidebar',\n },\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:customerEmail'),\n },\n {\n name: 'order',\n type: 'relationship',\n admin: {\n position: 'sidebar',\n },\n label: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:order'),\n relationTo: ordersSlug,\n },\n {\n name: 'cart',\n type: 'relationship',\n admin: {\n position: 'sidebar',\n },\n relationTo: cartsSlug,\n },\n ...(currenciesConfig\n ? [\n {\n type: 'row',\n admin: {\n position: 'sidebar',\n },\n fields: [\n amountField({\n currenciesConfig,\n }),\n currencyField({\n currenciesConfig,\n }),\n ],\n } as Field,\n ]\n : []),\n ]\n\n const baseConfig: CollectionConfig = {\n slug: 'transactions',\n access: {\n create: adminOnly,\n delete: adminOnly,\n read: adminOnly,\n update: adminOnly,\n },\n admin: {\n defaultColumns: ['createdAt', 'customer', 'order', 'amount', 'status'],\n description: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:transactionsCollectionDescription'),\n group: 'Ecommerce',\n },\n fields,\n labels: {\n plural: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:transactions'),\n singular: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:transaction'),\n },\n }\n\n return { ...baseConfig }\n}\n"],"names":["amountField","cartItemsField","currencyField","statusField","createTransactionsCollection","props","access","adminOnly","addressFields","cartsSlug","currenciesConfig","customersSlug","enableVariants","ordersSlug","paymentMethods","productsSlug","variantsSlug","fields","type","tabs","overrides","name","label","t","labels","plural","singular","length","options","map","method","value","group","admin","position","relationTo","baseConfig","slug","create","delete","read","update","defaultColumns","description"],"mappings":"AAIA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,aAAa,QAAQ,gCAA+B;AAC7D,SAASC,WAAW,QAAQ,8BAA6B;AAsCzD,OAAO,MAAMC,+BAAmE,CAACC;IAC/E,MAAM,EACJC,QAAQ,EAAEC,SAAS,EAAE,EACrBC,aAAa,EACbC,YAAY,OAAO,EACnBC,gBAAgB,EAChBC,gBAAgB,OAAO,EACvBC,iBAAiB,KAAK,EACtBC,aAAa,QAAQ,EACrBC,cAAc,EACdC,eAAe,UAAU,EACzBC,eAAe,UAAU,EAC1B,GAAGX,SAAS,CAAC;IAEd,MAAMY,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;gBACJ;oBACEF,QAAQ;wBACNhB,eAAe;4BACbW;4BACAQ,WAAW;gCACTC,MAAM;gCACNC,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;oCAC/DA,EAAE;gCACJC,QAAQ;oCACNC,QAAQ,CAAC,EAAEF,CAAC,EAAE,GACZ,+DAA+D;wCAC/DA,EAAE;oCACJG,UAAU,CAAC,EAAEH,CAAC,EAAE,GACd,+DAA+D;wCAC/DA,EAAE;gCACN;4BACF;4BACAR;4BACAC;wBACF;2BACIF,gBAAgBa,UAAUb,eAAea,MAAM,GAAG,IAClD;4BACE;gCACEN,MAAM;gCACNH,MAAM;gCACNI,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;oCAC/DA,EAAE;gCACJK,SAASd,eAAee,GAAG,CAAC,CAACC,SAAY,CAAA;wCACvCR,OAAOQ,OAAOR,KAAK,IAAIQ,OAAOT,IAAI;wCAClCU,OAAOD,OAAOT,IAAI;oCACpB,CAAA;4BACF;+BACIP,eAAee,GAAG,CAAC,CAACC,SAAWA,OAAOE,KAAK,KAAK,EAAE;yBACvD,GACD,EAAE;qBACP;oBACDV,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;wBAC/DA,EAAE;gBACN;gBACA;oBACEN,QAAQ;2BACFT,gBACA;4BACE;gCACEa,MAAM;gCACNH,MAAM;gCACND,QAAQT;gCACRc,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;oCAC/DA,EAAE;4BACN;yBACD,GACD,EAAE;qBACP;oBACDD,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;wBAC/DA,EAAE;gBACN;aACD;QACH;QACApB,YAAY;YACViB,WAAW;gBACTa,OAAO;oBACLC,UAAU;gBACZ;YACF;QACF;QACA;YACEb,MAAM;YACNH,MAAM;YACNe,OAAO;gBACLC,UAAU;YACZ;YACAZ,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;YACJY,YAAYxB;QACd;QACA;YACEU,MAAM;YACNH,MAAM;YACNe,OAAO;gBACLC,UAAU;YACZ;YACAZ,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;QACN;QACA;YACEF,MAAM;YACNH,MAAM;YACNe,OAAO;gBACLC,UAAU;YACZ;YACAZ,OAAO,CAAC,EAAEC,CAAC,EAAE,GACX,+DAA+D;gBAC/DA,EAAE;YACJY,YAAYtB;QACd;QACA;YACEQ,MAAM;YACNH,MAAM;YACNe,OAAO;gBACLC,UAAU;YACZ;YACAC,YAAY1B;QACd;WACIC,mBACA;YACE;gBACEQ,MAAM;gBACNe,OAAO;oBACLC,UAAU;gBACZ;gBACAjB,QAAQ;oBACNjB,YAAY;wBACVU;oBACF;oBACAR,cAAc;wBACZQ;oBACF;iBACD;YACH;SACD,GACD,EAAE;KACP;IAED,MAAM0B,aAA+B;QACnCC,MAAM;QACN/B,QAAQ;YACNgC,QAAQ/B;YACRgC,QAAQhC;YACRiC,MAAMjC;YACNkC,QAAQlC;QACV;QACA0B,OAAO;YACLS,gBAAgB;gBAAC;gBAAa;gBAAY;gBAAS;gBAAU;aAAS;YACtEC,aAAa,CAAC,EAAEpB,CAAC,EAAE,GACjB,+DAA+D;gBAC/DA,EAAE;YACJS,OAAO;QACT;QACAf;QACAO,QAAQ;YACNC,QAAQ,CAAC,EAAEF,CAAC,EAAE,GACZ,+DAA+D;gBAC/DA,EAAE;YACJG,UAAU,CAAC,EAAEH,CAAC,EAAE,GACd,+DAA+D;gBAC/DA,EAAE;QACN;IACF;IAEA,OAAO;QAAE,GAAGa,UAAU;IAAC;AACzB,EAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
import type { AccessConfig } from '../../types.js';
|
|
3
|
+
type Props = {
|
|
4
|
+
access: {
|
|
5
|
+
adminOnly: NonNullable<AccessConfig['adminOnly']>;
|
|
6
|
+
publicAccess: NonNullable<AccessConfig['publicAccess']>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Slug of the variant types collection, defaults to 'variantTypes'.
|
|
10
|
+
*/
|
|
11
|
+
variantTypesSlug?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const createVariantOptionsCollection: (props: Props) => CollectionConfig;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=createVariantOptionsCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createVariantOptionsCollection.d.ts","sourceRoot":"","sources":["../../../src/collections/variants/createVariantOptionsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,KAAK,KAAK,GAAG;IACX,MAAM,EAAE;QACN,SAAS,EAAE,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAA;QACjD,YAAY,EAAE,WAAW,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAAA;KACxD,CAAA;IACD;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,8BAA8B,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,gBAwD9D,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const createVariantOptionsCollection = (props)=>{
|
|
2
|
+
const { access: { adminOnly, publicAccess }, variantTypesSlug = 'variantTypes' } = props || {};
|
|
3
|
+
const fields = [
|
|
4
|
+
{
|
|
5
|
+
name: 'variantType',
|
|
6
|
+
type: 'relationship',
|
|
7
|
+
admin: {
|
|
8
|
+
readOnly: true
|
|
9
|
+
},
|
|
10
|
+
relationTo: variantTypesSlug,
|
|
11
|
+
required: true
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: 'label',
|
|
15
|
+
type: 'text',
|
|
16
|
+
required: true
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'value',
|
|
20
|
+
type: 'text',
|
|
21
|
+
admin: {
|
|
22
|
+
description: 'should be defaulted or dynamic based on label'
|
|
23
|
+
},
|
|
24
|
+
required: true
|
|
25
|
+
}
|
|
26
|
+
];
|
|
27
|
+
const baseConfig = {
|
|
28
|
+
slug: 'variantOptions',
|
|
29
|
+
access: {
|
|
30
|
+
create: adminOnly,
|
|
31
|
+
delete: adminOnly,
|
|
32
|
+
read: publicAccess,
|
|
33
|
+
update: adminOnly
|
|
34
|
+
},
|
|
35
|
+
admin: {
|
|
36
|
+
group: false,
|
|
37
|
+
useAsTitle: 'label'
|
|
38
|
+
},
|
|
39
|
+
fields,
|
|
40
|
+
labels: {
|
|
41
|
+
plural: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
42
|
+
t('plugin-ecommerce:variantOptions'),
|
|
43
|
+
singular: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
44
|
+
t('plugin-ecommerce:variantOption')
|
|
45
|
+
},
|
|
46
|
+
trash: true
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
...baseConfig
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=createVariantOptionsCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/variants/createVariantOptionsCollection.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { AccessConfig } from '../../types.js'\n\ntype Props = {\n access: {\n adminOnly: NonNullable<AccessConfig['adminOnly']>\n publicAccess: NonNullable<AccessConfig['publicAccess']>\n }\n /**\n * Slug of the variant types collection, defaults to 'variantTypes'.\n */\n variantTypesSlug?: string\n}\n\nexport const createVariantOptionsCollection: (props: Props) => CollectionConfig = (props) => {\n const {\n access: { adminOnly, publicAccess },\n variantTypesSlug = 'variantTypes',\n } = props || {}\n\n const fields: Field[] = [\n {\n name: 'variantType',\n type: 'relationship',\n admin: {\n readOnly: true,\n },\n relationTo: variantTypesSlug,\n required: true,\n },\n {\n name: 'label',\n type: 'text',\n required: true,\n },\n {\n name: 'value',\n type: 'text',\n admin: {\n description: 'should be defaulted or dynamic based on label',\n },\n required: true,\n },\n ]\n\n const baseConfig: CollectionConfig = {\n slug: 'variantOptions',\n access: {\n create: adminOnly,\n delete: adminOnly,\n read: publicAccess,\n update: adminOnly,\n },\n admin: {\n group: false,\n useAsTitle: 'label',\n },\n fields,\n labels: {\n plural: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantOptions'),\n singular: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantOption'),\n },\n trash: true,\n }\n\n return { ...baseConfig }\n}\n"],"names":["createVariantOptionsCollection","props","access","adminOnly","publicAccess","variantTypesSlug","fields","name","type","admin","readOnly","relationTo","required","description","baseConfig","slug","create","delete","read","update","group","useAsTitle","labels","plural","t","singular","trash"],"mappings":"AAeA,OAAO,MAAMA,iCAAqE,CAACC;IACjF,MAAM,EACJC,QAAQ,EAAEC,SAAS,EAAEC,YAAY,EAAE,EACnCC,mBAAmB,cAAc,EAClC,GAAGJ,SAAS,CAAC;IAEd,MAAMK,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,UAAU;YACZ;YACAC,YAAYN;YACZO,UAAU;QACZ;QACA;YACEL,MAAM;YACNC,MAAM;YACNI,UAAU;QACZ;QACA;YACEL,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLI,aAAa;YACf;YACAD,UAAU;QACZ;KACD;IAED,MAAME,aAA+B;QACnCC,MAAM;QACNb,QAAQ;YACNc,QAAQb;YACRc,QAAQd;YACRe,MAAMd;YACNe,QAAQhB;QACV;QACAM,OAAO;YACLW,OAAO;YACPC,YAAY;QACd;QACAf;QACAgB,QAAQ;YACNC,QAAQ,CAAC,EAAEC,CAAC,EAAE,GACZ,+DAA+D;gBAC/DA,EAAE;YACJC,UAAU,CAAC,EAAED,CAAC,EAAE,GACd,+DAA+D;gBAC/DA,EAAE;QACN;QACAE,OAAO;IACT;IAEA,OAAO;QAAE,GAAGZ,UAAU;IAAC;AACzB,EAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
import type { AccessConfig } from '../../types.js';
|
|
3
|
+
type Props = {
|
|
4
|
+
access: {
|
|
5
|
+
adminOnly: NonNullable<AccessConfig['adminOnly']>;
|
|
6
|
+
publicAccess: NonNullable<AccessConfig['publicAccess']>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Slug of the variant options collection, defaults to 'variantOptions'.
|
|
10
|
+
*/
|
|
11
|
+
variantOptionsSlug?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const createVariantTypesCollection: (props: Props) => CollectionConfig;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=createVariantTypesCollection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createVariantTypesCollection.d.ts","sourceRoot":"","sources":["../../../src/collections/variants/createVariantTypesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,KAAK,KAAK,GAAG;IACX,MAAM,EAAE;QACN,SAAS,EAAE,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAA;QACjD,YAAY,EAAE,WAAW,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAAA;KACxD,CAAA;IACD;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B,CAAA;AAED,eAAO,MAAM,4BAA4B,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,gBAoD5D,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export const createVariantTypesCollection = (props)=>{
|
|
2
|
+
const { access: { adminOnly, publicAccess }, variantOptionsSlug = 'variantOptions' } = props || {};
|
|
3
|
+
const fields = [
|
|
4
|
+
{
|
|
5
|
+
name: 'label',
|
|
6
|
+
type: 'text',
|
|
7
|
+
required: true
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
name: 'name',
|
|
11
|
+
type: 'text',
|
|
12
|
+
required: true
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'options',
|
|
16
|
+
type: 'join',
|
|
17
|
+
collection: variantOptionsSlug,
|
|
18
|
+
maxDepth: 2,
|
|
19
|
+
on: 'variantType',
|
|
20
|
+
orderable: true
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
const baseConfig = {
|
|
24
|
+
slug: 'variantTypes',
|
|
25
|
+
access: {
|
|
26
|
+
create: adminOnly,
|
|
27
|
+
delete: adminOnly,
|
|
28
|
+
read: publicAccess,
|
|
29
|
+
update: adminOnly
|
|
30
|
+
},
|
|
31
|
+
admin: {
|
|
32
|
+
group: false,
|
|
33
|
+
useAsTitle: 'label'
|
|
34
|
+
},
|
|
35
|
+
fields,
|
|
36
|
+
labels: {
|
|
37
|
+
plural: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
38
|
+
t('plugin-ecommerce:variantTypes'),
|
|
39
|
+
singular: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
40
|
+
t('plugin-ecommerce:variantType')
|
|
41
|
+
},
|
|
42
|
+
trash: true
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
...baseConfig
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=createVariantTypesCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/variants/createVariantTypesCollection.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { AccessConfig } from '../../types.js'\n\ntype Props = {\n access: {\n adminOnly: NonNullable<AccessConfig['adminOnly']>\n publicAccess: NonNullable<AccessConfig['publicAccess']>\n }\n /**\n * Slug of the variant options collection, defaults to 'variantOptions'.\n */\n variantOptionsSlug?: string\n}\n\nexport const createVariantTypesCollection: (props: Props) => CollectionConfig = (props) => {\n const {\n access: { adminOnly, publicAccess },\n variantOptionsSlug = 'variantOptions',\n } = props || {}\n\n const fields: Field[] = [\n {\n name: 'label',\n type: 'text',\n required: true,\n },\n {\n name: 'name',\n type: 'text',\n required: true,\n },\n {\n name: 'options',\n type: 'join',\n collection: variantOptionsSlug,\n maxDepth: 2,\n on: 'variantType',\n orderable: true,\n },\n ]\n\n const baseConfig: CollectionConfig = {\n slug: 'variantTypes',\n access: {\n create: adminOnly,\n delete: adminOnly,\n read: publicAccess,\n update: adminOnly,\n },\n admin: {\n group: false,\n useAsTitle: 'label',\n },\n fields,\n labels: {\n plural: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantTypes'),\n singular: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantType'),\n },\n trash: true,\n }\n\n return { ...baseConfig }\n}\n"],"names":["createVariantTypesCollection","props","access","adminOnly","publicAccess","variantOptionsSlug","fields","name","type","required","collection","maxDepth","on","orderable","baseConfig","slug","create","delete","read","update","admin","group","useAsTitle","labels","plural","t","singular","trash"],"mappings":"AAeA,OAAO,MAAMA,+BAAmE,CAACC;IAC/E,MAAM,EACJC,QAAQ,EAAEC,SAAS,EAAEC,YAAY,EAAE,EACnCC,qBAAqB,gBAAgB,EACtC,GAAGJ,SAAS,CAAC;IAEd,MAAMK,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;YACNC,UAAU;QACZ;QACA;YACEF,MAAM;YACNC,MAAM;YACNC,UAAU;QACZ;QACA;YACEF,MAAM;YACNC,MAAM;YACNE,YAAYL;YACZM,UAAU;YACVC,IAAI;YACJC,WAAW;QACb;KACD;IAED,MAAMC,aAA+B;QACnCC,MAAM;QACNb,QAAQ;YACNc,QAAQb;YACRc,QAAQd;YACRe,MAAMd;YACNe,QAAQhB;QACV;QACAiB,OAAO;YACLC,OAAO;YACPC,YAAY;QACd;QACAhB;QACAiB,QAAQ;YACNC,QAAQ,CAAC,EAAEC,CAAC,EAAE,GACZ,+DAA+D;gBAC/DA,EAAE;YACJC,UAAU,CAAC,EAAED,CAAC,EAAE,GACd,+DAA+D;gBAC/DA,EAAE;QACN;QACAE,OAAO;IACT;IAEA,OAAO;QAAE,GAAGb,UAAU;IAAC;AACzB,EAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CollectionBeforeChangeHook } from 'payload';
|
|
2
|
+
type Props = {
|
|
3
|
+
productsSlug: string;
|
|
4
|
+
variantOptionsSlug: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const variantsCollectionBeforeChange: (args: Props) => CollectionBeforeChangeHook;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=beforeChange.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"beforeChange.d.ts","sourceRoot":"","sources":["../../../../../src/collections/variants/createVariantsCollection/hooks/beforeChange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAEzD,KAAK,KAAK,GAAG;IACX,YAAY,EAAE,MAAM,CAAA;IACpB,kBAAkB,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,8BAA8B,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,0BA2C3D,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const variantsCollectionBeforeChange = ({ productsSlug, variantOptionsSlug })=>async ({ data, req })=>{
|
|
2
|
+
if (data?.options?.length && data.options.length > 0) {
|
|
3
|
+
const titleArray = [];
|
|
4
|
+
const productID = data.product;
|
|
5
|
+
const product = await req.payload.findByID({
|
|
6
|
+
id: productID,
|
|
7
|
+
collection: productsSlug,
|
|
8
|
+
depth: 0,
|
|
9
|
+
select: {
|
|
10
|
+
title: true,
|
|
11
|
+
variantTypes: true
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
if (product.title && typeof product.title === 'string') {
|
|
15
|
+
titleArray.push(product.title);
|
|
16
|
+
}
|
|
17
|
+
for (const option of data.options){
|
|
18
|
+
const variantOption = await req.payload.findByID({
|
|
19
|
+
id: option,
|
|
20
|
+
collection: variantOptionsSlug,
|
|
21
|
+
depth: 0,
|
|
22
|
+
select: {
|
|
23
|
+
label: true
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
if (!variantOption) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (variantOption.label && typeof variantOption.label === 'string') {
|
|
30
|
+
titleArray.push(variantOption.label);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
data.title = titleArray.join(' — ');
|
|
34
|
+
}
|
|
35
|
+
return data;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=beforeChange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/collections/variants/createVariantsCollection/hooks/beforeChange.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook } from 'payload'\n\ntype Props = {\n productsSlug: string\n variantOptionsSlug: string\n}\n\nexport const variantsCollectionBeforeChange: (args: Props) => CollectionBeforeChangeHook =\n ({ productsSlug, variantOptionsSlug }) =>\n async ({ data, req }) => {\n if (data?.options?.length && data.options.length > 0) {\n const titleArray: string[] = []\n const productID = data.product\n const product = await req.payload.findByID({\n id: productID,\n collection: productsSlug,\n depth: 0,\n select: {\n title: true,\n variantTypes: true,\n },\n })\n\n if (product.title && typeof product.title === 'string') {\n titleArray.push(product.title)\n }\n\n for (const option of data.options) {\n const variantOption = await req.payload.findByID({\n id: option,\n collection: variantOptionsSlug,\n depth: 0,\n select: {\n label: true,\n },\n })\n\n if (!variantOption) {\n continue\n }\n\n if (variantOption.label && typeof variantOption.label === 'string') {\n titleArray.push(variantOption.label)\n }\n }\n\n data.title = titleArray.join(' — ')\n }\n\n return data\n }\n"],"names":["variantsCollectionBeforeChange","productsSlug","variantOptionsSlug","data","req","options","length","titleArray","productID","product","payload","findByID","id","collection","depth","select","title","variantTypes","push","option","variantOption","label","join"],"mappings":"AAOA,OAAO,MAAMA,iCACX,CAAC,EAAEC,YAAY,EAAEC,kBAAkB,EAAE,GACrC,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAE;QAClB,IAAID,MAAME,SAASC,UAAUH,KAAKE,OAAO,CAACC,MAAM,GAAG,GAAG;YACpD,MAAMC,aAAuB,EAAE;YAC/B,MAAMC,YAAYL,KAAKM,OAAO;YAC9B,MAAMA,UAAU,MAAML,IAAIM,OAAO,CAACC,QAAQ,CAAC;gBACzCC,IAAIJ;gBACJK,YAAYZ;gBACZa,OAAO;gBACPC,QAAQ;oBACNC,OAAO;oBACPC,cAAc;gBAChB;YACF;YAEA,IAAIR,QAAQO,KAAK,IAAI,OAAOP,QAAQO,KAAK,KAAK,UAAU;gBACtDT,WAAWW,IAAI,CAACT,QAAQO,KAAK;YAC/B;YAEA,KAAK,MAAMG,UAAUhB,KAAKE,OAAO,CAAE;gBACjC,MAAMe,gBAAgB,MAAMhB,IAAIM,OAAO,CAACC,QAAQ,CAAC;oBAC/CC,IAAIO;oBACJN,YAAYX;oBACZY,OAAO;oBACPC,QAAQ;wBACNM,OAAO;oBACT;gBACF;gBAEA,IAAI,CAACD,eAAe;oBAClB;gBACF;gBAEA,IAAIA,cAAcC,KAAK,IAAI,OAAOD,cAAcC,KAAK,KAAK,UAAU;oBAClEd,WAAWW,IAAI,CAACE,cAAcC,KAAK;gBACrC;YACF;YAEAlB,KAAKa,KAAK,GAAGT,WAAWe,IAAI,CAAC;QAC/B;QAEA,OAAOnB;IACT,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateOptions.d.ts","sourceRoot":"","sources":["../../../../../src/collections/variants/createVariantsCollection/hooks/validateOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,KAAK,KAAK,GAAG;IACX,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAChC,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,QAiE9C,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const validateOptions = (props)=>async (values, { data, req })=>{
|
|
2
|
+
const { productsCollectionSlug = 'products' } = props || {};
|
|
3
|
+
const { t } = req;
|
|
4
|
+
if (!values || values.length === 0) {
|
|
5
|
+
// @ts-expect-error - TODO: Fix types
|
|
6
|
+
return t('ecommerce:variantOptionsRequired');
|
|
7
|
+
}
|
|
8
|
+
const productID = data.product;
|
|
9
|
+
if (!productID) {
|
|
10
|
+
// @ts-expect-error - TODO: Fix types
|
|
11
|
+
return t('ecommerce:productRequired');
|
|
12
|
+
}
|
|
13
|
+
const product = await req.payload.findByID({
|
|
14
|
+
id: productID,
|
|
15
|
+
collection: productsCollectionSlug,
|
|
16
|
+
depth: 1,
|
|
17
|
+
joins: {
|
|
18
|
+
variants: {
|
|
19
|
+
where: {
|
|
20
|
+
id: {
|
|
21
|
+
not_equals: data.id
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
select: {
|
|
27
|
+
variants: true,
|
|
28
|
+
variantTypes: true
|
|
29
|
+
},
|
|
30
|
+
user: req.user
|
|
31
|
+
});
|
|
32
|
+
// @ts-expect-error - TODO: Fix types
|
|
33
|
+
const variants = product.variants?.docs ?? [];
|
|
34
|
+
// @ts-expect-error - TODO: Fix types
|
|
35
|
+
if (values.length < product?.variantTypes?.length) {
|
|
36
|
+
// @ts-expect-error - TODO: Fix types
|
|
37
|
+
return t('ecommerce:variantOptionsRequiredAll');
|
|
38
|
+
}
|
|
39
|
+
if (variants.length > 0) {
|
|
40
|
+
const existingOptions = [];
|
|
41
|
+
variants.forEach((variant)=>{
|
|
42
|
+
existingOptions.push(variant.options);
|
|
43
|
+
});
|
|
44
|
+
const exists = existingOptions.some((combo)=>combo.length === values.length && combo.every((val)=>values.includes(val)));
|
|
45
|
+
if (exists) {
|
|
46
|
+
// @ts-expect-error - TODO: Fix types
|
|
47
|
+
return t('ecommerce:variantOptionsAlreadyExists');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=validateOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/collections/variants/createVariantsCollection/hooks/validateOptions.ts"],"sourcesContent":["import type { Validate } from 'payload'\n\ntype Props = {\n productsCollectionSlug?: string\n}\n\nexport const validateOptions: (props?: Props) => Validate =\n (props) =>\n async (values, { data, req }) => {\n const { productsCollectionSlug = 'products' } = props || {}\n const { t } = req\n\n if (!values || values.length === 0) {\n // @ts-expect-error - TODO: Fix types\n return t('ecommerce:variantOptionsRequired')\n }\n\n const productID = data.product\n\n if (!productID) {\n // @ts-expect-error - TODO: Fix types\n return t('ecommerce:productRequired')\n }\n\n const product = await req.payload.findByID({\n id: productID,\n collection: productsCollectionSlug,\n depth: 1,\n joins: {\n variants: {\n where: {\n id: {\n not_equals: data.id, // exclude the current variant from the search\n },\n },\n },\n },\n select: {\n variants: true,\n variantTypes: true,\n },\n user: req.user,\n })\n\n // @ts-expect-error - TODO: Fix types\n const variants = product.variants?.docs ?? []\n\n // @ts-expect-error - TODO: Fix types\n if (values.length < product?.variantTypes?.length) {\n // @ts-expect-error - TODO: Fix types\n return t('ecommerce:variantOptionsRequiredAll')\n }\n\n if (variants.length > 0) {\n const existingOptions: (number | string)[][] = []\n\n variants.forEach((variant: any) => {\n existingOptions.push(variant.options)\n })\n\n const exists = existingOptions.some(\n (combo) => combo.length === values.length && combo.every((val) => values.includes(val)),\n )\n\n if (exists) {\n // @ts-expect-error - TODO: Fix types\n return t('ecommerce:variantOptionsAlreadyExists')\n }\n }\n\n return true\n }\n"],"names":["validateOptions","props","values","data","req","productsCollectionSlug","t","length","productID","product","payload","findByID","id","collection","depth","joins","variants","where","not_equals","select","variantTypes","user","docs","existingOptions","forEach","variant","push","options","exists","some","combo","every","val","includes"],"mappings":"AAMA,OAAO,MAAMA,kBACX,CAACC,QACD,OAAOC,QAAQ,EAAEC,IAAI,EAAEC,GAAG,EAAE;QAC1B,MAAM,EAAEC,yBAAyB,UAAU,EAAE,GAAGJ,SAAS,CAAC;QAC1D,MAAM,EAAEK,CAAC,EAAE,GAAGF;QAEd,IAAI,CAACF,UAAUA,OAAOK,MAAM,KAAK,GAAG;YAClC,qCAAqC;YACrC,OAAOD,EAAE;QACX;QAEA,MAAME,YAAYL,KAAKM,OAAO;QAE9B,IAAI,CAACD,WAAW;YACd,qCAAqC;YACrC,OAAOF,EAAE;QACX;QAEA,MAAMG,UAAU,MAAML,IAAIM,OAAO,CAACC,QAAQ,CAAC;YACzCC,IAAIJ;YACJK,YAAYR;YACZS,OAAO;YACPC,OAAO;gBACLC,UAAU;oBACRC,OAAO;wBACLL,IAAI;4BACFM,YAAYf,KAAKS,EAAE;wBACrB;oBACF;gBACF;YACF;YACAO,QAAQ;gBACNH,UAAU;gBACVI,cAAc;YAChB;YACAC,MAAMjB,IAAIiB,IAAI;QAChB;QAEA,qCAAqC;QACrC,MAAML,WAAWP,QAAQO,QAAQ,EAAEM,QAAQ,EAAE;QAE7C,qCAAqC;QACrC,IAAIpB,OAAOK,MAAM,GAAGE,SAASW,cAAcb,QAAQ;YACjD,qCAAqC;YACrC,OAAOD,EAAE;QACX;QAEA,IAAIU,SAAST,MAAM,GAAG,GAAG;YACvB,MAAMgB,kBAAyC,EAAE;YAEjDP,SAASQ,OAAO,CAAC,CAACC;gBAChBF,gBAAgBG,IAAI,CAACD,QAAQE,OAAO;YACtC;YAEA,MAAMC,SAASL,gBAAgBM,IAAI,CACjC,CAACC,QAAUA,MAAMvB,MAAM,KAAKL,OAAOK,MAAM,IAAIuB,MAAMC,KAAK,CAAC,CAACC,MAAQ9B,OAAO+B,QAAQ,CAACD;YAGpF,IAAIJ,QAAQ;gBACV,qCAAqC;gBACrC,OAAOtB,EAAE;YACX;QACF;QAEA,OAAO;IACT,EAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
import type { AccessConfig, CurrenciesConfig, InventoryConfig } from '../../../types.js';
|
|
3
|
+
type Props = {
|
|
4
|
+
access: {
|
|
5
|
+
adminOnly: NonNullable<AccessConfig['adminOnly']>;
|
|
6
|
+
adminOrPublishedStatus: NonNullable<AccessConfig['adminOrPublishedStatus']>;
|
|
7
|
+
};
|
|
8
|
+
currenciesConfig?: CurrenciesConfig;
|
|
9
|
+
/**
|
|
10
|
+
* Enables inventory tracking for variants. Defaults to true.
|
|
11
|
+
*/
|
|
12
|
+
inventory?: boolean | InventoryConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Slug of the products collection, defaults to 'products'.
|
|
15
|
+
*/
|
|
16
|
+
productsSlug?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Slug of the variant options collection, defaults to 'variantOptions'.
|
|
19
|
+
*/
|
|
20
|
+
variantOptionsSlug?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const createVariantsCollection: (props: Props) => CollectionConfig;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/collections/variants/createVariantsCollection/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAOxF,KAAK,KAAK,GAAG;IACX,MAAM,EAAE;QACN,SAAS,EAAE,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAA;QACjD,sBAAsB,EAAE,WAAW,CAAC,YAAY,CAAC,wBAAwB,CAAC,CAAC,CAAA;KAC5E,CAAA;IACD,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,eAAe,CAAA;IACrC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B,CAAA;AAED,eAAO,MAAM,wBAAwB,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,gBAqGxD,CAAA"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { inventoryField } from '../../../fields/inventoryField.js';
|
|
2
|
+
import { pricesField } from '../../../fields/pricesField.js';
|
|
3
|
+
import { variantsCollectionBeforeChange as beforeChange } from './hooks/beforeChange.js';
|
|
4
|
+
import { validateOptions } from './hooks/validateOptions.js';
|
|
5
|
+
export const createVariantsCollection = (props)=>{
|
|
6
|
+
const { access: { adminOnly, adminOrPublishedStatus }, currenciesConfig, inventory = true, productsSlug = 'products', variantOptionsSlug = 'variantOptions' } = props || {};
|
|
7
|
+
const { supportedCurrencies } = currenciesConfig || {};
|
|
8
|
+
const fields = [
|
|
9
|
+
{
|
|
10
|
+
name: 'title',
|
|
11
|
+
type: 'text',
|
|
12
|
+
admin: {
|
|
13
|
+
description: 'Used for administrative purposes, not shown to customers. This is populated by default.'
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'product',
|
|
18
|
+
type: 'relationship',
|
|
19
|
+
admin: {
|
|
20
|
+
position: 'sidebar',
|
|
21
|
+
readOnly: true
|
|
22
|
+
},
|
|
23
|
+
relationTo: productsSlug,
|
|
24
|
+
required: true
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
// This might need to be a custom component, to show a selector for each variant that is
|
|
28
|
+
// enabled on the parent product
|
|
29
|
+
// - separate select inputs, each showing only a specific variant (w/ options)
|
|
30
|
+
// - it will save data to the DB as IDs in this relationship field
|
|
31
|
+
// and needs a validate function as well which enforces that the options are fully specified, and accurate
|
|
32
|
+
name: 'options',
|
|
33
|
+
type: 'relationship',
|
|
34
|
+
admin: {
|
|
35
|
+
components: {
|
|
36
|
+
Field: {
|
|
37
|
+
path: '@payloadcms/plugin-ecommerce/rsc#VariantOptionsSelector'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
hasMany: true,
|
|
42
|
+
label: 'Variant options',
|
|
43
|
+
relationTo: variantOptionsSlug,
|
|
44
|
+
required: true,
|
|
45
|
+
validate: validateOptions()
|
|
46
|
+
},
|
|
47
|
+
...inventory ? [
|
|
48
|
+
inventoryField()
|
|
49
|
+
] : []
|
|
50
|
+
];
|
|
51
|
+
if (supportedCurrencies?.length && supportedCurrencies.length > 0) {
|
|
52
|
+
const currencyOptions = [];
|
|
53
|
+
supportedCurrencies.forEach((currency)=>{
|
|
54
|
+
currencyOptions.push(currency.code);
|
|
55
|
+
});
|
|
56
|
+
if (currenciesConfig) {
|
|
57
|
+
fields.push(...pricesField({
|
|
58
|
+
currenciesConfig
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const baseConfig = {
|
|
63
|
+
slug: 'variants',
|
|
64
|
+
access: {
|
|
65
|
+
create: adminOnly,
|
|
66
|
+
delete: adminOnly,
|
|
67
|
+
read: adminOrPublishedStatus,
|
|
68
|
+
update: adminOnly
|
|
69
|
+
},
|
|
70
|
+
admin: {
|
|
71
|
+
description: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
72
|
+
t('plugin-ecommerce:variantsCollectionDescription'),
|
|
73
|
+
group: false,
|
|
74
|
+
useAsTitle: 'title'
|
|
75
|
+
},
|
|
76
|
+
fields,
|
|
77
|
+
hooks: {
|
|
78
|
+
beforeChange: [
|
|
79
|
+
beforeChange({
|
|
80
|
+
productsSlug,
|
|
81
|
+
variantOptionsSlug
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
labels: {
|
|
86
|
+
plural: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
87
|
+
t('plugin-ecommerce:variants'),
|
|
88
|
+
singular: ({ t })=>// @ts-expect-error - translations are not typed in plugins yet
|
|
89
|
+
t('plugin-ecommerce:variant')
|
|
90
|
+
},
|
|
91
|
+
trash: true,
|
|
92
|
+
versions: {
|
|
93
|
+
drafts: {
|
|
94
|
+
autosave: true
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
return baseConfig;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/collections/variants/createVariantsCollection/index.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { AccessConfig, CurrenciesConfig, InventoryConfig } from '../../../types.js'\n\nimport { inventoryField } from '../../../fields/inventoryField.js'\nimport { pricesField } from '../../../fields/pricesField.js'\nimport { variantsCollectionBeforeChange as beforeChange } from './hooks/beforeChange.js'\nimport { validateOptions } from './hooks/validateOptions.js'\n\ntype Props = {\n access: {\n adminOnly: NonNullable<AccessConfig['adminOnly']>\n adminOrPublishedStatus: NonNullable<AccessConfig['adminOrPublishedStatus']>\n }\n currenciesConfig?: CurrenciesConfig\n /**\n * Enables inventory tracking for variants. Defaults to true.\n */\n inventory?: boolean | InventoryConfig\n /**\n * Slug of the products collection, defaults to 'products'.\n */\n productsSlug?: string\n /**\n * Slug of the variant options collection, defaults to 'variantOptions'.\n */\n variantOptionsSlug?: string\n}\n\nexport const createVariantsCollection: (props: Props) => CollectionConfig = (props) => {\n const {\n access: { adminOnly, adminOrPublishedStatus },\n currenciesConfig,\n inventory = true,\n productsSlug = 'products',\n variantOptionsSlug = 'variantOptions',\n } = props || {}\n const { supportedCurrencies } = currenciesConfig || {}\n\n const fields: Field[] = [\n {\n name: 'title',\n type: 'text',\n admin: {\n description:\n 'Used for administrative purposes, not shown to customers. This is populated by default.',\n },\n },\n {\n name: 'product',\n type: 'relationship',\n admin: {\n position: 'sidebar',\n readOnly: true,\n },\n relationTo: productsSlug,\n required: true,\n },\n {\n // This might need to be a custom component, to show a selector for each variant that is\n // enabled on the parent product\n // - separate select inputs, each showing only a specific variant (w/ options)\n // - it will save data to the DB as IDs in this relationship field\n // and needs a validate function as well which enforces that the options are fully specified, and accurate\n name: 'options',\n type: 'relationship',\n admin: {\n components: {\n Field: {\n path: '@payloadcms/plugin-ecommerce/rsc#VariantOptionsSelector',\n },\n },\n },\n hasMany: true,\n label: 'Variant options',\n relationTo: variantOptionsSlug,\n required: true,\n validate: validateOptions(),\n },\n ...(inventory ? [inventoryField()] : []),\n ]\n\n if (supportedCurrencies?.length && supportedCurrencies.length > 0) {\n const currencyOptions: string[] = []\n\n supportedCurrencies.forEach((currency) => {\n currencyOptions.push(currency.code)\n })\n\n if (currenciesConfig) {\n fields.push(...pricesField({ currenciesConfig }))\n }\n }\n\n const baseConfig: CollectionConfig = {\n slug: 'variants',\n access: {\n create: adminOnly,\n delete: adminOnly,\n read: adminOrPublishedStatus,\n update: adminOnly,\n },\n admin: {\n description: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variantsCollectionDescription'),\n group: false,\n useAsTitle: 'title',\n },\n fields,\n hooks: {\n beforeChange: [beforeChange({ productsSlug, variantOptionsSlug })],\n },\n labels: {\n plural: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variants'),\n singular: ({ t }) =>\n // @ts-expect-error - translations are not typed in plugins yet\n t('plugin-ecommerce:variant'),\n },\n trash: true,\n versions: {\n drafts: {\n autosave: true,\n },\n },\n }\n\n return baseConfig\n}\n"],"names":["inventoryField","pricesField","variantsCollectionBeforeChange","beforeChange","validateOptions","createVariantsCollection","props","access","adminOnly","adminOrPublishedStatus","currenciesConfig","inventory","productsSlug","variantOptionsSlug","supportedCurrencies","fields","name","type","admin","description","position","readOnly","relationTo","required","components","Field","path","hasMany","label","validate","length","currencyOptions","forEach","currency","push","code","baseConfig","slug","create","delete","read","update","t","group","useAsTitle","hooks","labels","plural","singular","trash","versions","drafts","autosave"],"mappings":"AAIA,SAASA,cAAc,QAAQ,oCAAmC;AAClE,SAASC,WAAW,QAAQ,iCAAgC;AAC5D,SAASC,kCAAkCC,YAAY,QAAQ,0BAAyB;AACxF,SAASC,eAAe,QAAQ,6BAA4B;AAsB5D,OAAO,MAAMC,2BAA+D,CAACC;IAC3E,MAAM,EACJC,QAAQ,EAAEC,SAAS,EAAEC,sBAAsB,EAAE,EAC7CC,gBAAgB,EAChBC,YAAY,IAAI,EAChBC,eAAe,UAAU,EACzBC,qBAAqB,gBAAgB,EACtC,GAAGP,SAAS,CAAC;IACd,MAAM,EAAEQ,mBAAmB,EAAE,GAAGJ,oBAAoB,CAAC;IAErD,MAAMK,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aACE;YACJ;QACF;QACA;YACEH,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLE,UAAU;gBACVC,UAAU;YACZ;YACAC,YAAYV;YACZW,UAAU;QACZ;QACA;YACE,wFAAwF;YACxF,gCAAgC;YAChC,8EAA8E;YAC9E,kEAAkE;YAClE,0GAA0G;YAC1GP,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLM,YAAY;oBACVC,OAAO;wBACLC,MAAM;oBACR;gBACF;YACF;YACAC,SAAS;YACTC,OAAO;YACPN,YAAYT;YACZU,UAAU;YACVM,UAAUzB;QACZ;WACIO,YAAY;YAACX;SAAiB,GAAG,EAAE;KACxC;IAED,IAAIc,qBAAqBgB,UAAUhB,oBAAoBgB,MAAM,GAAG,GAAG;QACjE,MAAMC,kBAA4B,EAAE;QAEpCjB,oBAAoBkB,OAAO,CAAC,CAACC;YAC3BF,gBAAgBG,IAAI,CAACD,SAASE,IAAI;QACpC;QAEA,IAAIzB,kBAAkB;YACpBK,OAAOmB,IAAI,IAAIjC,YAAY;gBAAES;YAAiB;QAChD;IACF;IAEA,MAAM0B,aAA+B;QACnCC,MAAM;QACN9B,QAAQ;YACN+B,QAAQ9B;YACR+B,QAAQ/B;YACRgC,MAAM/B;YACNgC,QAAQjC;QACV;QACAU,OAAO;YACLC,aAAa,CAAC,EAAEuB,CAAC,EAAE,GACjB,+DAA+D;gBAC/DA,EAAE;YACJC,OAAO;YACPC,YAAY;QACd;QACA7B;QACA8B,OAAO;YACL1C,cAAc;gBAACA,aAAa;oBAAES;oBAAcC;gBAAmB;aAAG;QACpE;QACAiC,QAAQ;YACNC,QAAQ,CAAC,EAAEL,CAAC,EAAE,GACZ,+DAA+D;gBAC/DA,EAAE;YACJM,UAAU,CAAC,EAAEN,CAAC,EAAE,GACd,+DAA+D;gBAC/DA,EAAE;QACN;QACAO,OAAO;QACPC,UAAU;YACRC,QAAQ;gBACNC,UAAU;YACZ;QACF;IACF;IAEA,OAAOhB;AACT,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/currencies/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE3C,eAAO,MAAM,GAAG,EAAE,QAKjB,CAAA;AAED,eAAO,MAAM,GAAG,EAAE,QAKjB,CAAA;AAED,eAAO,MAAM,GAAG,EAAE,QAKjB,CAAA"}
|