Merged PR 946: #2244 Preiseingabe bei Archivartikeln nur noch anzeigen, wenn keine der avail...

#2244 Preiseingabe bei Archivartikeln nur noch anzeigen, wenn keine der availabilities einen Preis besitzt

Related work items: #2244
This commit is contained in:
Andreas Schickinger
2021-11-08 16:41:17 +00:00
committed by Nino Righi
parent a1dea02498
commit 49bb23805e

View File

@@ -45,7 +45,9 @@ export class PurchasingOptionsModalComponent {
readonly quantityError$ = this.purchasingOptionsModalStore.selectQuantityError;
readonly showCustomPrice$ = this.availability$.pipe(map((availability) => !availability.price?.value?.value));
readonly showCustomPrice$ = this.purchasingOptionsModalStore.selectAvailabilities.pipe(
map((availabilities) => Object.keys(availabilities)?.every((key) => !availabilities[key]?.price?.value?.value))
);
readonly customPriceInvalid$ = combineLatest([
this.showCustomPrice$,
@@ -113,12 +115,18 @@ export class PurchasingOptionsModalComponent {
map((buyer) => buyer.source)
);
price$ = combineLatest([this.availability$, this.purchasingOptionsModalStore.selectCustomPrice]).pipe(
map(([availability, customPrice]) => availability?.price?.value?.value ?? customPrice ?? 0)
price$ = combineLatest([this.purchasingOptionsModalStore.selectAvailabilities, this.purchasingOptionsModalStore.selectCustomPrice]).pipe(
map(([availabilities, customPrice]) => {
const key = Object.keys(availabilities).find((key) => !!availabilities[key]?.price?.value?.value);
return availabilities[key]?.price?.value?.value ?? customPrice ?? 0;
})
);
vat$ = combineLatest([this.availability$, this.purchasingOptionsModalStore.selectCustomVat]).pipe(
map(([availability, customVat]) => availability?.price.vat ?? customVat)
vat$ = combineLatest([this.purchasingOptionsModalStore.selectAvailabilities, this.purchasingOptionsModalStore.selectCustomVat]).pipe(
map(([availabilities, customVat]) => {
const key = Object.keys(availabilities).find((key) => !!availabilities[key]?.price?.vat?.vatType);
return availabilities[key]?.price?.vat?.vatType ?? customVat;
})
);
readonly promoPoints$ = combineLatest([this.item$, this.quantity$, this.price$]).pipe(
@@ -226,6 +234,20 @@ export class PurchasingOptionsModalComponent {
};
}
if (!newItem.availability?.price?.value?.value) {
const price = await this.price$.pipe(first()).toPromise();
const vat = await this.vat$.pipe(first()).toPromise();
newItem.availability.price = {
value: {
value: price,
currency: 'EUR',
},
vat: {
vatType: vat,
},
};
}
switch (option) {
case 'take-away':
case 'pick-up':