Преглед на файлове

feat(core): Make PaymentMethod entity translatable

Relates to #1184
Michael Bromley преди 2 години
родител
ревизия
2a4b3bc478
променени са 23 файла, в които са добавени 324 реда и са изтрити 90 реда
  1. 20 4
      packages/asset-server-plugin/e2e/graphql/generated-e2e-asset-server-plugin-types.ts
  2. 11 0
      packages/common/src/generated-shop-types.ts
  3. 21 4
      packages/common/src/generated-types.ts
  4. 1 2
      packages/core/e2e/active-order-strategy.e2e-spec.ts
  5. 3 3
      packages/core/e2e/custom-field-relations.e2e-spec.ts
  6. 20 4
      packages/core/e2e/graphql/generated-e2e-admin-types.ts
  7. 10 0
      packages/core/e2e/graphql/generated-e2e-shop-types.ts
  8. 41 11
      packages/core/e2e/payment-method.e2e-spec.ts
  9. 9 4
      packages/core/src/api/schema/admin-api/payment-method.api.graphql
  10. 9 0
      packages/core/src/api/schema/common/payment-method.type.graphql
  11. 1 2
      packages/core/src/data-import/providers/populator/populator.ts
  12. 1 0
      packages/core/src/entity/custom-entity-fields.ts
  13. 2 0
      packages/core/src/entity/entities.ts
  14. 33 0
      packages/core/src/entity/payment-method/payment-method-translation.entity.ts
  15. 11 5
      packages/core/src/entity/payment-method/payment-method.entity.ts
  16. 65 39
      packages/core/src/service/services/payment-method.service.ts
  17. 5 4
      packages/dev-server/dev-config.ts
  18. 20 4
      packages/elasticsearch-plugin/e2e/graphql/generated-e2e-elasticsearch-plugin-types.ts
  19. 20 4
      packages/payments-plugin/e2e/graphql/generated-admin-types.ts
  20. 10 0
      packages/payments-plugin/e2e/graphql/generated-shop-types.ts
  21. 11 0
      packages/payments-plugin/src/mollie/graphql/generated-shop-types.ts
  22. 0 0
      schema-admin.json
  23. 0 0
      schema-shop.json

+ 20 - 4
packages/asset-server-plugin/e2e/graphql/generated-e2e-asset-server-plugin-types.ts

