Hi Oksana
I also saw that link but can't apply to POS extension yet.
Problems:
1. How to subscribe the options to extension property in view form? Option list is "ObservableArray", different from string. If in text box, will use command like this: -
this.CountryCode.subscribe((newValue: string): void => {
this._addOrUpdateExtensionProperty("COUNTRYREGIONCODEPHONE", <ProxyEntities.CommercePropertyValue>{ StringValue: newValue });
});
2. How to set value to option from extension properties? If in text box, can easily set string.
public init(state: ICustomerAddEditCustomControlState): void {
if (!state.isSelectionMode) {
this.CountryCode(this._getExtensionString("COUNTRYREGIONCODEPHONE"));
}
}
private _getExtensionString(key: string): string {
let value: string;
let customer: ProxyEntities.Customer = this.customer;
value = StringExtensions.EMPTY;
if (!ObjectExtensions.isNullOrUndefined(customer.ExtensionProperties))
{
value = this.getPropertyValue(customer.ExtensionProperties, key).StringValue;
}
return value;
}
private getPropertyValue(extensionProperties: ProxyEntities.CommerceProperty[], column: string): ProxyEntities.CommercePropertyValue {
extensionProperties = extensionProperties || [];
return extensionProperties.filter((prop: ProxyEntities.CommerceProperty) => prop.Key === column)
.map((prop: ProxyEntities.CommerceProperty) => prop.Value)[0];
}
3. How to populate options in view form? I try to put in constructor and push custom entities similar to the way to show in data list but not work yet.
public CountryCodes: ObservableArray<ClientPhoneCountryCodes.IPhoneCountryCodes>;
constructor(id: string, context: ICustomerAddEditCustomControlContext) {
super(id, context);
this._context = context;
this.CountryCodes = ko.observableArray<ClientPhoneCountryCodes.IPhoneCountryCodes>(this.getCountryCodes());
};
}
private getCountryCodes(): ClientPhoneCountryCodes.IPhoneCountryCodes[] {
let countryCodes: ClientPhoneCountryCodes.IPhoneCountryCodes[] = [];
this._context.runtime.executeAsync(new GetDeviceConfigurationClientRequest())
.then((response: ClientEntities.ICancelableDataResult<GetDeviceConfigurationClientResponse>): ProxyEntities.DeviceConfiguration => {
return response.data.result;
})
// get store hours
.then((deviceConfiguration: ProxyEntities.DeviceConfiguration)
: Promise<ClientEntities.ICancelableDataResult<PhoneCountryCodes.GetPhoneCountryCodesResponse>> => {
return this._context.runtime.executeAsync(
new PhoneCountryCodes.GetPhoneCountryCodesRequest<PhoneCountryCodes.GetPhoneCountryCodesResponse>(deviceConfiguration.StoreNumber));
}).then((response: ClientEntities.ICancelableDataResult<PhoneCountryCodes.GetPhoneCountryCodesResponse>): void => {
if (ObjectExtensions.isNullOrUndefined(response)
|| ObjectExtensions.isNullOrUndefined(response.data)
|| response.canceled) {
return;
}
response.data.result.forEach((countryCode: Entities.PhoneCountryCodes): void => {
countryCodes.push(this.convertToClientCodes(countryCode));
});
}).catch((reason: any) => {
this._context.logger.logError("CustomerAddEdit.PhoneCountryCodes: " + JSON.stringify(reason));
});
return countryCodes;
}
private convertToClientCodes(countryCodes: Entities.PhoneCountryCodes): ClientPhoneCountryCodes.IPhoneCountryCodes {
return {
id: countryCodes.Id,
countryCode: countryCodes.CountryCode,
countryRegionId: countryCodes.CountryRegionId
};
}