#1370 Kunden Checkbox verhalten

This commit is contained in:
Andreas Schickinger
2021-02-03 16:50:56 +01:00
parent db850d7f82
commit d285627878
4 changed files with 46 additions and 29 deletions

View File

@@ -65,7 +65,7 @@ export class CheckoutService {
throw new Error('Not Implemented');
}
getSetableCustomerTypes(processId: number): Observable<string[]> {
getSetableCustomerTypes(processId: number): Observable<StringDictionary<boolean>> {
throw new Error('Not Implemented');
}

View File

@@ -55,21 +55,14 @@ export abstract class CustomerCreateComponentBase {
});
this.disabledSelectOptions$ = this.checkoutService.getSetableCustomerTypes(this.application.activatedProcessId).pipe(
map((setableTypes) => {
const disabledTypes: StringDictionary<boolean> = {
webshop: false,
b2b: false,
store: false,
guest: false,
};
for (const key in disabledTypes) {
if (!setableTypes.includes(key)) {
disabledTypes[key] = true;
map((opts) => {
const result = { ...opts };
for (const key in result) {
if (Object.prototype.hasOwnProperty.call(result, key)) {
result[key] = !result[key];
}
}
return disabledTypes;
return result;
})
);
}

View File

@@ -20,11 +20,19 @@ export class CustomerCreateGuard implements CanActivateChild {
return this.checkoutService.getSetableCustomerTypes(this.application.activatedProcessId).pipe(
map((selectables) => {
const result = selectables.includes(currentRoute);
if (!result) {
this.router.navigate(['/customer/create', selectables[0]], { queryParams: route.queryParams });
if (selectables[currentRoute]) {
return true;
}
return result;
for (const key in selectables) {
if (Object.prototype.hasOwnProperty.call(selectables, key)) {
if (selectables[key]) {
this.router.navigate(['/customer/create', key], { queryParams: route.queryParams });
return false;
}
}
}
return false;
})
);
}

View File

@@ -139,25 +139,41 @@ export class CheckoutRefactImp implements CheckoutService {
);
}
getSetableCustomerTypes(processId: number) {
getSetableCustomerTypes(processId: number): Observable<StringDictionary<boolean>> {
return this.canSetCustomer(processId, undefined).pipe(
map((res) => {
let setableTypes = [];
let setableTypes: StringDictionary<boolean> = {
store: true,
guest: true,
webshop: true,
b2b: true,
};
if (Object.keys(res.filter).length === 0) {
return ['store', 'guest', 'webshop', 'b2b'];
} else {
const cusotmerType = res.filter.customertype;
if (cusotmerType) {
setableTypes = [...setableTypes, ...cusotmerType.split(';')];
}
return setableTypes;
}
let customerAttributes = res.filter.customerattributes;
if (customerAttributes) {
setableTypes = [...setableTypes, ...cusotmerType.replace('store', 'branch').split(';')];
const customerTypes = res.filter?.customertype?.split(';') || [];
const customerAttributes = res.filter?.customerattributes?.split(';') || [];
const typesAndAttributes = [...customerTypes, ...customerAttributes];
if (typesAndAttributes.includes('webshop') && !typesAndAttributes.includes('!guest')) {
typesAndAttributes.push('guest');
}
for (const key in setableTypes) {
if (Object.prototype.hasOwnProperty.call(setableTypes, key)) {
if (typesAndAttributes.includes(key)) {
setableTypes[key] = true;
} else if (typesAndAttributes.includes(`!${key}`)) {
setableTypes[key] = false;
} else {
setableTypes[key] = false;
}
}
}
console.log('setableTypes', setableTypes);
return setableTypes;
})
);