Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ProductVariantPrice custom fields ui inputs #3263

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b78351c
feat(admin-ui): Added ProductVariantPrice custom fields ui inputs
Dec 6, 2024
0a960e6
feat(core): Added create & update input for ProductVariantPrice
Dec 6, 2024
dd00bbf
@oidt has signed the CLA in vendure-ecommerce/vendure#3264
github-actions[bot] Dec 9, 2024
f43e834
chore: Chang the current stable release to 3.x (#3264)
oidt Dec 9, 2024
41151ea
chore: Clean up changelog
michaelbromley Dec 9, 2024
0707278
chore: Fix version info in readme
michaelbromley Dec 9, 2024
7ea0710
@Winne4r has signed the CLA in vendure-ecommerce/vendure#3272
github-actions[bot] Dec 13, 2024
0c122bc
fix(core): Fix serialization of ShippingMethod
michaelbromley Dec 17, 2024
02bcdba
fix(core): Fix circular reference error in email sending job
michaelbromley Dec 17, 2024
72befaa
test: Improve port assignment in e2e tests
michaelbromley Dec 17, 2024
1f8a177
chore: Run docs search indexing on master branch
michaelbromley Dec 17, 2024
d606d7a
fix(asset-server-plugin): Correctly handle EXIF rotation on source fi…
Anddrrew Dec 17, 2024
af59b36
docs(core): Minor correction and addition (#3251)
mschipperheyn Dec 17, 2024
c965ce5
docs: Fix a couple of typos
michaelbromley Dec 17, 2024
8d3a941
chore: Publish v3.1.1
michaelbromley Dec 17, 2024
f297dc4
docs: Improve docs related to caching
michaelbromley Dec 18, 2024
94aa0c7
docs: Improve docs on some new strategies
michaelbromley Dec 18, 2024
07e74f7
docs: Update logo in docs site
michaelbromley Dec 18, 2024
69a1de0
fix(core): Include variant custom fields when duplicating a product (…
mschipperheyn Dec 18, 2024
8c6e48e
@Ankish76 has signed the CLA in vendure-ecommerce/vendure#3282
github-actions[bot] Dec 20, 2024
17c7d21
@ankitdev10 has signed the CLA in vendure-ecommerce/vendure#3288
github-actions[bot] Dec 21, 2024
7d462a0
@HerclasNido has signed the CLA in vendure-ecommerce/vendure#3298
github-actions[bot] Dec 27, 2024
0bf4186
chore: Add GPL exception for Vendure plugins (#3280)
michaelbromley Dec 30, 2024
ba3c875
refactor(payments-plugin): Use some instead of find (#3292)
twlite Dec 30, 2024
e61abe6
chore: Changed demo website (#3283)
oidt Dec 30, 2024
f362a4b
fix(common): Contract multiple sequential replacers to just one in no…
jezzzm Dec 30, 2024
95e9bcd
@xtul9 has signed the CLA in vendure-ecommerce/vendure#3309
github-actions[bot] Jan 7, 2025
cdde217
@markbmullins has signed the CLA in vendure-ecommerce/vendure#3308
github-actions[bot] Jan 9, 2025
82787cf
fix(admin-ui): Update Polish localization (#3309)
xtul9 Jan 9, 2025
b631781
fix(core): Improvements to Redis cache plugin (#3303)
jacobfrantz1 Jan 9, 2025
779ebd2
docs(elasticsearch-plugin): Changed the reference to shop-api (#3307)
oidt Jan 9, 2025
9bb155b
docs(elasticsearch-plugin): Added missing inStock field for SearchInp…
Winne4r Jan 9, 2025
4349ef8
fix(payments-plugin): Stripe plugin supports correct languageCode (#3…
HerclasNido Jan 9, 2025
889dd72
@wpplumber has signed the CLA in vendure-ecommerce/vendure#3313
github-actions[bot] Jan 10, 2025
fd6a9fd
fix(create): Specify Typesense Docker image version
dlhck Jan 14, 2025
30f5665
chore: Reinstate package-lock file
michaelbromley Jan 15, 2025
c8c0c16
docs: Update Northflank guide
michaelbromley Jan 15, 2025
cd5b722
chore: Regenerate docs
michaelbromley Jan 15, 2025
4c6773e
@putermancer has signed the CLA in vendure-ecommerce/vendure#3319
github-actions[bot] Jan 16, 2025
e22c601
@apoca has signed the CLA in vendure-ecommerce/vendure#3325
github-actions[bot] Jan 20, 2025
5aea7e4
feat(admin-ui): Added ProductVariantPrice custom fields ui inputs
Dec 6, 2024
14f1778
feat(core): Added create & update input for ProductVariantPrice
Dec 6, 2024
506e854
Merge remote-tracking branch 'origin/feat/product-variant-price-cf-ui…
Draykee Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,24 @@
[priceIncludesTax]="channelPriceIncludesTax$ | async"
[taxCategoryId]="detailForm.get('taxCategoryId')!.value"
/>

<vdr-card [title]="'common.custom-fields' | translate" *ngIf="customPriceFields.length">
<vdr-tabbed-custom-fields
entityName="ProductVariantPrice"
[customFields]="customPriceFields"
[customFieldsFormGroup]="price.get(['customFields'])"
[readonly]="!(updatePermissions | hasPermission)"
/>
{{ price.get(['customFields'])?.value | json}}
Draykee marked this conversation as resolved.
Show resolved Hide resolved
</vdr-card>
</div>

<vdr-variant-price-strategy-detail
[channelPriceIncludesTax]="channelPriceIncludesTax$ | async"
[channelDefaultCurrencyCode]="channelDefaultCurrencyCode"
[variant]="variant"
/>

<ng-container *ngIf="unusedCurrencyCodes$ | async as unusedCurrencyCodes">
<div *ngIf="unusedCurrencyCodes.length">
<vdr-dropdown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class ProductVariantDetailComponent
{
public readonly updatePermissions = [Permission.UpdateCatalog, Permission.UpdateProduct];
readonly customFields = this.getCustomFieldConfig('ProductVariant');
readonly customPriceFields = this.getCustomFieldConfig('ProductVariantPrice');
readonly customOptionFields = this.getCustomFieldConfig('ProductOption');
stockLevels$: Observable<NonNullable<GetProductVariantDetailQuery['productVariant']>['stockLevels']>;
detailForm = this.formBuilder.group<VariantFormValue>({
Expand Down Expand Up @@ -99,6 +100,7 @@ export class ProductVariantDetailComponent
price: FormControl<number | null>;
currencyCode: FormControl<CurrencyCode | null>;
delete: FormControl<boolean | null>;
customFields: FormGroup<any>; //TODO: Add type
}>
>([]);
assetChanges: SelectedAssets = {};
Expand Down Expand Up @@ -181,6 +183,7 @@ export class ProductVariantDetailComponent
currencyCode,
price: 0,
delete: false as boolean,
customFields: this.formBuilder.group(getCustomFieldsDefaults(this.customPriceFields)),
}),
);
}
Expand Down Expand Up @@ -246,6 +249,7 @@ export class ProductVariantDetailComponent
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
currencyCode: control.value.currencyCode!,
delete: control.value.delete === true,
customFields: control.get('customFields')?.value,
}));
}
return this.dataService.mutate(ProductVariantUpdateMutationDocument, {
Expand Down Expand Up @@ -356,13 +360,16 @@ export class ProductVariantDetailComponent
}
this.pricesForm.clear();
for (const price of variant.prices) {
this.pricesForm.push(
this.formBuilder.group({
price: price.price,
currencyCode: price.currencyCode,
delete: false as boolean,
}),
);
const priceForm = this.formBuilder.group({
price: price.price,
currencyCode: price.currencyCode,
delete: false as boolean,
customFields: this.formBuilder.group(getCustomFieldsDefaults(this.customPriceFields)),
});
if (this.customPriceFields.length) {
this.setCustomFieldFormValues(this.customPriceFields, priceForm.get(['customFields']), price);
}
this.pricesForm.push(priceForm);
}
if (this.customFields.length) {
this.setCustomFieldFormValues(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ASSET_FRAGMENT, PRODUCT_OPTION_FRAGMENT } from '@vendure/admin-ui/core';
import {
ASSET_FRAGMENT,
PRODUCT_OPTION_FRAGMENT,
PRODUCT_VARIANT_PRICE_FRAGMENT,
} from '@vendure/admin-ui/core';
import { gql } from 'apollo-angular';

export const PRODUCT_VARIANT_DETAIL_QUERY_PRODUCT_VARIANT_FRAGMENT = gql`
Expand All @@ -12,8 +16,7 @@ export const PRODUCT_VARIANT_DETAIL_QUERY_PRODUCT_VARIANT_FRAGMENT = gql`
price
currencyCode
prices {
price
currencyCode
...ProductVariantPrice
}
priceWithTax
stockOnHand
Expand Down Expand Up @@ -87,6 +90,7 @@ export const PRODUCT_VARIANT_DETAIL_QUERY_PRODUCT_VARIANT_FRAGMENT = gql`
}
}
}
${PRODUCT_VARIANT_PRICE_FRAGMENT}
`;

export const PRODUCT_VARIANT_DETAIL_QUERY = gql`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ export const PRODUCT_OPTION_FRAGMENT = gql`
}
`;

export const PRODUCT_VARIANT_PRICE_FRAGMENT = gql`
fragment ProductVariantPrice on ProductVariantPrice {
price
currencyCode
}
`;

export const PRODUCT_VARIANT_FRAGMENT = gql`
fragment ProductVariant on ProductVariant {
id
Expand Down
20 changes: 20 additions & 0 deletions packages/core/src/api/config/graphql-custom-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,26 @@ export function addGraphQLCustomFields(
}
}

// Only admin API needs to extend the ProductVariantPrice type
if (!publicOnly) {
// For custom fields on the ProductVariantPrice entity, we have to extend the ProductVariantPrice input type
if (customFieldConfig.ProductVariantPrice?.length) {
customFieldTypeDefs += `
input UpdateProductVariantPriceCustomFieldsInput {
${mapToFields(
customFieldConfig.ProductVariantPrice,
wrapListType(getGraphQlInputType),
getGraphQlInputName,
)}
}

extend input ProductVariantPriceInput {
customFields: UpdateProductVariantPriceCustomFieldsInput
}
`;
}
}

const publicAddressFields = customFieldConfig.Address?.filter(
config => !config.internal && (publicOnly === true ? config.public !== false : true),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
RemoveProductVariantsFromChannelInput,
UpdateProductVariantInput,
} from '@vendure/common/lib/generated-types';
import { ID, PaginatedList } from '@vendure/common/lib/shared-types';
import { CustomFieldsObject, ID, PaginatedList } from '@vendure/common/lib/shared-types';
import { unique } from '@vendure/common/lib/unique';
import { In, IsNull } from 'typeorm';

Expand Down Expand Up @@ -552,6 +552,7 @@ export class ProductVariantService {
priceInput.price,
ctx.channelId,
priceInput.currencyCode,
// TODO: Include once codegen works: priceInput.customFields
);
}
}
Expand All @@ -570,6 +571,7 @@ export class ProductVariantService {
price: number,
channelId: ID,
currencyCode?: CurrencyCode,
customFields?: CustomFieldsObject,
): Promise<ProductVariantPrice> {
const { productVariantPriceUpdateStrategy } = this.configService.catalogOptions;
const allPrices = await this.connection.getRepository(ctx, ProductVariantPrice).find({
Expand Down Expand Up @@ -598,6 +600,7 @@ export class ProductVariantService {
price,
variant: new ProductVariant({ id: productVariantId }),
currencyCode: currencyCode ?? ctx.channel.defaultCurrencyCode,
// TODO: Add custom fields
}),
);
await this.eventBus.publish(new ProductVariantPriceEvent(ctx, [createdPrice], 'created'));
Expand All @@ -611,6 +614,7 @@ export class ProductVariantService {
targetPrice.price = price;
const updatedPrice = await this.connection
.getRepository(ctx, ProductVariantPrice)
// TODO: Update custom fields
.save(targetPrice);
await this.eventBus.publish(new ProductVariantPriceEvent(ctx, [updatedPrice], 'updated'));
additionalPricesToUpdate = await productVariantPriceUpdateStrategy.onPriceUpdated(
Expand Down
Loading