mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
#4236 Kulturpass - Artikel ohne Preisbindung erhalten günstigeren Preis
(cherry picked from commit 1d865c47d7)
This commit is contained in:
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
||||
import { ComponentStore, OnStoreInit, tapResponse } from '@ngrx/component-store';
|
||||
import { AddToShoppingCartDTO, AvailabilityDTO, BranchDTO, CheckoutDTO, ShoppingCartDTO, ShoppingCartItemDTO } from '@swagger/checkout';
|
||||
import { DomainCheckoutService } from '@domain/checkout';
|
||||
import { mergeMap, switchMap, tap, withLatestFrom } from 'rxjs/operators';
|
||||
import { catchError, mergeMap, switchMap, tap, withLatestFrom } from 'rxjs/operators';
|
||||
import {
|
||||
BranchService,
|
||||
DisplayOrderDTO,
|
||||
@@ -12,12 +12,13 @@ import {
|
||||
ResponseArgsOfIEnumerableOfBranchDTO,
|
||||
ResponseArgsOfValueTupleOfIEnumerableOfDisplayOrderDTOAndIEnumerableOfKeyValueDTOOfStringAndString,
|
||||
} from '@swagger/oms';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Observable, of, zip } from 'rxjs';
|
||||
import { AuthService } from '@core/auth';
|
||||
import { UiModalService } from '@ui/modal';
|
||||
import { getCatalogProductNumber } from './catalog-product-number';
|
||||
import { ItemDTO } from '@swagger/cat';
|
||||
import { DomainAvailabilityService } from '@domain/availability';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
|
||||
export interface KulturpassOrderModalState {
|
||||
orderItemListItem?: OrderItemListItemDTO;
|
||||
@@ -200,9 +201,18 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
|
||||
addItemToShoppingCart = this.effect((item$: Observable<ItemDTO>) =>
|
||||
item$.pipe(
|
||||
mergeMap((item) =>
|
||||
this._availabilityService
|
||||
.getTakeAwayAvailability({
|
||||
mergeMap((item) => {
|
||||
const takeAwayAvailability$ = this._availabilityService.getTakeAwayAvailability({
|
||||
item: {
|
||||
ean: item.product.ean,
|
||||
itemId: item.id,
|
||||
price: item.catalogAvailability.price,
|
||||
},
|
||||
quantity: this.itemQuantityByCatalogProductNumber(getCatalogProductNumber(item)) + 1,
|
||||
});
|
||||
|
||||
const deliveryAvailability$ = this._availabilityService
|
||||
.getDeliveryAvailability({
|
||||
item: {
|
||||
ean: item.product.ean,
|
||||
itemId: item.id,
|
||||
@@ -210,12 +220,45 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
},
|
||||
quantity: this.itemQuantityByCatalogProductNumber(getCatalogProductNumber(item)) + 1,
|
||||
})
|
||||
.pipe(tapResponse(this.handleAddItemToShoppingCartResponse(item), this.handleAddItemToShoppingCartError))
|
||||
)
|
||||
.pipe(
|
||||
catchError((err) => {
|
||||
return of(undefined);
|
||||
})
|
||||
);
|
||||
|
||||
return zip(takeAwayAvailability$, deliveryAvailability$).pipe(
|
||||
tapResponse(this.handleAddItemToShoppingCartResponse2(item), this.handleAddItemToShoppingCartError)
|
||||
);
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
handleAddItemToShoppingCartResponse = (item: ItemDTO) => (availability: AvailabilityDTO) => {
|
||||
handleAddItemToShoppingCartResponse2 = (item: ItemDTO) => ([takeAwayAvailability, deliveryAvailability]: [
|
||||
AvailabilityDTO,
|
||||
AvailabilityDTO
|
||||
]) => {
|
||||
const isPriceMaintained = deliveryAvailability['priceMaintained'] ?? false;
|
||||
const offlinePrice = takeAwayAvailability.price?.value?.value ?? -1;
|
||||
const onlinePrice = deliveryAvailability?.price?.value?.value ?? -1;
|
||||
|
||||
const availability = takeAwayAvailability;
|
||||
|
||||
/**
|
||||
* Onlinepreis ist niedliger als der Offlinepreis
|
||||
* wenn der Artikel nicht Preisgebunden ist, wird der Onlinepreis genommen
|
||||
* wenn der Artikel Preisgebunden ist, wird der Ladenpreis verwendet
|
||||
*/
|
||||
|
||||
/**
|
||||
* Offlinepreis ist niedliger als der Onlinepreis
|
||||
* wenn der Artikel nicht Preisgebunden ist, wird der Ladenpreis genommen
|
||||
* wenn der Artikel Preisgebunden ist, wird der Ladenpreis verwendet
|
||||
*/
|
||||
|
||||
if (onlinePrice < offlinePrice && !isPriceMaintained) {
|
||||
availability.price = deliveryAvailability.price;
|
||||
}
|
||||
|
||||
this.setAvailability({
|
||||
catalogProductNumber: getCatalogProductNumber(item),
|
||||
availability: availability,
|
||||
@@ -240,6 +283,31 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
this.addItem(addToShoppingCartDTO);
|
||||
};
|
||||
|
||||
// handleAddItemToShoppingCartResponse = (item: ItemDTO) => (availability: AvailabilityDTO) => {
|
||||
// this.setAvailability({
|
||||
// catalogProductNumber: getCatalogProductNumber(item),
|
||||
// availability: availability,
|
||||
// });
|
||||
|
||||
// const addToShoppingCartDTO: AddToShoppingCartDTO = {
|
||||
// quantity: 1,
|
||||
// availability: availability,
|
||||
// destination: {
|
||||
// data: {
|
||||
// target: 1,
|
||||
// targetBranch: { id: this.branch.id },
|
||||
// },
|
||||
// },
|
||||
// promotion: {
|
||||
// points: 0,
|
||||
// },
|
||||
// itemType: item.type,
|
||||
// product: { catalogProductNumber: getCatalogProductNumber(item), ...item.product },
|
||||
// };
|
||||
|
||||
// this.addItem(addToShoppingCartDTO);
|
||||
// };
|
||||
|
||||
handleAddItemToShoppingCartError = (err: any) => {
|
||||
this._modal.error('Fehler beim Hinzufügen des Artikels', err);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user