Skip to content

Commit

Permalink
feat(admin-ui): Allow OrderAddress custom fields to be modified
Browse files Browse the repository at this point in the history
Relates to #979
  • Loading branch information
michaelbromley committed Aug 19, 2021
1 parent c622f1f commit 175e61a
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ModalService,
ModifyOrderInput,
NotificationService,
OrderAddressFragment,
OrderDetail,
ProductSelectorSearch,
ServerConfigService,
Expand Down Expand Up @@ -137,6 +138,7 @@ export class OrderEditorComponent
countryCode: new FormControl(order.shippingAddress?.countryCode),
phoneNumber: new FormControl(order.shippingAddress?.phoneNumber),
});
this.addAddressCustomFieldsFormGroup(this.shippingAddressForm, order.shippingAddress);
}
if (!this.billingAddressForm) {
this.billingAddressForm = new FormGroup({
Expand All @@ -150,6 +152,7 @@ export class OrderEditorComponent
countryCode: new FormControl(order.billingAddress?.countryCode),
phoneNumber: new FormControl(order.billingAddress?.phoneNumber),
});
this.addAddressCustomFieldsFormGroup(this.billingAddressForm, order.billingAddress);
}
this.orderLineCustomFieldsFormArray = new FormArray([]);
for (const line of order.lines) {
Expand Down Expand Up @@ -430,6 +433,21 @@ export class OrderEditorComponent
});
}

private addAddressCustomFieldsFormGroup(
parentFormGroup: FormGroup,
address?: OrderAddressFragment | null,
) {
if (address && this.addressCustomFields.length) {
const addressCustomFieldsFormGroup = new FormGroup({});
for (const customFieldDef of this.addressCustomFields) {
const name = customFieldDef.name;
const value = (address as any).customFields?.[name];
addressCustomFieldsFormGroup.addControl(name, new FormControl(value));
}
parentFormGroup.addControl('customFields', addressCustomFieldsFormGroup);
}
}

protected setFormValues(entity: OrderDetail.Fragment, languageCode: LanguageCode): void {
/* not used */
}
Expand Down

0 comments on commit 175e61a

Please sign in to comment.