Skip to content

Commit 0d22b25

Browse files
fix(admin-ui): Add ProductVariantPrice custom fields ui inputs (#3327)
Co-authored-by: Michael Bromley <[email protected]>
1 parent 1bddbcc commit 0d22b25

File tree

20 files changed

+29641
-72120
lines changed

20 files changed

+29641
-72120
lines changed

package-lock.json

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/admin-ui/src/lib/catalog/src/components/product-variant-detail/product-variant-detail.component.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,26 @@
195195
[priceIncludesTax]="channelPriceIncludesTax$ | async"
196196
[taxCategoryId]="detailForm.get('taxCategoryId')!.value"
197197
/>
198+
199+
<div class="form-grid-span" *ngIf="customPriceFields.length">
200+
<div class="title-row">
201+
<span class="title">{{ 'common.custom-fields' | translate }}</span>
202+
</div>
203+
<vdr-tabbed-custom-fields
204+
entityName="ProductVariantPrice"
205+
[customFields]="customPriceFields"
206+
[customFieldsFormGroup]="price.get(['customFields'])"
207+
[readonly]="!(updatePermissions | hasPermission)"
208+
/>
209+
</div>
198210
</div>
211+
199212
<vdr-variant-price-strategy-detail
200213
[channelPriceIncludesTax]="channelPriceIncludesTax$ | async"
201214
[channelDefaultCurrencyCode]="channelDefaultCurrencyCode"
202215
[variant]="variant"
203216
/>
217+
204218
<ng-container *ngIf="unusedCurrencyCodes$ | async as unusedCurrencyCodes">
205219
<div *ngIf="unusedCurrencyCodes.length">
206220
<vdr-dropdown>

packages/admin-ui/src/lib/catalog/src/components/product-variant-detail/product-variant-detail.component.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@ vdr-product-variant-quick-jump {
2929
}
3030
}
3131
}
32+
33+
.title-row {
34+
display: flex;
35+
justify-content: space-between;
36+
align-items: center;
37+
}
38+
.title {
39+
font-size: var(--font-size-base);
40+
}

packages/admin-ui/src/lib/catalog/src/components/product-variant-detail/product-variant-detail.component.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class ProductVariantDetailComponent
7171
{
7272
public readonly updatePermissions = [Permission.UpdateCatalog, Permission.UpdateProduct];
7373
readonly customFields = this.getCustomFieldConfig('ProductVariant');
74+
readonly customPriceFields = this.getCustomFieldConfig('ProductVariantPrice');
7475
readonly customOptionFields = this.getCustomFieldConfig('ProductOption');
7576
stockLevels$: Observable<NonNullable<GetProductVariantDetailQuery['productVariant']>['stockLevels']>;
7677
detailForm = this.formBuilder.group<VariantFormValue>({
@@ -99,6 +100,7 @@ export class ProductVariantDetailComponent
99100
price: FormControl<number | null>;
100101
currencyCode: FormControl<CurrencyCode | null>;
101102
delete: FormControl<boolean | null>;
103+
customFields: FormGroup<any>; //TODO: Add type
102104
}>
103105
>([]);
104106
assetChanges: SelectedAssets = {};
@@ -181,6 +183,7 @@ export class ProductVariantDetailComponent
181183
currencyCode,
182184
price: 0,
183185
delete: false as boolean,
186+
customFields: this.formBuilder.group(getCustomFieldsDefaults(this.customPriceFields)),
184187
}),
185188
);
186189
}
@@ -246,6 +249,7 @@ export class ProductVariantDetailComponent
246249
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
247250
currencyCode: control.value.currencyCode!,
248251
delete: control.value.delete === true,
252+
customFields: control.get('customFields')?.value,
249253
}));
250254
}
251255
return this.dataService.mutate(ProductVariantUpdateMutationDocument, {
@@ -353,13 +357,16 @@ export class ProductVariantDetailComponent
353357
}
354358
this.pricesForm.clear();
355359
for (const price of variant.prices) {
356-
this.pricesForm.push(
357-
this.formBuilder.group({
358-
price: price.price,
359-
currencyCode: price.currencyCode,
360-
delete: false as boolean,
361-
}),
362-
);
360+
const priceForm = this.formBuilder.group({
361+
price: price.price,
362+
currencyCode: price.currencyCode,
363+
delete: false as boolean,
364+
customFields: this.formBuilder.group(getCustomFieldsDefaults(this.customPriceFields)),
365+
});
366+
if (this.customPriceFields.length) {
367+
this.setCustomFieldFormValues(this.customPriceFields, priceForm.get(['customFields']), price);
368+
}
369+
this.pricesForm.push(priceForm);
363370
}
364371
if (this.customFields.length) {
365372
this.setCustomFieldFormValues(

packages/admin-ui/src/lib/catalog/src/components/product-variant-detail/product-variant-detail.graphql.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { ASSET_FRAGMENT, PRODUCT_OPTION_FRAGMENT } from '@vendure/admin-ui/core';
1+
import {
2+
ASSET_FRAGMENT,
3+
PRODUCT_OPTION_FRAGMENT,
4+
PRODUCT_VARIANT_PRICE_FRAGMENT,
5+
} from '@vendure/admin-ui/core';
26
import { gql } from 'apollo-angular';
37

48
export const PRODUCT_VARIANT_DETAIL_QUERY_PRODUCT_VARIANT_FRAGMENT = gql`
@@ -12,8 +16,7 @@ export const PRODUCT_VARIANT_DETAIL_QUERY_PRODUCT_VARIANT_FRAGMENT = gql`
1216
price
1317
currencyCode
1418
prices {
15-
price
16-
currencyCode
19+
...ProductVariantPrice
1720
}
1821
priceWithTax
1922
stockOnHand
@@ -87,6 +90,7 @@ export const PRODUCT_VARIANT_DETAIL_QUERY_PRODUCT_VARIANT_FRAGMENT = gql`
8790
}
8891
}
8992
}
93+
${PRODUCT_VARIANT_PRICE_FRAGMENT}
9094
`;
9195

9296
export const PRODUCT_VARIANT_DETAIL_QUERY = gql`

packages/admin-ui/src/lib/core/src/common/generated-types.ts

Lines changed: 25 additions & 14 deletions
Large diffs are not rendered by default.

packages/admin-ui/src/lib/core/src/data/definitions/product-definitions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ export const PRODUCT_OPTION_FRAGMENT = gql`
6262
}
6363
`;
6464

65+
export const PRODUCT_VARIANT_PRICE_FRAGMENT = gql`
66+
fragment ProductVariantPrice on ProductVariantPrice {
67+
price
68+
currencyCode
69+
}
70+
`;
71+
6572
export const PRODUCT_VARIANT_FRAGMENT = gql`
6673
fragment ProductVariant on ProductVariant {
6774
id

0 commit comments

Comments
 (0)