@@ -731,10 +731,9 @@ export type CreatePaymentMethodInput = {
     checker?: InputMaybe<ConfigurableOperationInput>;
     code: Scalars['String'];
     customFields?: InputMaybe<Scalars['JSON']>;
-    description?: InputMaybe<Scalars['String']>;
     enabled: Scalars['Boolean'];
     handler: ConfigurableOperationInput;
-    name: Scalars['String'];
+    translations: Array<PaymentMethodTranslationInput>;
 };
 
 export type CreateProductInput = {
@@ -3622,6 +3621,7 @@ export type PaymentMethod = Node & {
     handler: ConfigurableOperation;
     id: Scalars['ID'];
     name: Scalars['String'];
+    translations: Array<PaymentMethodTranslation>;
     updatedAt: Scalars['DateTime'];
 };
 
@@ -3681,6 +3681,23 @@ export type PaymentMethodSortParameter = {
     updatedAt?: InputMaybe<SortOrder>;
 };
 
+export type PaymentMethodTranslation = {
+    createdAt: Scalars['DateTime'];
+    description: Scalars['String'];
+    id: Scalars['ID'];
+    languageCode: LanguageCode;
+    name: Scalars['String'];
+    updatedAt: Scalars['DateTime'];
+};
+
+export type PaymentMethodTranslationInput = {
+    customFields?: InputMaybe<Scalars['JSON']>;
+    description?: InputMaybe<Scalars['String']>;
+    id?: InputMaybe<Scalars['ID']>;
+    languageCode: LanguageCode;
+    name?: InputMaybe<Scalars['String']>;
+};
+
 /** Returned if an attempting to refund a Payment against OrderLines from a different Order */
 export type PaymentOrderMismatchError = ErrorResult & {
     errorCode: ErrorCode;
@@ -5437,11 +5454,10 @@ export type UpdatePaymentMethodInput = {
     checker?: InputMaybe<ConfigurableOperationInput>;
     code?: InputMaybe<Scalars['String']>;
     customFields?: InputMaybe<Scalars['JSON']>;
-    description?: InputMaybe<Scalars['String']>;
     enabled?: InputMaybe<Scalars['Boolean']>;
     handler?: InputMaybe<ConfigurableOperationInput>;
     id: Scalars['ID'];
-    name?: InputMaybe<Scalars['String']>;
+    translations?: InputMaybe<Array<PaymentMethodTranslationInput>>;
 };
 
 export type UpdateProductInput = {

+ 11 - 0
packages/common/src/generated-shop-types.ts

@@ -2246,6 +2246,7 @@ export type PaymentMethod = Node & {
     handler: ConfigurableOperation;
     id: Scalars['ID'];
     name: Scalars['String'];
+    translations: Array<PaymentMethodTranslation>;
     updatedAt: Scalars['DateTime'];
 };
 
@@ -2260,6 +2261,16 @@ export type PaymentMethodQuote = {
     name: Scalars['String'];
 };
 
+export type PaymentMethodTranslation = {
+    __typename?: 'PaymentMethodTranslation';
+    createdAt: Scalars['DateTime'];
+    description: Scalars['String'];
+    id: Scalars['ID'];
+    languageCode: LanguageCode;
+    name: Scalars['String'];
+    updatedAt: Scalars['DateTime'];
+};
+
 /**
  * @description
  * Permissions for administrators and customers. Used to control access to

+ 21 - 4
packages/common/src/generated-types.ts

@@ -745,10 +745,9 @@ export type CreatePaymentMethodInput = {
   checker?: InputMaybe<ConfigurableOperationInput>;
   code: Scalars['String'];
   customFields?: InputMaybe<Scalars['JSON']>;
-  description?: InputMaybe<Scalars['String']>;
   enabled: Scalars['Boolean'];
   handler: ConfigurableOperationInput;
-  name: Scalars['String'];
+  translations: Array<PaymentMethodTranslationInput>;
 };
 
 export type CreateProductInput = {
@@ -3821,6 +3820,7 @@ export type PaymentMethod = Node & {
   handler: ConfigurableOperation;
   id: Scalars['ID'];
   name: Scalars['String'];
+  translations: Array<PaymentMethodTranslation>;
   updatedAt: Scalars['DateTime'];
 };
 
@@ -3883,6 +3883,24 @@ export type PaymentMethodSortParameter = {
   updatedAt?: InputMaybe<SortOrder>;
 };
 
+export type PaymentMethodTranslation = {
+  __typename?: 'PaymentMethodTranslation';
+  createdAt: Scalars['DateTime'];
+  description: Scalars['String'];
+  id: Scalars['ID'];
+  languageCode: LanguageCode;
+  name: Scalars['String'];
+  updatedAt: Scalars['DateTime'];
+};
+
+export type PaymentMethodTranslationInput = {
+  customFields?: InputMaybe<Scalars['JSON']>;
+  description?: InputMaybe<Scalars['String']>;
+  id?: InputMaybe<Scalars['ID']>;
+  languageCode: LanguageCode;
+  name?: InputMaybe<Scalars['String']>;
+};
+
 /** Returned if an attempting to refund a Payment against OrderLines from a different Order */
 export type PaymentOrderMismatchError = ErrorResult & {
   __typename?: 'PaymentOrderMismatchError';
@@ -5728,11 +5746,10 @@ export type UpdatePaymentMethodInput = {
   checker?: InputMaybe<ConfigurableOperationInput>;
   code?: InputMaybe<Scalars['String']>;
   customFields?: InputMaybe<Scalars['JSON']>;
-  description?: InputMaybe<Scalars['String']>;
   enabled?: InputMaybe<Scalars['Boolean']>;
   handler?: InputMaybe<ConfigurableOperationInput>;
   id: Scalars['ID'];
-  name?: InputMaybe<Scalars['String']>;
+  translations?: InputMaybe<Array<PaymentMethodTranslationInput>>;
 };
 
 export type UpdateProductInput = {

+ 1 - 2
packages/core/e2e/active-order-strategy.e2e-spec.ts

@@ -1,4 +1,4 @@
-import { DefaultLogger, mergeConfig, orderPercentageDiscount } from '@vendure/core';
+import { mergeConfig, orderPercentageDiscount } from '@vendure/core';
 import { createTestEnvironment } from '@vendure/testing';
 import gql from 'graphql-tag';
 import path from 'path';
@@ -25,7 +25,6 @@ import { assertThrowsWithMessage } from './utils/assert-throws-with-message';
 describe('custom ActiveOrderStrategy', () => {
     const { server, adminClient, shopClient } = createTestEnvironment(
         mergeConfig(testConfig(), {
-            logger: new DefaultLogger(),
             plugins: [TokenActiveOrderPlugin],
             paymentOptions: {
                 paymentMethodHandlers: [testSuccessfulPaymentMethod],

+ 3 - 3
packages/core/e2e/custom-field-relations.e2e-spec.ts

@@ -1058,14 +1058,14 @@ describe('Custom field relations', () => {
                     mutation {
                         createPaymentMethod(
                             input: {
-                                name: "test"
                                 code: "test"
                                 enabled: true
                                 handler: {
                                     code: "${testSuccessfulPaymentMethod.code}"
                                     arguments: []
                                 }
-                                customFields: { singleId: "T_1", multiIds: ["T_1", "T_2"] }
+                                customFields: { singleId: "T_1", multiIds: ["T_1", "T_2"] },
+                                translations: [{ languageCode: en, name: "test" }]
                             }
                         ) {
                             id
@@ -1084,7 +1084,7 @@ describe('Custom field relations', () => {
                         updatePaymentMethod(
                             input: {
                                 id: "${paymentMethodId}"
-                                customFields: { singleId: "T_2", multiIds: ["T_3", "T_4"] }
+                                customFields: { singleId: "T_2", multiIds: ["T_3", "T_4"] },
                             }
                         ) {
                             id

+ 20 - 4
packages/core/e2e/graphql/generated-e2e-admin-types.ts

@@ -731,10 +731,9 @@ export type CreatePaymentMethodInput = {
     checker?: InputMaybe<ConfigurableOperationInput>;
     code: Scalars['String'];
     customFields?: InputMaybe<Scalars['JSON']>;
-    description?: InputMaybe<Scalars['String']>;
     enabled: Scalars['Boolean'];
     handler: ConfigurableOperationInput;
-    name: Scalars['String'];
+    translations: Array<PaymentMethodTranslationInput>;
 };
 
 export type CreateProductInput = {
@@ -3622,6 +3621,7 @@ export type PaymentMethod = Node & {
     handler: ConfigurableOperation;
     id: Scalars['ID'];
     name: Scalars['String'];
+    translations: Array<PaymentMethodTranslation>;
     updatedAt: Scalars['DateTime'];
 };
 
@@ -3681,6 +3681,23 @@ export type PaymentMethodSortParameter = {
     updatedAt?: InputMaybe<SortOrder>;
 };
 
+export type PaymentMethodTranslation = {
+    createdAt: Scalars['DateTime'];
+    description: Scalars['String'];
+    id: Scalars['ID'];
+    languageCode: LanguageCode;
+    name: Scalars['String'];
+    updatedAt: Scalars['DateTime'];
+};
+
+export type PaymentMethodTranslationInput = {
+    customFields?: InputMaybe<Scalars['JSON']>;
+    description?: InputMaybe<Scalars['String']>;
+    id?: InputMaybe<Scalars['ID']>;
+    languageCode: LanguageCode;
+    name?: InputMaybe<Scalars['String']>;
+};
+
 /** Returned if an attempting to refund a Payment against OrderLines from a different Order */
 export type PaymentOrderMismatchError = ErrorResult & {
     errorCode: ErrorCode;
@@ -5437,11 +5454,10 @@ export type UpdatePaymentMethodInput = {
     checker?: InputMaybe<ConfigurableOperationInput>;
     code?: InputMaybe<Scalars['String']>;
     customFields?: InputMaybe<Scalars['JSON']>;
-    description?: InputMaybe<Scalars['String']>;
     enabled?: InputMaybe<Scalars['Boolean']>;
     handler?: InputMaybe<ConfigurableOperationInput>;
     id: Scalars['ID'];
-    name?: InputMaybe<Scalars['String']>;
+    translations?: InputMaybe<Array<PaymentMethodTranslationInput>>;
 };
 
 export type UpdateProductInput = {

+ 10 - 0
packages/core/e2e/graphql/generated-e2e-shop-types.ts

@@ -2168,6 +2168,7 @@ export type PaymentMethod = Node & {
     handler: ConfigurableOperation;
     id: Scalars['ID'];
     name: Scalars['String'];
+    translations: Array<PaymentMethodTranslation>;
     updatedAt: Scalars['DateTime'];
 };
 
@@ -2181,6 +2182,15 @@ export type PaymentMethodQuote = {
     name: Scalars['String'];
 };
 
+export type PaymentMethodTranslation = {
+    createdAt: Scalars['DateTime'];
+    description: Scalars['String'];
+    id: Scalars['ID'];
+    languageCode: LanguageCode;
+    name: Scalars['String'];
+    updatedAt: Scalars['DateTime'];
+};
+
 /**
  * @description
  * Permissions for administrators and customers. Used to control access to

+ 41 - 11
packages/core/e2e/payment-method.e2e-spec.ts

@@ -79,13 +79,18 @@ describe('PaymentMethod resolver', () => {
         >(CREATE_PAYMENT_METHOD, {
             input: {
                 code: 'no-checks',
-                name: 'No Checker',
-                description: 'This is a test payment method',
                 enabled: true,
                 handler: {
                     code: dummyPaymentHandler.code,
                     arguments: [{ name: 'automaticSettle', value: 'true' }],
                 },
+                translations: [
+                    {
+                        languageCode: LanguageCode.en,
+                        name: 'No Checker',
+                        description: 'This is a test payment method',
+                    },
+                ],
             },
         });
 
@@ -115,7 +120,6 @@ describe('PaymentMethod resolver', () => {
         >(UPDATE_PAYMENT_METHOD, {
             input: {
                 id: 'T_1',
-                description: 'modified',
                 checker: {
                     code: minPriceChecker.code,
                     arguments: [{ name: 'minPrice', value: '0' }],
@@ -124,6 +128,12 @@ describe('PaymentMethod resolver', () => {
                     code: dummyPaymentHandler.code,
                     arguments: [{ name: 'automaticSettle', value: 'false' }],
                 },
+                translations: [
+                    {
+                        languageCode: LanguageCode.en,
+                        description: 'modified',
+                    },
+                ],
             },
         });
 
@@ -200,8 +210,6 @@ describe('PaymentMethod resolver', () => {
             >(CREATE_PAYMENT_METHOD, {
                 input: {
                     code: 'price-check',
-                    name: 'With Min Price Checker',
-                    description: 'Order total must be more than 2k',
                     enabled: true,
                     checker: {
                         code: minPriceChecker.code,
@@ -211,6 +219,13 @@ describe('PaymentMethod resolver', () => {
                         code: dummyPaymentHandler.code,
                         arguments: [{ name: 'automaticSettle', value: 'true' }],
                     },
+                    translations: [
+                        {
+                            languageCode: LanguageCode.en,
+                            name: 'With Min Price Checker',
+                            description: 'Order total must be more than 2k',
+                        },
+                    ],
                 },
             });
             await adminClient.query<
@@ -219,13 +234,18 @@ describe('PaymentMethod resolver', () => {
             >(CREATE_PAYMENT_METHOD, {
                 input: {
                     code: 'disabled-method',
-                    name: 'Disabled ones',
-                    description: 'This method is disabled',
                     enabled: false,
                     handler: {
                         code: dummyPaymentHandler.code,
                         arguments: [{ name: 'automaticSettle', value: 'true' }],
                     },
+                    translations: [
+                        {
+                            languageCode: LanguageCode.en,
+                            name: 'Disabled ones',
+                            description: 'This method is disabled',
+                        },
+                    ],
                 },
             });
 
@@ -325,13 +345,18 @@ describe('PaymentMethod resolver', () => {
             >(CREATE_PAYMENT_METHOD, {
                 input: {
                     code: 'channel-2-method',
-                    name: 'Channel 2 method',
-                    description: 'This is a test payment method',
                     enabled: true,
                     handler: {
                         code: dummyPaymentHandler.code,
                         arguments: [{ name: 'automaticSettle', value: 'true' }],
                     },
+                    translations: [
+                        {
+                            languageCode: LanguageCode.en,
+                            name: 'Channel 2 method',
+                            description: 'This is a test payment method',
+                        },
+                    ],
                 },
             });
 
@@ -407,13 +432,18 @@ describe('PaymentMethod resolver', () => {
             >(CREATE_PAYMENT_METHOD, {
                 input: {
                     code: 'channel-2-method2',
-                    name: 'Channel 2 method 2',
-                    description: 'This is a test payment method',
                     enabled: true,
                     handler: {
                         code: dummyPaymentHandler.code,
                         arguments: [{ name: 'automaticSettle', value: 'true' }],
                     },
+                    translations: [
+                        {
+                            languageCode: LanguageCode.en,
+                            name: 'Channel 2 method 2',
+                            description: 'This is a test payment method',
+                        },
+                    ],
                 },
             });
 

+ 9 - 4
packages/core/src/api/schema/admin-api/payment-method.api.graphql

@@ -22,21 +22,26 @@ type PaymentMethodList implements PaginatedList {
 # generated by generateListOptions function
 input PaymentMethodListOptions
 
+input PaymentMethodTranslationInput {
+    id: ID
+    languageCode: LanguageCode!
+    name: String
+    description: String
+}
+
 input CreatePaymentMethodInput {
-    name: String!
     code: String!
-    description: String
     enabled: Boolean!
     checker: ConfigurableOperationInput
     handler: ConfigurableOperationInput!
+    translations: [PaymentMethodTranslationInput!]!
 }
 
 input UpdatePaymentMethodInput {
     id: ID!
-    name: String
     code: String
-    description: String
     enabled: Boolean
     checker: ConfigurableOperationInput
     handler: ConfigurableOperationInput
+    translations: [PaymentMethodTranslationInput!]
 }

+ 9 - 0
packages/core/src/api/schema/common/payment-method.type.graphql

@@ -8,5 +8,14 @@ type PaymentMethod implements Node {
     enabled: Boolean!
     checker: ConfigurableOperation
     handler: ConfigurableOperation!
+    translations: [PaymentMethodTranslation!]!
 }
 
+type PaymentMethodTranslation {
+    id: ID!
+    createdAt: DateTime!
+    updatedAt: DateTime!
+    languageCode: LanguageCode!
+    name: String!
+    description: String!
+}

+ 1 - 2
packages/core/src/data-import/providers/populator/populator.ts

@@ -315,11 +315,10 @@ export class Populator {
     private async populatePaymentMethods(ctx: RequestContext, paymentMethods: InitialData['paymentMethods']) {
         for (const method of paymentMethods) {
             await this.paymentMethodService.create(ctx, {
-                name: method.name,
                 code: normalizeString(method.name, '-'),
-                description: '',
                 enabled: true,
                 handler: method.handler,
+                translations: [{ languageCode: ctx.languageCode, name: method.name, description: '' }],
             });
         }
     }

+ 1 - 0
packages/core/src/entity/custom-entity-fields.ts

@@ -17,6 +17,7 @@ export class CustomGlobalSettingsFields {}
 export class CustomOrderFields {}
 export class CustomOrderLineFields {}
 export class CustomPaymentMethodFields {}
+export class CustomPaymentMethodFieldsTranslation {}
 export class CustomProductFields {}
 export class CustomProductFieldsTranslation {}
 export class CustomProductOptionFields {}

+ 2 - 0
packages/core/src/entity/entities.ts

@@ -28,6 +28,7 @@ import { RefundLine } from './order-line-reference/refund-line.entity';
 import { OrderLine } from './order-line/order-line.entity';
 import { OrderModification } from './order-modification/order-modification.entity';
 import { Order } from './order/order.entity';
+import { PaymentMethodTranslation } from './payment-method/payment-method-translation.entity';
 import { PaymentMethod } from './payment-method/payment-method.entity';
 import { Payment } from './payment/payment.entity';
 import { ProductOptionGroupTranslation } from './product-option-group/product-option-group-translation.entity';
@@ -105,6 +106,7 @@ export const coreEntitiesMap = {
     OrderModification,
     Payment,
     PaymentMethod,
+    PaymentMethodTranslation,
     Product,
     ProductAsset,
     ProductOption,

+ 33 - 0
packages/core/src/entity/payment-method/payment-method-translation.entity.ts

@@ -0,0 +1,33 @@
+import { LanguageCode } from '@vendure/common/lib/generated-types';
+import { DeepPartial } from '@vendure/common/lib/shared-types';
+import { Column, Entity, Index, ManyToOne } from 'typeorm';
+
+import { Translation } from '../../common/types/locale-types';
+import { HasCustomFields } from '../../config/custom-field/custom-field-types';
+import { VendureEntity } from '../base/base.entity';
+import { CustomPaymentMethodFieldsTranslation } from '../custom-entity-fields';
+
+import { PaymentMethod } from './payment-method.entity';
+
+@Entity()
+export class PaymentMethodTranslation
+    extends VendureEntity
+    implements Translation<PaymentMethod>, HasCustomFields
+{
+    constructor(input?: DeepPartial<Translation<PaymentMethod>>) {
+        super(input);
+    }
+
+    @Column('varchar') languageCode: LanguageCode;
+
+    @Column() name: string;
+
+    @Column('text', { default: '' }) description: string;
+
+    @Index()
+    @ManyToOne(type => PaymentMethod, base => base.translations, { onDelete: 'CASCADE' })
+    base: PaymentMethod;
+
+    @Column(type => CustomPaymentMethodFieldsTranslation)
+    customFields: CustomPaymentMethodFieldsTranslation;
+}

+ 11 - 5
packages/core/src/entity/payment-method/payment-method.entity.ts

@@ -1,13 +1,16 @@
-import { ConfigArg, ConfigurableOperation } from '@vendure/common/lib/generated-types';
+import { ConfigurableOperation } from '@vendure/common/lib/generated-types';
 import { DeepPartial } from '@vendure/common/lib/shared-types';
-import { Column, Entity, JoinTable, ManyToMany } from 'typeorm';
+import { Column, Entity, JoinTable, ManyToMany, OneToMany } from 'typeorm';
 
+import { LocaleString, Translatable, Translation } from '../../common/index';
 import { ChannelAware } from '../../common/types/common-types';
 import { HasCustomFields } from '../../config/custom-field/custom-field-types';
 import { VendureEntity } from '../base/base.entity';
 import { Channel } from '../channel/channel.entity';
 import { CustomPaymentMethodFields } from '../custom-entity-fields';
 
+import { PaymentMethodTranslation } from './payment-method-translation.entity';
+
 /**
  * @description
  * A PaymentMethod is created automatically according to the configured {@link PaymentMethodHandler}s defined
@@ -16,16 +19,19 @@ import { CustomPaymentMethodFields } from '../custom-entity-fields';
  * @docsCategory entities
  */
 @Entity()
-export class PaymentMethod extends VendureEntity implements ChannelAware, HasCustomFields {
+export class PaymentMethod extends VendureEntity implements Translatable, ChannelAware, HasCustomFields {
     constructor(input?: DeepPartial<PaymentMethod>) {
         super(input);
     }
 
-    @Column({ default: '' }) name: string;
+    name: LocaleString;
 
     @Column({ default: '' }) code: string;
 
-    @Column({ default: '' }) description: string;
+    description: LocaleString;
+
+    @OneToMany(type => PaymentMethodTranslation, translation => translation.base, { eager: true })
+    translations: Array<Translation<PaymentMethod>>;
 
     @Column() enabled: boolean;
 

+ 65 - 39
packages/core/src/service/services/payment-method.service.ts

@@ -15,18 +15,21 @@ import { RequestContext } from '../../api/common/request-context';
 import { RelationPaths } from '../../api/index';
 import { UserInputError } from '../../common/error/errors';
 import { ListQueryOptions } from '../../common/types/common-types';
-import { idsAreEqual } from '../../common/utils';
+import { assertFound, idsAreEqual } from '../../common/utils';
 import { ConfigService } from '../../config/config.service';
 import { PaymentMethodEligibilityChecker } from '../../config/payment/payment-method-eligibility-checker';
 import { PaymentMethodHandler } from '../../config/payment/payment-method-handler';
 import { TransactionalConnection } from '../../connection/transactional-connection';
 import { Order } from '../../entity/order/order.entity';
+import { PaymentMethodTranslation } from '../../entity/payment-method/payment-method-translation.entity';
 import { PaymentMethod } from '../../entity/payment-method/payment-method.entity';
 import { EventBus } from '../../event-bus/event-bus';
 import { PaymentMethodEvent } from '../../event-bus/events/payment-method-event';
 import { ConfigArgService } from '../helpers/config-arg/config-arg.service';
 import { CustomFieldRelationService } from '../helpers/custom-field-relation/custom-field-relation.service';
 import { ListQueryBuilder } from '../helpers/list-query-builder/list-query-builder';
+import { TranslatableSaver } from '../helpers/translatable-saver/translatable-saver';
+import { TranslatorService } from '../helpers/translator/translator.service';
 import { patchEntity } from '../helpers/utils/patch-entity';
 
 import { ChannelService } from './channel.service';
@@ -47,6 +50,8 @@ export class PaymentMethodService {
         private configArgService: ConfigArgService,
         private channelService: ChannelService,
         private customFieldRelationService: CustomFieldRelationService,
+        private translatableSaver: TranslatableSaver,
+        private translator: TranslatorService,
     ) {}
 
     findAll(
@@ -57,10 +62,13 @@ export class PaymentMethodService {
         return this.listQueryBuilder
             .build(PaymentMethod, options, { ctx, relations, channelId: ctx.channelId })
             .getManyAndCount()
-            .then(([items, totalItems]) => ({
-                items,
-                totalItems,
-            }));
+            .then(([methods, totalItems]) => {
+                const items = methods.map(m => this.translator.translate(m, ctx));
+                return {
+                    items,
+                    totalItems,
+                };
+            });
     }
 
     findOne(
@@ -68,44 +76,60 @@ export class PaymentMethodService {
         paymentMethodId: ID,
         relations: RelationPaths<PaymentMethod> = [],
     ): Promise<PaymentMethod | undefined> {
-        return this.connection.findOneInChannel(ctx, PaymentMethod, paymentMethodId, ctx.channelId, {
-            relations,
-        });
+        return this.connection
+            .findOneInChannel(ctx, PaymentMethod, paymentMethodId, ctx.channelId, {
+                relations,
+            })
+            .then(paymentMethod => {
+                if (paymentMethod) {
+                    return this.translator.translate(paymentMethod, ctx);
+                }
+            });
     }
 
     async create(ctx: RequestContext, input: CreatePaymentMethodInput): Promise<PaymentMethod> {
-        const paymentMethod = new PaymentMethod(input);
-        paymentMethod.handler = this.configArgService.parseInput('PaymentMethodHandler', input.handler);
-        if (input.checker) {
-            paymentMethod.checker = this.configArgService.parseInput(
-                'PaymentMethodEligibilityChecker',
-                input.checker,
-            );
-        }
-        await this.channelService.assignToCurrentChannel(paymentMethod, ctx);
-        const savedPaymentMethod = await this.connection
-            .getRepository(ctx, PaymentMethod)
-            .save(paymentMethod);
+        const savedPaymentMethod = await this.translatableSaver.create({
+            ctx,
+            input,
+            entityType: PaymentMethod,
+            translationType: PaymentMethodTranslation,
+            beforeSave: async pm => {
+                pm.handler = this.configArgService.parseInput('PaymentMethodHandler', input.handler);
+                if (input.checker) {
+                    pm.checker = this.configArgService.parseInput(
+                        'PaymentMethodEligibilityChecker',
+                        input.checker,
+                    );
+                }
+                await this.channelService.assignToCurrentChannel(pm, ctx);
+            },
+        });
         await this.customFieldRelationService.updateRelations(ctx, PaymentMethod, input, savedPaymentMethod);
         this.eventBus.publish(new PaymentMethodEvent(ctx, savedPaymentMethod, 'created', input));
-        return savedPaymentMethod;
+        return assertFound(this.findOne(ctx, savedPaymentMethod.id));
     }
 
     async update(ctx: RequestContext, input: UpdatePaymentMethodInput): Promise<PaymentMethod> {
-        const paymentMethod = await this.connection.getEntityOrThrow(ctx, PaymentMethod, input.id);
-        const updatedPaymentMethod = patchEntity(paymentMethod, omit(input, ['handler', 'checker']));
-        if (input.checker) {
-            paymentMethod.checker = this.configArgService.parseInput(
-                'PaymentMethodEligibilityChecker',
-                input.checker,
-            );
-        }
-        if (input.checker === null) {
-            paymentMethod.checker = null;
-        }
-        if (input.handler) {
-            paymentMethod.handler = this.configArgService.parseInput('PaymentMethodHandler', input.handler);
-        }
+        const updatedPaymentMethod = await this.translatableSaver.update({
+            ctx,
+            input,
+            entityType: PaymentMethod,
+            translationType: PaymentMethodTranslation,
+            beforeSave: async pm => {
+                if (input.checker) {
+                    pm.checker = this.configArgService.parseInput(
+                        'PaymentMethodEligibilityChecker',
+                        input.checker,
+                    );
+                }
+                if (input.checker === null) {
+                    pm.checker = null;
+                }
+                if (input.handler) {
+                    pm.handler = this.configArgService.parseInput('PaymentMethodHandler', input.handler);
+                }
+            },
+        });
         await this.customFieldRelationService.updateRelations(
             ctx,
             PaymentMethod,
@@ -113,7 +137,8 @@ export class PaymentMethodService {
             updatedPaymentMethod,
         );
         this.eventBus.publish(new PaymentMethodEvent(ctx, updatedPaymentMethod, 'updated', input));
-        return this.connection.getRepository(ctx, PaymentMethod).save(updatedPaymentMethod);
+        await this.connection.getRepository(ctx, PaymentMethod).save(updatedPaymentMethod, { reload: false });
+        return assertFound(this.findOne(ctx, updatedPaymentMethod.id));
     }
 
     async delete(
@@ -178,9 +203,9 @@ export class PaymentMethodService {
             .getRepository(ctx, PaymentMethod)
             .find({ where: { enabled: true }, relations: ['channels'] });
         const results: PaymentMethodQuote[] = [];
-        const paymentMethodsInChannel = paymentMethods.filter(p =>
-            p.channels.find(pc => idsAreEqual(pc.id, ctx.channelId)),
-        );
+        const paymentMethodsInChannel = paymentMethods
+            .filter(p => p.channels.find(pc => idsAreEqual(pc.id, ctx.channelId)))
+            .map(p => this.translator.translate(p, ctx));
         for (const method of paymentMethodsInChannel) {
             let isEligible = true;
             let eligibilityMessage: string | undefined;
@@ -195,6 +220,7 @@ export class PaymentMethodService {
                     eligibilityMessage = typeof eligible === 'string' ? eligible : undefined;
                 }
             }
+
             results.push({
                 id: method.id,
                 code: method.code,

+ 5 - 4
packages/dev-server/dev-config.ts

@@ -15,6 +15,7 @@ import { defaultEmailHandlers, EmailPlugin } from '@vendure/email-plugin';
 import { BullMQJobQueuePlugin } from '@vendure/job-queue-plugin/package/bullmq';
 import path from 'path';
 import { ConnectionOptions } from 'typeorm';
+
 import { MultivendorPlugin } from './test-plugins/multivendor-plugin/multivendor.plugin';
 
 /**
@@ -88,10 +89,10 @@ export const devConfig: VendureConfig = {
                 changeEmailAddressUrl: 'http://localhost:4201/change-email-address',
             },
         }),
-        // AdminUiPlugin.init({
-        //     route: 'admin',
-        //     port: 5001,
-        // }),
+        AdminUiPlugin.init({
+            route: 'admin',
+            port: 5001,
+        }),
     ],
 };
 

+ 20 - 4
packages/elasticsearch-plugin/e2e/graphql/generated-e2e-elasticsearch-plugin-types.ts

@@ -731,10 +731,9 @@ export type CreatePaymentMethodInput = {
     checker?: InputMaybe<ConfigurableOperationInput>;
     code: Scalars['String'];
     customFields?: InputMaybe<Scalars['JSON']>;
-    description?: InputMaybe<Scalars['String']>;
     enabled: Scalars['Boolean'];
     handler: ConfigurableOperationInput;
-    name: Scalars['String'];
+    translations: Array<PaymentMethodTranslationInput>;
 };
 
 export type CreateProductInput = {
@@ -3622,6 +3621,7 @@ export type PaymentMethod = Node & {
     handler: ConfigurableOperation;
     id: Scalars['ID'];
     name: Scalars['String'];
+    translations: Array<PaymentMethodTranslation>;
     updatedAt: Scalars['DateTime'];
 };
 
@@ -3681,6 +3681,23 @@ export type PaymentMethodSortParameter = {
     updatedAt?: InputMaybe<SortOrder>;
 };
 
+export type PaymentMethodTranslation = {
+    createdAt: Scalars['DateTime'];
+    description: Scalars['String'];
+    id: Scalars['ID'];
+    languageCode: LanguageCode;
+    name: Scalars['String'];
+    updatedAt: Scalars['DateTime'];
+};
+
+export type PaymentMethodTranslationInput = {
+    customFields?: InputMaybe<Scalars['JSON']>;
+    description?: InputMaybe<Scalars['String']>;
+    id?: InputMaybe<Scalars['ID']>;
+    languageCode: LanguageCode;
+    name?: InputMaybe<Scalars['String']>;
+};
+
 /** Returned if an attempting to refund a Payment against OrderLines from a different Order */
 export type PaymentOrderMismatchError = ErrorResult & {
     errorCode: ErrorCode;
@@ -5437,11 +5454,10 @@ export type UpdatePaymentMethodInput = {
     checker?: InputMaybe<ConfigurableOperationInput>;
     code?: InputMaybe<Scalars['String']>;
     customFields?: InputMaybe<Scalars['JSON']>;
-    description?: InputMaybe<Scalars['String']>;
     enabled?: InputMaybe<Scalars['Boolean']>;
     handler?: InputMaybe<ConfigurableOperationInput>;
     id: Scalars['ID'];
-    name?: InputMaybe<Scalars['String']>;
+    translations?: InputMaybe<Array<PaymentMethodTranslationInput>>;
 };
 
 export type UpdateProductInput = {

+ 20 - 4
packages/payments-plugin/e2e/graphql/generated-admin-types.ts

@@ -731,10 +731,9 @@ export type CreatePaymentMethodInput = {
     checker?: InputMaybe<ConfigurableOperationInput>;
     code: Scalars['String'];
     customFields?: InputMaybe<Scalars['JSON']>;
-    description?: InputMaybe<Scalars['String']>;
     enabled: Scalars['Boolean'];
     handler: ConfigurableOperationInput;
-    name: Scalars['String'];
+    translations: Array<PaymentMethodTranslationInput>;
 };
 
 export type CreateProductInput = {
@@ -3622,6 +3621,7 @@ export type PaymentMethod = Node & {
     handler: ConfigurableOperation;
     id: Scalars['ID'];
     name: Scalars['String'];
+    translations: Array<PaymentMethodTranslation>;
     updatedAt: Scalars['DateTime'];
 };
 
@@ -3681,6 +3681,23 @@ export type PaymentMethodSortParameter = {
     updatedAt?: InputMaybe<SortOrder>;
 };
 
+export type PaymentMethodTranslation = {
+    createdAt: Scalars['DateTime'];
+    description: Scalars['String'];
+    id: Scalars['ID'];
+    languageCode: LanguageCode;
+    name: Scalars['String'];
+    updatedAt: Scalars['DateTime'];
+};
+
+export type PaymentMethodTranslationInput = {
+    customFields?: InputMaybe<Scalars['JSON']>;
+    description?: InputMaybe<Scalars['String']>;
+    id?: InputMaybe<Scalars['ID']>;
+    languageCode: LanguageCode;
+    name?: InputMaybe<Scalars['String']>;
+};
+
 /** Returned if an attempting to refund a Payment against OrderLines from a different Order */
 export type PaymentOrderMismatchError = ErrorResult & {
     errorCode: ErrorCode;
@@ -5437,11 +5454,10 @@ export type UpdatePaymentMethodInput = {
     checker?: InputMaybe<ConfigurableOperationInput>;
     code?: InputMaybe<Scalars['String']>;
     customFields?: InputMaybe<Scalars['JSON']>;
-    description?: InputMaybe<Scalars['String']>;
     enabled?: InputMaybe<Scalars['Boolean']>;
     handler?: InputMaybe<ConfigurableOperationInput>;
     id: Scalars['ID'];
-    name?: InputMaybe<Scalars['String']>;
+    translations?: InputMaybe<Array<PaymentMethodTranslationInput>>;
 };
 
 export type UpdateProductInput = {

+ 10 - 0
packages/payments-plugin/e2e/graphql/generated-shop-types.ts

@@ -2168,6 +2168,7 @@ export type PaymentMethod = Node & {
     handler: ConfigurableOperation;
     id: Scalars['ID'];
     name: Scalars['String'];
+    translations: Array<PaymentMethodTranslation>;
     updatedAt: Scalars['DateTime'];
 };
 
@@ -2181,6 +2182,15 @@ export type PaymentMethodQuote = {
     name: Scalars['String'];
 };
 
+export type PaymentMethodTranslation = {
+    createdAt: Scalars['DateTime'];
+    description: Scalars['String'];
+    id: Scalars['ID'];
+    languageCode: LanguageCode;
+    name: Scalars['String'];
+    updatedAt: Scalars['DateTime'];
+};
+
 /**
  * @description
  * Permissions for administrators and customers. Used to control access to

+ 11 - 0
packages/payments-plugin/src/mollie/graphql/generated-shop-types.ts

@@ -2296,6 +2296,7 @@ export type PaymentMethod = Node & {
     handler: ConfigurableOperation;
     id: Scalars['ID'];
     name: Scalars['String'];
+    translations: Array<PaymentMethodTranslation>;
     updatedAt: Scalars['DateTime'];
 };
 
@@ -2310,6 +2311,16 @@ export type PaymentMethodQuote = {
     name: Scalars['String'];
 };
 
+export type PaymentMethodTranslation = {
+    __typename?: 'PaymentMethodTranslation';
+    createdAt: Scalars['DateTime'];
+    description: Scalars['String'];
+    id: Scalars['ID'];
+    languageCode: LanguageCode;
+    name: Scalars['String'];
+    updatedAt: Scalars['DateTime'];
+};
+
 /**
  * @description
  * Permissions for administrators and customers. Used to control access to

Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
schema-admin.json


Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
schema-shop.json


Някои файлове не бяха показани, защото твърде много файлове са промени