issue-1664.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import {
  2. Facet,
  3. LanguageCode,
  4. LocaleString,
  5. PluginCommonModule,
  6. Product,
  7. Translation,
  8. VendureEntity,
  9. VendurePlugin,
  10. } from '@vendure/core';
  11. import gql from 'graphql-tag';
  12. import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
  13. @Entity()
  14. class Vendor extends VendureEntity {
  15. constructor(input: Partial<Vendor>) {
  16. super(input);
  17. }
  18. description: LocaleString;
  19. @Column()
  20. name: string;
  21. @OneToMany(() => Product, product => (product.customFields as any).vendor)
  22. products: Product[];
  23. @OneToMany(() => VendorTranslation, translation => translation.base, { eager: true })
  24. translations: Array<Translation<Vendor>>;
  25. }
  26. @Entity()
  27. export class VendorTranslation extends VendureEntity implements Translation<Vendor> {
  28. constructor(input?: Partial<Translation<Vendor>>) {
  29. super(input);
  30. }
  31. @Column('varchar')
  32. languageCode: LanguageCode;
  33. @Column('text')
  34. description: string;
  35. @ManyToOne(() => Vendor, vendor => vendor.translations, { onDelete: 'CASCADE' })
  36. base: Vendor;
  37. }
  38. const schema = gql`
  39. type Vendor implements Node {
  40. id: ID!
  41. createdAt: DateTime!
  42. updatedAt: DateTime!
  43. name: String!
  44. description: String!
  45. }
  46. `;
  47. /**
  48. * Test plugin for https://github.com/vendure-ecommerce/vendure/issues/1664
  49. */
  50. @VendurePlugin({
  51. imports: [PluginCommonModule],
  52. entities: [Vendor, VendorTranslation],
  53. shopApiExtensions: { schema, resolvers: [] },
  54. adminApiExtensions: { schema, resolvers: [] },
  55. configuration: config => {
  56. config.customFields.Product.push({
  57. name: 'vendor',
  58. label: [{ languageCode: LanguageCode.en_AU, value: 'Vendor' }],
  59. type: 'relation',
  60. entity: Vendor,
  61. eager: true,
  62. nullable: false,
  63. defaultValue: null,
  64. ui: {
  65. component: 'cp-product-vendor-selector',
  66. },
  67. });
  68. config.customFields.User.push({
  69. name: 'vendor',
  70. label: [{ languageCode: LanguageCode.en_AU, value: 'Vendor' }],
  71. type: 'relation',
  72. entity: Vendor,
  73. eager: true,
  74. nullable: false,
  75. defaultValue: null,
  76. ui: {
  77. component: 'cp-product-vendor-selector',
  78. },
  79. });
  80. config.customFields.User.push({
  81. name: 'facet',
  82. label: [{ languageCode: LanguageCode.en_AU, value: 'Facet' }],
  83. type: 'relation',
  84. entity: Facet,
  85. eager: true,
  86. nullable: false,
  87. defaultValue: null,
  88. });
  89. config.customFields.Product.push({
  90. name: 'shopifyId',
  91. type: 'float',
  92. public: false,
  93. });
  94. return config;
  95. },
  96. })
  97. export class Test1664Plugin {}