Skip to content

Commit

Permalink
feat(core): Support custom fields on Channel entity
Browse files Browse the repository at this point in the history
Relates to #598
  • Loading branch information
rohanrajpal authored Jan 27, 2021
1 parent 77fbb2f commit 489faf5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export type CustomFieldConfig =
*/
export interface CustomFields {
Address?: CustomFieldConfig[];
Channel?: CustomFieldConfig[];
Collection?: CustomFieldConfig[];
Customer?: CustomFieldConfig[];
Facet?: CustomFieldConfig[];
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/config/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export const defaultConfig: RuntimeVendureConfig = {
},
customFields: {
Address: [],
Channel: [],
Collection: [],
Customer: [],
Facet: [],
Expand Down
9 changes: 5 additions & 4 deletions packages/core/src/entity/channel/channel.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DeepPartial } from '@vendure/common/lib/shared-types';
import { Column, Entity, ManyToOne } from 'typeorm';

import { VendureEntity } from '../base/base.entity';
import { CustomChannelFields } from '../custom-entity-fields';
import { Zone } from '../zone/zone.entity';

/**
Expand Down Expand Up @@ -38,13 +39,13 @@ export class Channel extends VendureEntity {
@Column('varchar')
currencyCode: CurrencyCode;

@Column(type => CustomChannelFields)
customFields: CustomChannelFields;

@Column() pricesIncludeTax: boolean;

private generateToken(): string {
const randomString = () =>
Math.random()
.toString(36)
.substr(3, 10);
const randomString = () => Math.random().toString(36).substr(3, 10);
return `${randomString()}${randomString()}`;
}
}
1 change: 1 addition & 0 deletions packages/core/src/entity/custom-entity-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class CustomProductFields {}
export class CustomProductFieldsTranslation {}
export class CustomCollectionFields {}
export class CustomCollectionFieldsTranslation {}
export class CustomChannelFields {}
export class CustomProductOptionFields {}
export class CustomProductOptionFieldsTranslation {}
export class CustomProductOptionGroupFields {}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/entity/register-custom-entity-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { VendureConfig } from '../config/vendure-config';

import {
CustomAddressFields,
CustomChannelFields,
CustomCollectionFields,
CustomCollectionFieldsTranslation,
CustomCustomerFields,
Expand Down Expand Up @@ -211,6 +212,7 @@ export function registerCustomEntityFields(config: VendureConfig) {
registerCustomFieldsForEntity(config, 'Collection', CustomCollectionFields);
registerCustomFieldsForEntity(config, 'Collection', CustomCollectionFieldsTranslation, true);
registerCustomFieldsForEntity(config, 'Customer', CustomCustomerFields);
registerCustomFieldsForEntity(config, 'Channel', CustomChannelFields);
registerCustomFieldsForEntity(config, 'Facet', CustomFacetFields);
registerCustomFieldsForEntity(config, 'Facet', CustomFacetFieldsTranslation, true);
registerCustomFieldsForEntity(config, 'FacetValue', CustomFacetValueFields);
Expand Down

0 comments on commit 489faf5

Please sign in to comment.