Skip to content

Commit

Permalink
feat(core): Add maximum coupon usage (#2331)
Browse files Browse the repository at this point in the history
Closes #2330
Co-authored-by: Karics <[email protected]>
  • Loading branch information
PKarics authored Aug 10, 2023
1 parent e197bc1 commit bdd2720
Show file tree
Hide file tree
Showing 23 changed files with 299 additions and 17 deletions.
25 changes: 15 additions & 10 deletions packages/admin-ui/src/lib/core/src/common/generated-types.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const PROMOTION_FRAGMENT = gql`
enabled
couponCode
perCustomerUsageLimit
usageLimit
startsAt
endsAt
conditions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class PromotionDataService {
'startsAt',
'endsAt',
'perCustomerUsageLimit',
'usageLimit',
'enabled',
'translations',
'customFields',
Expand All @@ -50,6 +51,7 @@ export class PromotionDataService {
'startsAt',
'endsAt',
'perCustomerUsageLimit',
'usageLimit',
'enabled',
'translations',
'customFields',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
</vdr-form-field>
<vdr-form-field
[label]="'marketing.per-customer-limit' | translate"
[tooltip]="'marketing.per-customer-limit-tooltip' | translate"
for="perCustomerUsageLimit"
>
<input
Expand All @@ -92,6 +93,20 @@
formControlName="perCustomerUsageLimit"
/>
</vdr-form-field>
<vdr-form-field
[label]="'marketing.usage-limit' | translate"
[tooltip]="'marketing.usage-limit-tooltip' | translate"
for="usageLimit"
>
<input
id="usageLimit"
[readonly]="!('UpdatePromotion' | hasPermission)"
type="number"
min="1"
max="9999999"
formControlName="usageLimit"
/>
</vdr-form-field>
</div>
</vdr-card>
<vdr-card
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class PromotionDetailComponent
enabled: true,
couponCode: null as string | null,
perCustomerUsageLimit: null as number | null,
usageLimit: null as number | null,
startsAt: null,
endsAt: null,
conditions: this.formBuilder.array([]),
Expand Down Expand Up @@ -152,6 +153,7 @@ export class PromotionDetailComponent
description: '',
couponCode: null,
perCustomerUsageLimit: null,
usageLimit: null,
enabled: false,
conditions: [],
actions: [],
Expand Down Expand Up @@ -256,6 +258,7 @@ export class PromotionDetailComponent
enabled: entity.enabled,
couponCode: entity.couponCode,
perCustomerUsageLimit: entity.perCustomerUsageLimit,
usageLimit: entity.usageLimit,
startsAt: entity.startsAt,
endsAt: entity.endsAt,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,14 @@
{{ promotion.perCustomerUsageLimit }}
</ng-template>
</vdr-dt2-column>
<vdr-dt2-column
[heading]="'marketing.per-customer-limit' | translate"
[sort]="sorts.get('usageLimit')"
[hiddenByDefault]="true"
>
<ng-template let-promotion="item">
{{ promotion.usageLimit }}
</ng-template>
</vdr-dt2-column>
<vdr-dt2-custom-field-column *ngFor="let customField of customFields" [customField]="customField" [sorts]="sorts" />
</vdr-data-table-2>
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ export class PromotionListComponent
filterField: 'description',
},
{
name: 'usageLimit',
name: 'perCustomerUsageLimit',
type: { kind: 'number' },
label: _('marketing.per-customer-limit'),
filterField: 'perCustomerUsageLimit',
},
{
name: 'usageLimit',
type: { kind: 'number' },
label: _('marketing.usage-limit'),
filterField: 'usageLimit',
},
])
.addCustomFieldFilters(this.customFields)
.connectToRoute(this.route);
Expand All @@ -92,6 +98,7 @@ export class PromotionListComponent
{ name: 'name' },
{ name: 'couponCode' },
{ name: 'perCustomerUsageLimit' },
{ name: 'usageLimit' },
])
.addCustomFieldSorts(this.customFields)
.connectToRoute(this.route);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ export type CreatePromotionInput = {
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations: Array<PromotionTranslationInput>;
usageLimit?: InputMaybe<Scalars['Int']>;
};

export type CreatePromotionResult = MissingConditionsError | Promotion;
Expand Down Expand Up @@ -4591,6 +4592,7 @@ export type Promotion = Node & {
startsAt?: Maybe<Scalars['DateTime']>;
translations: Array<PromotionTranslation>;
updatedAt: Scalars['DateTime'];
usageLimit?: Maybe<Scalars['Int']>;
};

export type PromotionFilterParameter = {
Expand All @@ -4604,6 +4606,7 @@ export type PromotionFilterParameter = {
perCustomerUsageLimit?: InputMaybe<NumberOperators>;
startsAt?: InputMaybe<DateOperators>;
updatedAt?: InputMaybe<DateOperators>;
usageLimit?: InputMaybe<NumberOperators>;
};

export type PromotionList = PaginatedList & {
Expand Down Expand Up @@ -4634,6 +4637,7 @@ export type PromotionSortParameter = {
perCustomerUsageLimit?: InputMaybe<SortOrder>;
startsAt?: InputMaybe<SortOrder>;
updatedAt?: InputMaybe<SortOrder>;
usageLimit?: InputMaybe<SortOrder>;
};

export type PromotionTranslation = {
Expand Down Expand Up @@ -6114,6 +6118,7 @@ export type UpdatePromotionInput = {
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations?: InputMaybe<Array<PromotionTranslationInput>>;
usageLimit?: InputMaybe<Scalars['Int']>;
};

export type UpdatePromotionResult = MissingConditionsError | Promotion;
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2740,6 +2740,7 @@ export type Promotion = Node & {
startsAt?: Maybe<Scalars['DateTime']>;
translations: Array<PromotionTranslation>;
updatedAt: Scalars['DateTime'];
usageLimit?: Maybe<Scalars['Int']>;
};

export type PromotionList = PaginatedList & {
Expand Down
5 changes: 5 additions & 0 deletions packages/common/src/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ export type CreatePromotionInput = {
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations: Array<PromotionTranslationInput>;
usageLimit?: InputMaybe<Scalars['Int']>;
};

export type CreatePromotionResult = MissingConditionsError | Promotion;
Expand Down Expand Up @@ -4713,6 +4714,7 @@ export type Promotion = Node & {
startsAt?: Maybe<Scalars['DateTime']>;
translations: Array<PromotionTranslation>;
updatedAt: Scalars['DateTime'];
usageLimit?: Maybe<Scalars['Int']>;
};

export type PromotionFilterParameter = {
Expand All @@ -4726,6 +4728,7 @@ export type PromotionFilterParameter = {
perCustomerUsageLimit?: InputMaybe<NumberOperators>;
startsAt?: InputMaybe<DateOperators>;
updatedAt?: InputMaybe<DateOperators>;
usageLimit?: InputMaybe<NumberOperators>;
};

export type PromotionList = PaginatedList & {
Expand Down Expand Up @@ -4757,6 +4760,7 @@ export type PromotionSortParameter = {
perCustomerUsageLimit?: InputMaybe<SortOrder>;
startsAt?: InputMaybe<SortOrder>;
updatedAt?: InputMaybe<SortOrder>;
usageLimit?: InputMaybe<SortOrder>;
};

export type PromotionTranslation = {
Expand Down Expand Up @@ -6287,6 +6291,7 @@ export type UpdatePromotionInput = {
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations?: InputMaybe<Array<PromotionTranslationInput>>;
usageLimit?: InputMaybe<Scalars['Int']>;
};

export type UpdatePromotionResult = MissingConditionsError | Promotion;
Expand Down
5 changes: 5 additions & 0 deletions packages/core/e2e/graphql/generated-e2e-admin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ export type CreatePromotionInput = {
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations: Array<PromotionTranslationInput>;
usageLimit?: InputMaybe<Scalars['Int']>;
};

export type CreatePromotionResult = MissingConditionsError | Promotion;
Expand Down Expand Up @@ -4591,6 +4592,7 @@ export type Promotion = Node & {
startsAt?: Maybe<Scalars['DateTime']>;
translations: Array<PromotionTranslation>;
updatedAt: Scalars['DateTime'];
usageLimit?: Maybe<Scalars['Int']>;
};

export type PromotionFilterParameter = {
Expand All @@ -4604,6 +4606,7 @@ export type PromotionFilterParameter = {
perCustomerUsageLimit?: InputMaybe<NumberOperators>;
startsAt?: InputMaybe<DateOperators>;
updatedAt?: InputMaybe<DateOperators>;
usageLimit?: InputMaybe<NumberOperators>;
};

export type PromotionList = PaginatedList & {
Expand Down Expand Up @@ -4634,6 +4637,7 @@ export type PromotionSortParameter = {
perCustomerUsageLimit?: InputMaybe<SortOrder>;
startsAt?: InputMaybe<SortOrder>;
updatedAt?: InputMaybe<SortOrder>;
usageLimit?: InputMaybe<SortOrder>;
};

export type PromotionTranslation = {
Expand Down Expand Up @@ -6114,6 +6118,7 @@ export type UpdatePromotionInput = {
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations?: InputMaybe<Array<PromotionTranslationInput>>;
usageLimit?: InputMaybe<Scalars['Int']>;
};

export type UpdatePromotionResult = MissingConditionsError | Promotion;
Expand Down
1 change: 1 addition & 0 deletions packages/core/e2e/graphql/generated-e2e-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2649,6 +2649,7 @@ export type Promotion = Node & {
startsAt?: Maybe<Scalars['DateTime']>;
translations: Array<PromotionTranslation>;
updatedAt: Scalars['DateTime'];
usageLimit?: Maybe<Scalars['Int']>;
};

export type PromotionList = PaginatedList & {
Expand Down
Loading

0 comments on commit bdd2720

Please sign in to comment.