diff --git a/packages/core/src/config/custom-field/custom-field-types.ts b/packages/core/src/config/custom-field/custom-field-types.ts index 2d8c35a041..2cb6ce7419 100644 --- a/packages/core/src/config/custom-field/custom-field-types.ts +++ b/packages/core/src/config/custom-field/custom-field-types.ts @@ -149,6 +149,7 @@ export interface CustomFields { ProductOptionGroup?: CustomFieldConfig[]; ProductVariant?: CustomFieldConfig[]; User?: CustomFieldConfig[]; + ShippingMethod?: CustomFieldConfig[]; } /** diff --git a/packages/core/src/config/default-config.ts b/packages/core/src/config/default-config.ts index 8ed8ae2cbd..ecfef401a7 100644 --- a/packages/core/src/config/default-config.ts +++ b/packages/core/src/config/default-config.ts @@ -132,6 +132,7 @@ export const defaultConfig: RuntimeVendureConfig = { ProductOptionGroup: [], ProductVariant: [], User: [], + ShippingMethod: [], }, plugins: [], }; diff --git a/packages/core/src/entity/custom-entity-fields.ts b/packages/core/src/entity/custom-entity-fields.ts index e8178f63dd..e71f9a8af8 100644 --- a/packages/core/src/entity/custom-entity-fields.ts +++ b/packages/core/src/entity/custom-entity-fields.ts @@ -18,3 +18,4 @@ export class CustomProductVariantFieldsTranslation {} export class CustomUserFields {} export class CustomGlobalSettingsFields {} export class CustomOrderFields {} +export class CustomShippingMethodFields {} diff --git a/packages/core/src/entity/register-custom-entity-fields.ts b/packages/core/src/entity/register-custom-entity-fields.ts index 335b5f9441..5093d3dfeb 100644 --- a/packages/core/src/entity/register-custom-entity-fields.ts +++ b/packages/core/src/entity/register-custom-entity-fields.ts @@ -27,6 +27,7 @@ import { CustomProductOptionGroupFieldsTranslation, CustomProductVariantFields, CustomProductVariantFieldsTranslation, + CustomShippingMethodFields, CustomUserFields, } from './custom-entity-fields'; @@ -62,9 +63,7 @@ function registerCustomFieldsForEntity( const length = customField.length || 255; if (MAX_STRING_LENGTH < length) { throw new Error( - `ERROR: The "length" property of the custom field "${ - customField.name - }" is greater than the maximum allowed value of ${MAX_STRING_LENGTH}`, + `ERROR: The "length" property of the custom field "${customField.name}" is greater than the maximum allowed value of ${MAX_STRING_LENGTH}`, ); } options.length = length; @@ -177,4 +176,5 @@ export function registerCustomEntityFields(config: VendureConfig) { registerCustomFieldsForEntity(config, 'ProductVariant', CustomProductVariantFieldsTranslation, true); registerCustomFieldsForEntity(config, 'User', CustomUserFields); registerCustomFieldsForEntity(config, 'GlobalSettings', CustomGlobalSettingsFields); + registerCustomFieldsForEntity(config, 'ShippingMethod', CustomShippingMethodFields); } diff --git a/packages/core/src/entity/shipping-method/shipping-method.entity.ts b/packages/core/src/entity/shipping-method/shipping-method.entity.ts index c48d75f50d..5f98e15145 100644 --- a/packages/core/src/entity/shipping-method/shipping-method.entity.ts +++ b/packages/core/src/entity/shipping-method/shipping-method.entity.ts @@ -4,6 +4,7 @@ import { Column, Entity, JoinTable, ManyToMany } from 'typeorm'; import { ChannelAware, SoftDeletable } from '../../common/types/common-types'; import { getConfig } from '../../config/config-helpers'; +import { HasCustomFields } from '../../config/custom-field/custom-field-types'; import { ShippingCalculationResult, ShippingCalculator, @@ -11,6 +12,7 @@ import { import { ShippingEligibilityChecker } from '../../config/shipping-method/shipping-eligibility-checker'; import { VendureEntity } from '../base/base.entity'; import { Channel } from '../channel/channel.entity'; +import { CustomShippingMethodFields } from '../custom-entity-fields'; import { Order } from '../order/order.entity'; /** @@ -24,7 +26,7 @@ import { Order } from '../order/order.entity'; * @docsCategory entities */ @Entity() -export class ShippingMethod extends VendureEntity implements ChannelAware, SoftDeletable { +export class ShippingMethod extends VendureEntity implements ChannelAware, SoftDeletable, HasCustomFields { private readonly allCheckers: { [code: string]: ShippingEligibilityChecker } = {}; private readonly allCalculators: { [code: string]: ShippingCalculator } = {}; @@ -47,10 +49,13 @@ export class ShippingMethod extends VendureEntity implements ChannelAware, SoftD @Column('simple-json') calculator: ConfigurableOperation; - @ManyToMany(type => Channel) + @ManyToMany((type) => Channel) @JoinTable() channels: Channel[]; + @Column((type) => CustomShippingMethodFields) + customFields: CustomShippingMethodFields; + async apply(order: Order): Promise { const calculator = this.allCalculators[this.calculator.code]; if (calculator) {