mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
chore(swagger-oms, swagger-checkout): Update Swagger and resolved breaking changes
This commit is contained in:
@@ -12,7 +12,13 @@ import {
|
||||
ShoppingCartItemDTO,
|
||||
} from '@generated/swagger/checkout-api';
|
||||
import { DomainCheckoutService } from '@domain/checkout';
|
||||
import { catchError, mergeMap, switchMap, tap, withLatestFrom } from 'rxjs/operators';
|
||||
import {
|
||||
catchError,
|
||||
mergeMap,
|
||||
switchMap,
|
||||
tap,
|
||||
withLatestFrom,
|
||||
} from 'rxjs/operators';
|
||||
import {
|
||||
BranchService,
|
||||
DisplayOrderDTO,
|
||||
@@ -40,7 +46,10 @@ export interface KulturpassOrderModalState {
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderModalState> implements OnStoreInit {
|
||||
export class KulturpassOrderModalStore
|
||||
extends ComponentStore<KulturpassOrderModalState>
|
||||
implements OnStoreInit
|
||||
{
|
||||
private _checkoutService = inject(DomainCheckoutService);
|
||||
private _branchService = inject(BranchService);
|
||||
private _authService = inject(AuthService);
|
||||
@@ -87,23 +96,33 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
|
||||
readonly order$ = this.select((state) => state.order);
|
||||
|
||||
readonly updateCheckout = this.updater((state, checkout: CheckoutDTO) => ({ ...state, checkout }));
|
||||
readonly updateCheckout = this.updater((state, checkout: CheckoutDTO) => ({
|
||||
...state,
|
||||
checkout,
|
||||
}));
|
||||
|
||||
readonly updateOrder = this.updater((state, order: OrderDTO) => ({ ...state, order }));
|
||||
readonly updateOrder = this.updater((state, order: OrderDTO) => ({
|
||||
...state,
|
||||
order,
|
||||
}));
|
||||
|
||||
readonly fetchShoppingCart$ = this.select((state) => state.fetchShoppingCart);
|
||||
|
||||
readonly updateFetchShoppingCart = this.updater((state, fetchShoppingCart: boolean) => ({
|
||||
...state,
|
||||
fetchShoppingCart,
|
||||
}));
|
||||
readonly updateFetchShoppingCart = this.updater(
|
||||
(state, fetchShoppingCart: boolean) => ({
|
||||
...state,
|
||||
fetchShoppingCart,
|
||||
}),
|
||||
);
|
||||
|
||||
readonly ordering$ = this.select((state) => state.ordering);
|
||||
|
||||
loadBranch = this.effect(($) =>
|
||||
$.pipe(
|
||||
switchMap(() =>
|
||||
this._branchService.BranchGetBranches({}).pipe(tapResponse(this.handleBranchResponse, this.handleBranchError)),
|
||||
this._branchService
|
||||
.BranchGetBranches({})
|
||||
.pipe(tapResponse(this.handleBranchResponse, this.handleBranchError)),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -111,31 +130,45 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
handleBranchResponse = (res: ResponseArgsOfIEnumerableOfBranchDTO) => {
|
||||
const branchNumber = this._authService.getClaimByKey('branch_no');
|
||||
|
||||
this.patchState({ branch: res.result.find((b) => b.branchNumber === branchNumber) });
|
||||
this.patchState({
|
||||
branch: res.result.find((b) => b.branchNumber === branchNumber),
|
||||
});
|
||||
};
|
||||
|
||||
handleBranchError = (err) => {
|
||||
this._modal.error('Fehler beim Laden der Filiale', err);
|
||||
};
|
||||
|
||||
createShoppingCart = this.effect((orderItemListItem$: Observable<OrderItemListItemDTO>) =>
|
||||
orderItemListItem$.pipe(
|
||||
tap((orderItemListItem) => {
|
||||
this.patchState({ orderItemListItem });
|
||||
this.updateFetchShoppingCart(true);
|
||||
}),
|
||||
switchMap((orderItemListItem) =>
|
||||
this._checkoutService
|
||||
.getShoppingCart({ processId: this.processId })
|
||||
.pipe(tapResponse(this.handleCreateShoppingCartResponse, this.handleCreateShoppingCartError)),
|
||||
createShoppingCart = this.effect(
|
||||
(orderItemListItem$: Observable<OrderItemListItemDTO>) =>
|
||||
orderItemListItem$.pipe(
|
||||
tap((orderItemListItem) => {
|
||||
this.patchState({ orderItemListItem });
|
||||
this.updateFetchShoppingCart(true);
|
||||
}),
|
||||
switchMap((orderItemListItem) =>
|
||||
this._checkoutService
|
||||
.getShoppingCart({ processId: this.processId })
|
||||
.pipe(
|
||||
tapResponse(
|
||||
this.handleCreateShoppingCartResponse,
|
||||
this.handleCreateShoppingCartError,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
handleCreateShoppingCartResponse = (res: ShoppingCartDTO) => {
|
||||
this.patchState({ shoppingCart: res });
|
||||
this._checkoutService.setBuyer({ processId: this.processId, buyer: this.order.buyer });
|
||||
this._checkoutService.setPayer({ processId: this.processId, payer: this.order.billing?.data });
|
||||
this._checkoutService.setBuyer({
|
||||
processId: this.processId,
|
||||
buyer: this.order.buyer,
|
||||
});
|
||||
this._checkoutService.setPayer({
|
||||
processId: this.processId,
|
||||
payer: this.order.billing?.data,
|
||||
});
|
||||
|
||||
this.updateFetchShoppingCart(false);
|
||||
};
|
||||
@@ -154,7 +187,9 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
processId: this.processId,
|
||||
items: [add],
|
||||
})
|
||||
.pipe(tapResponse(this.handleAddItemResponse, this.handleAddItemError)),
|
||||
.pipe(
|
||||
tapResponse(this.handleAddItemResponse, this.handleAddItemError),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -174,7 +209,12 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
shoppingCartItemId: change.id,
|
||||
update: { quantity: change.quantity },
|
||||
})
|
||||
.pipe(tapResponse(this.handleQuantityChangeResponse, this.handleQuantityChangeError)),
|
||||
.pipe(
|
||||
tapResponse(
|
||||
this.handleQuantityChangeResponse,
|
||||
this.handleQuantityChangeError,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -206,7 +246,10 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
this.onOrderSuccess(res.result.item1[0], res.result.item2);
|
||||
};
|
||||
|
||||
onOrderSuccess = (displayOrder: DisplayOrderDTO, action: KeyValueDTOOfStringAndString[]) => {};
|
||||
onOrderSuccess = (
|
||||
displayOrder: DisplayOrderDTO,
|
||||
action: KeyValueDTOOfStringAndString[],
|
||||
) => {};
|
||||
|
||||
handleOrderError = (err: any) => {
|
||||
this._modal.error('Fehler beim Bestellen', err);
|
||||
@@ -215,8 +258,9 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
|
||||
itemQuantityByCatalogProductNumber(catalogProductNumber: string) {
|
||||
return (
|
||||
this.shoppingCart?.items?.find((i) => getCatalogProductNumber(i?.data) === catalogProductNumber)?.data
|
||||
?.quantity ?? 0
|
||||
this.shoppingCart?.items?.find(
|
||||
(i) => getCatalogProductNumber(i?.data) === catalogProductNumber,
|
||||
)?.data?.quantity ?? 0
|
||||
);
|
||||
}
|
||||
|
||||
@@ -227,7 +271,11 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
.canAddItemsKulturpass([item?.product])
|
||||
.pipe(
|
||||
tapResponse(
|
||||
(results) => this.handleCanAddItemResponse({ item, result: results?.find((_) => true) }),
|
||||
(results) =>
|
||||
this.handleCanAddItemResponse({
|
||||
item,
|
||||
result: results?.find((_) => true),
|
||||
}),
|
||||
this.handleCanAddItemError,
|
||||
),
|
||||
),
|
||||
@@ -235,14 +283,23 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
),
|
||||
);
|
||||
|
||||
handleCanAddItemResponse = ({ item, result }: { item: ItemDTO; result: KulturPassResult }) => {
|
||||
handleCanAddItemResponse = ({
|
||||
item,
|
||||
result,
|
||||
}: {
|
||||
item: ItemDTO;
|
||||
result: KulturPassResult;
|
||||
}) => {
|
||||
if (result?.canAdd) {
|
||||
this.addItemToShoppingCart(item);
|
||||
} else {
|
||||
this._modal.open({
|
||||
content: UiMessageModalComponent,
|
||||
title: 'Artikel nicht förderfähig',
|
||||
data: { message: result?.message, closeAction: 'ohne Artikel fortfahren' },
|
||||
data: {
|
||||
message: result?.message,
|
||||
closeAction: 'ohne Artikel fortfahren',
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -254,14 +311,18 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
addItemToShoppingCart = this.effect((item$: Observable<ItemDTO>) =>
|
||||
item$.pipe(
|
||||
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 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({
|
||||
@@ -270,7 +331,10 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
itemId: item.id,
|
||||
price: item.catalogAvailability.price,
|
||||
},
|
||||
quantity: this.itemQuantityByCatalogProductNumber(getCatalogProductNumber(item)) + 1,
|
||||
quantity:
|
||||
this.itemQuantityByCatalogProductNumber(
|
||||
getCatalogProductNumber(item),
|
||||
) + 1,
|
||||
})
|
||||
.pipe(
|
||||
catchError((err) => {
|
||||
@@ -279,7 +343,10 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
);
|
||||
|
||||
return zip(takeAwayAvailability$, deliveryAvailability$).pipe(
|
||||
tapResponse(this.handleAddItemToShoppingCartResponse2(item), this.handleAddItemToShoppingCartError),
|
||||
tapResponse(
|
||||
this.handleAddItemToShoppingCartResponse2(item),
|
||||
this.handleAddItemToShoppingCartError,
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
@@ -287,20 +354,27 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
|
||||
handleAddItemToShoppingCartResponse2 =
|
||||
(item: ItemDTO) =>
|
||||
([takeAwayAvailability, deliveryAvailability]: [AvailabilityDTO, AvailabilityDTO]) => {
|
||||
([takeAwayAvailability, deliveryAvailability]: [
|
||||
AvailabilityDTO,
|
||||
AvailabilityDTO,
|
||||
]) => {
|
||||
let isPriceMaintained = item?.catalogAvailability?.priceMaintained;
|
||||
let onlinePrice = -1;
|
||||
|
||||
if (deliveryAvailability) {
|
||||
isPriceMaintained = isPriceMaintained ?? deliveryAvailability['priceMaintained'] ?? false;
|
||||
isPriceMaintained =
|
||||
isPriceMaintained ?? deliveryAvailability['priceMaintained'] ?? false;
|
||||
onlinePrice = deliveryAvailability?.price?.value?.value ?? -1;
|
||||
}
|
||||
|
||||
// Preis und priceMaintained werden immer erst vom Katalog genommen. Bei nicht Verfügbarkeit greifen die anderen Availabilities
|
||||
const offlinePrice =
|
||||
item?.catalogAvailability?.price?.value?.value ?? takeAwayAvailability?.price?.value?.value ?? -1;
|
||||
item?.catalogAvailability?.price?.value?.value ??
|
||||
takeAwayAvailability?.price?.value?.value ??
|
||||
-1;
|
||||
const availability = takeAwayAvailability;
|
||||
availability.price = item?.catalogAvailability?.price ?? takeAwayAvailability?.price;
|
||||
availability.price =
|
||||
item?.catalogAvailability?.price ?? takeAwayAvailability?.price;
|
||||
|
||||
/**
|
||||
* Onlinepreis ist niedliger als der Offlinepreis
|
||||
@@ -314,7 +388,11 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
* wenn der Artikel Preisgebunden ist, wird der Ladenpreis verwendet
|
||||
*/
|
||||
|
||||
if (!!deliveryAvailability && onlinePrice < offlinePrice && !isPriceMaintained) {
|
||||
if (
|
||||
!!deliveryAvailability &&
|
||||
onlinePrice < offlinePrice &&
|
||||
!isPriceMaintained
|
||||
) {
|
||||
availability.price = deliveryAvailability.price;
|
||||
}
|
||||
|
||||
@@ -333,10 +411,13 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
},
|
||||
},
|
||||
promotion: {
|
||||
points: 0,
|
||||
value: 0,
|
||||
},
|
||||
itemType: item.type,
|
||||
product: { catalogProductNumber: getCatalogProductNumber(item), ...item.product },
|
||||
product: {
|
||||
catalogProductNumber: getCatalogProductNumber(item),
|
||||
...item.product,
|
||||
},
|
||||
};
|
||||
|
||||
this.addItem(addToShoppingCartDTO);
|
||||
@@ -346,15 +427,28 @@ export class KulturpassOrderModalStore extends ComponentStore<KulturpassOrderMod
|
||||
this._modal.error('Fehler beim Hinzufügen des Artikels', err);
|
||||
};
|
||||
|
||||
setAvailability = this.updater((state, data: { catalogProductNumber: string; availability: AvailabilityDTO }) => {
|
||||
return { ...state, availabilities: { ...state.availabilities, [data.catalogProductNumber]: data.availability } };
|
||||
});
|
||||
setAvailability = this.updater(
|
||||
(
|
||||
state,
|
||||
data: { catalogProductNumber: string; availability: AvailabilityDTO },
|
||||
) => {
|
||||
return {
|
||||
...state,
|
||||
availabilities: {
|
||||
...state.availabilities,
|
||||
[data.catalogProductNumber]: data.availability,
|
||||
},
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
getAvailability(catalogProductNumber: string): AvailabilityDTO | undefined {
|
||||
return this.get((state) => state.availabilities[catalogProductNumber]);
|
||||
}
|
||||
|
||||
getAvailability$(catalogProductNumber: string): Observable<AvailabilityDTO | undefined> {
|
||||
getAvailability$(
|
||||
catalogProductNumber: string,
|
||||
): Observable<AvailabilityDTO | undefined> {
|
||||
return this.select((state) => state.availabilities[catalogProductNumber]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,11 @@ import {
|
||||
} from './purchase-options.helpers';
|
||||
import { Observable } from 'rxjs';
|
||||
import { first, switchMap } from 'rxjs/operators';
|
||||
import { DEFAULT_PRICE_DTO, DEFAULT_PRICE_VALUE, DEFAULT_VAT_VALUE } from '../constants';
|
||||
import {
|
||||
DEFAULT_PRICE_DTO,
|
||||
DEFAULT_PRICE_VALUE,
|
||||
DEFAULT_VAT_VALUE,
|
||||
} from '../constants';
|
||||
import {
|
||||
AddToShoppingCartDTO,
|
||||
EntityDTOContainerOfDestinationDTO,
|
||||
@@ -103,7 +107,9 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
return this.get(Selectors.getPurchaseOptionsInAvailabilities);
|
||||
}
|
||||
|
||||
getPurchaseOptionsInAvailabilities$ = this.select(Selectors.getPurchaseOptionsInAvailabilities);
|
||||
getPurchaseOptionsInAvailabilities$ = this.select(
|
||||
Selectors.getPurchaseOptionsInAvailabilities,
|
||||
);
|
||||
|
||||
get itemsForList() {
|
||||
return this.get(Selectors.getItemsForList);
|
||||
@@ -160,29 +166,48 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
});
|
||||
}
|
||||
|
||||
addFetchingAvailability = this.updater((state, fetchState: FetchingAvailability) => {
|
||||
return {
|
||||
...state,
|
||||
fetchingAvailabilities: [...state.fetchingAvailabilities, fetchState],
|
||||
};
|
||||
});
|
||||
addFetchingAvailability = this.updater(
|
||||
(state, fetchState: FetchingAvailability) => {
|
||||
return {
|
||||
...state,
|
||||
fetchingAvailabilities: [...state.fetchingAvailabilities, fetchState],
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
removeFetchingAvailability = this.updater((state, fetchState: FetchingAvailability) => {
|
||||
return {
|
||||
...state,
|
||||
fetchingAvailabilities: state.fetchingAvailabilities.filter((f) => f.id !== fetchState.id),
|
||||
};
|
||||
});
|
||||
removeFetchingAvailability = this.updater(
|
||||
(state, fetchState: FetchingAvailability) => {
|
||||
return {
|
||||
...state,
|
||||
fetchingAvailabilities: state.fetchingAvailabilities.filter(
|
||||
(f) => f.id !== fetchState.id,
|
||||
),
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
async initialize({ items, processId, type, inStoreBranch, pickupBranch }: PurchaseOptionsModalData) {
|
||||
const selectedBranch = await this._service.getSelectedBranchForProcess(processId).toPromise();
|
||||
async initialize({
|
||||
items,
|
||||
processId,
|
||||
type,
|
||||
inStoreBranch,
|
||||
pickupBranch,
|
||||
}: PurchaseOptionsModalData) {
|
||||
const selectedBranch = await this._service
|
||||
.getSelectedBranchForProcess(processId)
|
||||
.toPromise();
|
||||
const defaultBranch = await this._service.fetchDefaultBranch().toPromise();
|
||||
const customerFeatures = await this._service.getCustomerFeatures(processId).toPromise();
|
||||
const customerFeatures = await this._service
|
||||
.getCustomerFeatures(processId)
|
||||
.toPromise();
|
||||
|
||||
this.patchState({
|
||||
processId: processId,
|
||||
type: type,
|
||||
items: items.map((item) => ({ ...item, quantity: item['quantity'] ?? 1 })),
|
||||
items: items.map((item) => ({
|
||||
...item,
|
||||
quantity: item['quantity'] ?? 1,
|
||||
})),
|
||||
defaultBranch: selectedBranch ?? defaultBranch,
|
||||
pickupBranch: pickupBranch ?? selectedBranch,
|
||||
inStoreBranch: inStoreBranch ?? selectedBranch,
|
||||
@@ -255,7 +280,8 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
const items = await this._catalogService
|
||||
.searchByEans({ eans: this.items.map((item) => item.product.ean) })
|
||||
.toPromise();
|
||||
if (items.result.length > 0) await this._addCatalogueAvailabilities(items.result);
|
||||
if (items.result.length > 0)
|
||||
await this._addCatalogueAvailabilities(items.result);
|
||||
} else {
|
||||
await this._addCatalogueAvailabilities(items as ItemDTO[]);
|
||||
}
|
||||
@@ -264,7 +290,9 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
// #4813 - Function updated - "this.updater" didn't work, so "this.patchState" gets used instead
|
||||
// Added firstDayOfSale for catalogAvailability via ShoppingCart Route
|
||||
private async _addCatalogueAvailabilities(items: ItemDTO[]) {
|
||||
const currentAvailabilities = await this.availabilities$.pipe(first()).toPromise();
|
||||
const currentAvailabilities = await this.availabilities$
|
||||
.pipe(first())
|
||||
.toPromise();
|
||||
const availabilities = [...currentAvailabilities];
|
||||
items.forEach((item) => {
|
||||
const catalogAvailability = item.catalogAvailability;
|
||||
@@ -272,7 +300,10 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
purchaseOption: 'catalog',
|
||||
itemId: item.id,
|
||||
ean: item.product.ean, // Hier brauchen wir zusätzlich die EAN - siehe purchase-options-list-item.component.ts: "get isEVT()"
|
||||
data: { price: catalogAvailability?.price, firstDayOfSale: catalogAvailability?.firstDayOfSale },
|
||||
data: {
|
||||
price: catalogAvailability?.price,
|
||||
firstDayOfSale: catalogAvailability?.firstDayOfSale,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -287,8 +318,14 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
|
||||
const id = uniqueId('availability_');
|
||||
try {
|
||||
this.addFetchingAvailability({ id, itemId: itemData.sourceId, purchaseOption: 'pickup' });
|
||||
const res = await this._service.fetchPickupAvailability(itemData, itemData.quantity, branch).toPromise();
|
||||
this.addFetchingAvailability({
|
||||
id,
|
||||
itemId: itemData.sourceId,
|
||||
purchaseOption: 'pickup',
|
||||
});
|
||||
const res = await this._service
|
||||
.fetchPickupAvailability(itemData, itemData.quantity, branch)
|
||||
.toPromise();
|
||||
|
||||
const availability: Availability = {
|
||||
itemId: itemData.sourceId,
|
||||
@@ -301,7 +338,11 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
console.error('_loadPickupAvailability', err);
|
||||
}
|
||||
|
||||
this.removeFetchingAvailability({ id, itemId: itemData.sourceId, purchaseOption: 'pickup' });
|
||||
this.removeFetchingAvailability({
|
||||
id,
|
||||
itemId: itemData.sourceId,
|
||||
purchaseOption: 'pickup',
|
||||
});
|
||||
}
|
||||
|
||||
private async _loadInStoreAvailability(itemData: ItemData) {
|
||||
@@ -310,8 +351,14 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
|
||||
const id = uniqueId('availability_');
|
||||
try {
|
||||
this.addFetchingAvailability({ id, itemId: itemData.sourceId, purchaseOption: 'in-store' });
|
||||
const res = await this._service.fetchInStoreAvailability(itemData, itemData.quantity, branch).toPromise();
|
||||
this.addFetchingAvailability({
|
||||
id,
|
||||
itemId: itemData.sourceId,
|
||||
purchaseOption: 'in-store',
|
||||
});
|
||||
const res = await this._service
|
||||
.fetchInStoreAvailability(itemData, itemData.quantity, branch)
|
||||
.toPromise();
|
||||
|
||||
const availability: Availability = {
|
||||
itemId: itemData.sourceId,
|
||||
@@ -324,14 +371,24 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
console.error('_loadInStoreAvailability', err);
|
||||
}
|
||||
|
||||
this.removeFetchingAvailability({ id, itemId: itemData.sourceId, purchaseOption: 'in-store' });
|
||||
this.removeFetchingAvailability({
|
||||
id,
|
||||
itemId: itemData.sourceId,
|
||||
purchaseOption: 'in-store',
|
||||
});
|
||||
}
|
||||
|
||||
private async _loadDeliveryAvailability(itemData: ItemData) {
|
||||
const id = uniqueId('availability_');
|
||||
try {
|
||||
this.addFetchingAvailability({ id, itemId: itemData.sourceId, purchaseOption: 'delivery' });
|
||||
const res = await this._service.fetchDeliveryAvailability(itemData, itemData.quantity).toPromise();
|
||||
this.addFetchingAvailability({
|
||||
id,
|
||||
itemId: itemData.sourceId,
|
||||
purchaseOption: 'delivery',
|
||||
});
|
||||
const res = await this._service
|
||||
.fetchDeliveryAvailability(itemData, itemData.quantity)
|
||||
.toPromise();
|
||||
const availability: Availability = {
|
||||
itemId: itemData.sourceId,
|
||||
purchaseOption: 'delivery',
|
||||
@@ -343,14 +400,24 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
console.error('_loadDeliveryAvailability', error);
|
||||
}
|
||||
|
||||
this.removeFetchingAvailability({ id, itemId: itemData.sourceId, purchaseOption: 'delivery' });
|
||||
this.removeFetchingAvailability({
|
||||
id,
|
||||
itemId: itemData.sourceId,
|
||||
purchaseOption: 'delivery',
|
||||
});
|
||||
}
|
||||
|
||||
private async _loadDigDeliveryAvailability(itemData: ItemData) {
|
||||
const id = uniqueId('availability_');
|
||||
try {
|
||||
this.addFetchingAvailability({ id, itemId: itemData.sourceId, purchaseOption: 'dig-delivery' });
|
||||
const res = await this._service.fetchDigDeliveryAvailability(itemData, itemData.quantity).toPromise();
|
||||
this.addFetchingAvailability({
|
||||
id,
|
||||
itemId: itemData.sourceId,
|
||||
purchaseOption: 'dig-delivery',
|
||||
});
|
||||
const res = await this._service
|
||||
.fetchDigDeliveryAvailability(itemData, itemData.quantity)
|
||||
.toPromise();
|
||||
|
||||
const availability: Availability = {
|
||||
itemId: itemData.sourceId,
|
||||
@@ -363,14 +430,24 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
console.error('_loadDigDeliveryAvailability', error);
|
||||
}
|
||||
|
||||
this.removeFetchingAvailability({ id, itemId: itemData.sourceId, purchaseOption: 'dig-delivery' });
|
||||
this.removeFetchingAvailability({
|
||||
id,
|
||||
itemId: itemData.sourceId,
|
||||
purchaseOption: 'dig-delivery',
|
||||
});
|
||||
}
|
||||
|
||||
private async _loadB2bDeliveryAvailability(itemData: ItemData) {
|
||||
const id = uniqueId('availability_');
|
||||
try {
|
||||
this.addFetchingAvailability({ id, itemId: itemData.sourceId, purchaseOption: 'b2b-delivery' });
|
||||
const res = await this._service.fetchB2bDeliveryAvailability(itemData, itemData.quantity).toPromise();
|
||||
this.addFetchingAvailability({
|
||||
id,
|
||||
itemId: itemData.sourceId,
|
||||
purchaseOption: 'b2b-delivery',
|
||||
});
|
||||
const res = await this._service
|
||||
.fetchB2bDeliveryAvailability(itemData, itemData.quantity)
|
||||
.toPromise();
|
||||
|
||||
const availability: Availability = {
|
||||
itemId: itemData.sourceId,
|
||||
@@ -383,14 +460,24 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
console.error('_loadB2bDeliveryAvailability', error);
|
||||
}
|
||||
|
||||
this.removeFetchingAvailability({ id, itemId: itemData.sourceId, purchaseOption: 'b2b-delivery' });
|
||||
this.removeFetchingAvailability({
|
||||
id,
|
||||
itemId: itemData.sourceId,
|
||||
purchaseOption: 'b2b-delivery',
|
||||
});
|
||||
}
|
||||
|
||||
private async _loadDownloadAvailability(itemData: ItemData) {
|
||||
const id = uniqueId('availability_');
|
||||
try {
|
||||
this.addFetchingAvailability({ id, itemId: itemData.sourceId, purchaseOption: 'download' });
|
||||
const res = await this._service.fetchDownloadAvailability(itemData).toPromise();
|
||||
this.addFetchingAvailability({
|
||||
id,
|
||||
itemId: itemData.sourceId,
|
||||
purchaseOption: 'download',
|
||||
});
|
||||
const res = await this._service
|
||||
.fetchDownloadAvailability(itemData)
|
||||
.toPromise();
|
||||
|
||||
const availability: Availability = {
|
||||
itemId: itemData.sourceId,
|
||||
@@ -403,7 +490,11 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
console.error('_loadDownloadAvailability', error);
|
||||
}
|
||||
|
||||
this.removeFetchingAvailability({ id, itemId: itemData.sourceId, purchaseOption: 'download' });
|
||||
this.removeFetchingAvailability({
|
||||
id,
|
||||
itemId: itemData.sourceId,
|
||||
purchaseOption: 'download',
|
||||
});
|
||||
}
|
||||
|
||||
private _checkAndSetAvailability(availability: Availability) {
|
||||
@@ -411,7 +502,9 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
const availabilities = this.availabilities;
|
||||
|
||||
const index = availabilities.findIndex(
|
||||
(a) => a.itemId === availability.itemId && a.purchaseOption === availability.purchaseOption,
|
||||
(a) =>
|
||||
a.itemId === availability.itemId &&
|
||||
a.purchaseOption === availability.purchaseOption,
|
||||
);
|
||||
|
||||
if (index > -1) {
|
||||
@@ -423,7 +516,11 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
this.patchState({ availabilities });
|
||||
} else {
|
||||
let availabilities = this.availabilities.filter(
|
||||
(a) => !(a.itemId === availability.itemId && a.purchaseOption === availability.purchaseOption),
|
||||
(a) =>
|
||||
!(
|
||||
a.itemId === availability.itemId &&
|
||||
a.purchaseOption === availability.purchaseOption
|
||||
),
|
||||
);
|
||||
this.patchState({ availabilities });
|
||||
}
|
||||
@@ -432,7 +529,11 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
private _addCanAddResult(canAdd: CanAdd) {
|
||||
let canAddResults = this.canAddResults;
|
||||
canAddResults = canAddResults.filter(
|
||||
(c) => !(c.itemId === canAdd.itemId && c.purchaseOption === canAdd.purchaseOption),
|
||||
(c) =>
|
||||
!(
|
||||
c.itemId === canAdd.itemId &&
|
||||
c.purchaseOption === canAdd.purchaseOption
|
||||
),
|
||||
);
|
||||
canAddResults.push(canAdd);
|
||||
this.patchState({ canAddResults });
|
||||
@@ -474,7 +575,10 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
const b2bDeliveryAvailability = this.availabilities.find(
|
||||
(a) => a.itemId === item.id && a.purchaseOption === 'b2b-delivery',
|
||||
);
|
||||
deliveryAvailability = deliveryAvailability || digDeliveryAvailability || b2bDeliveryAvailability;
|
||||
deliveryAvailability =
|
||||
deliveryAvailability ||
|
||||
digDeliveryAvailability ||
|
||||
b2bDeliveryAvailability;
|
||||
if (deliveryAvailability) {
|
||||
payloads['Versand'].push(
|
||||
mapToItemPayload({
|
||||
@@ -487,7 +591,9 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
}
|
||||
|
||||
// Get Abholung availability
|
||||
let pickupAvailability = this.availabilities.find((a) => a.itemId === item.id && a.purchaseOption === 'pickup');
|
||||
let pickupAvailability = this.availabilities.find(
|
||||
(a) => a.itemId === item.id && a.purchaseOption === 'pickup',
|
||||
);
|
||||
if (pickupAvailability) {
|
||||
payloads['Abholung'].push(
|
||||
mapToItemPayload({
|
||||
@@ -519,7 +625,9 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
const itemPayloads = payloads[key];
|
||||
if (itemPayloads.length > 0) {
|
||||
try {
|
||||
const res = await this._service.fetchCanAdd(this.processId, key, itemPayloads).toPromise();
|
||||
const res = await this._service
|
||||
.fetchCanAdd(this.processId, key, itemPayloads)
|
||||
.toPromise();
|
||||
res.forEach((canAdd) => {
|
||||
const item = itemPayloads.find((i) => i.id === canAdd.id);
|
||||
this._addCanAddResult({
|
||||
@@ -549,7 +657,9 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
if (value && !selectedItemIds.includes(itemId)) {
|
||||
this.patchState({ selectedItemIds: [...selectedItemIds, itemId] });
|
||||
} else if (!value && selectedItemIds.includes(itemId)) {
|
||||
this.patchState({ selectedItemIds: selectedItemIds.filter((id) => id !== itemId) });
|
||||
this.patchState({
|
||||
selectedItemIds: selectedItemIds.filter((id) => id !== itemId),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -561,7 +671,9 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
|
||||
canAddItem(itemId: number): boolean {
|
||||
const purchaseOption = this.purchaseOption;
|
||||
const canAdd = this.canAddResults.find((c) => c.itemId === itemId && c.purchaseOption === purchaseOption);
|
||||
const canAdd = this.canAddResults.find(
|
||||
(c) => c.itemId === itemId && c.purchaseOption === purchaseOption,
|
||||
);
|
||||
|
||||
if (canAdd) {
|
||||
return canAdd.canAdd;
|
||||
@@ -574,20 +686,40 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
this.patchState({ selectedItemIds: [] });
|
||||
}
|
||||
|
||||
getItemsThatHaveAnAvailabilityForPurchaseOption(purchaseOption: PurchaseOption): Item[] {
|
||||
return this.get(Selectors.getItemsThatHaveAnAvailabilityForPurchaseOption(purchaseOption));
|
||||
getItemsThatHaveAnAvailabilityForPurchaseOption(
|
||||
purchaseOption: PurchaseOption,
|
||||
): Item[] {
|
||||
return this.get(
|
||||
Selectors.getItemsThatHaveAnAvailabilityForPurchaseOption(purchaseOption),
|
||||
);
|
||||
}
|
||||
|
||||
getItemsThatHaveAnAvailabilityForPurchaseOption$(purchaseOption: PurchaseOption): Observable<Item[]> {
|
||||
return this.select(Selectors.getItemsThatHaveAnAvailabilityForPurchaseOption(purchaseOption));
|
||||
getItemsThatHaveAnAvailabilityForPurchaseOption$(
|
||||
purchaseOption: PurchaseOption,
|
||||
): Observable<Item[]> {
|
||||
return this.select(
|
||||
Selectors.getItemsThatHaveAnAvailabilityForPurchaseOption(purchaseOption),
|
||||
);
|
||||
}
|
||||
|
||||
getItemsThatHaveAnAvailabilityAndCanAddForPurchaseOption(purchaseOption: PurchaseOption): Item[] {
|
||||
return this.get(Selectors.getItemsThatHaveAnAvailabilityAndCanAddForPurchaseOption(purchaseOption));
|
||||
getItemsThatHaveAnAvailabilityAndCanAddForPurchaseOption(
|
||||
purchaseOption: PurchaseOption,
|
||||
): Item[] {
|
||||
return this.get(
|
||||
Selectors.getItemsThatHaveAnAvailabilityAndCanAddForPurchaseOption(
|
||||
purchaseOption,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
getItemsThatHaveAnAvailabilityAndCanAddForPurchaseOption$(purchaseOption: PurchaseOption): Observable<Item[]> {
|
||||
return this.select(Selectors.getItemsThatHaveAnAvailabilityAndCanAddForPurchaseOption(purchaseOption));
|
||||
getItemsThatHaveAnAvailabilityAndCanAddForPurchaseOption$(
|
||||
purchaseOption: PurchaseOption,
|
||||
): Observable<Item[]> {
|
||||
return this.select(
|
||||
Selectors.getItemsThatHaveAnAvailabilityAndCanAddForPurchaseOption(
|
||||
purchaseOption,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
getAvailabilitiesForItem(itemId: number): Availability[] {
|
||||
@@ -679,15 +811,21 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
}
|
||||
|
||||
getPrice$(itemId: number) {
|
||||
return this.purchaseOption$.pipe(switchMap((po) => this.getPriceForPurchaseOption$(itemId, po)));
|
||||
return this.purchaseOption$.pipe(
|
||||
switchMap((po) => this.getPriceForPurchaseOption$(itemId, po)),
|
||||
);
|
||||
}
|
||||
|
||||
getPriceForPurchaseOption(itemId: number, purchaseOption: PurchaseOption) {
|
||||
return this.get(Selectors.getPriceForPurchaseOption(itemId, purchaseOption));
|
||||
return this.get(
|
||||
Selectors.getPriceForPurchaseOption(itemId, purchaseOption),
|
||||
);
|
||||
}
|
||||
|
||||
getPriceForPurchaseOption$(itemId: number, purchaseOption: PurchaseOption) {
|
||||
return this.select(Selectors.getPriceForPurchaseOption(itemId, purchaseOption));
|
||||
return this.select(
|
||||
Selectors.getPriceForPurchaseOption(itemId, purchaseOption),
|
||||
);
|
||||
}
|
||||
|
||||
getCanEditPrice(itemId: number) {
|
||||
@@ -748,27 +886,51 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
}
|
||||
|
||||
getCanAddResultForItemAndCurrentPurchaseOption(itemId: number) {
|
||||
return this.get(Selectors.getCanAddResultForItemAndCurrentPurchaseOption(itemId));
|
||||
return this.get(
|
||||
Selectors.getCanAddResultForItemAndCurrentPurchaseOption(itemId),
|
||||
);
|
||||
}
|
||||
|
||||
getCanAddResultForItemAndCurrentPurchaseOption$(itemId: number) {
|
||||
return this.select(Selectors.getCanAddResultForItemAndCurrentPurchaseOption(itemId));
|
||||
return this.select(
|
||||
Selectors.getCanAddResultForItemAndCurrentPurchaseOption(itemId),
|
||||
);
|
||||
}
|
||||
|
||||
getAvailabilityWithPurchaseOption(itemId: number, purchaseOption: PurchaseOption) {
|
||||
return this.get(Selectors.getAvailabilityWithPurchaseOption(itemId, purchaseOption));
|
||||
getAvailabilityWithPurchaseOption(
|
||||
itemId: number,
|
||||
purchaseOption: PurchaseOption,
|
||||
) {
|
||||
return this.get(
|
||||
Selectors.getAvailabilityWithPurchaseOption(itemId, purchaseOption),
|
||||
);
|
||||
}
|
||||
|
||||
getAvailabilityWithPurchaseOption$(itemId: number, purchaseOption: PurchaseOption) {
|
||||
return this.select(Selectors.getAvailabilityWithPurchaseOption(itemId, purchaseOption));
|
||||
getAvailabilityWithPurchaseOption$(
|
||||
itemId: number,
|
||||
purchaseOption: PurchaseOption,
|
||||
) {
|
||||
return this.select(
|
||||
Selectors.getAvailabilityWithPurchaseOption(itemId, purchaseOption),
|
||||
);
|
||||
}
|
||||
|
||||
getCanAddResultWithPurchaseOption(itemId: number, purchaseOption: PurchaseOption) {
|
||||
return this.get(Selectors.getCanAddResultWithPurchaseOption(itemId, purchaseOption));
|
||||
getCanAddResultWithPurchaseOption(
|
||||
itemId: number,
|
||||
purchaseOption: PurchaseOption,
|
||||
) {
|
||||
return this.get(
|
||||
Selectors.getCanAddResultWithPurchaseOption(itemId, purchaseOption),
|
||||
);
|
||||
}
|
||||
|
||||
getCanAddResultWithPurchaseOption$(itemId: number, purchaseOption: PurchaseOption) {
|
||||
return this.select(Selectors.getCanAddResultWithPurchaseOption(itemId, purchaseOption));
|
||||
getCanAddResultWithPurchaseOption$(
|
||||
itemId: number,
|
||||
purchaseOption: PurchaseOption,
|
||||
) {
|
||||
return this.select(
|
||||
Selectors.getCanAddResultWithPurchaseOption(itemId, purchaseOption),
|
||||
);
|
||||
}
|
||||
|
||||
addItemsToShoppingCart() {
|
||||
@@ -777,10 +939,16 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
}
|
||||
}
|
||||
|
||||
getAddToShoppingCartDTOForItem(itemId: number, purchaseOption: PurchaseOption): AddToShoppingCartDTO {
|
||||
getAddToShoppingCartDTOForItem(
|
||||
itemId: number,
|
||||
purchaseOption: PurchaseOption,
|
||||
): AddToShoppingCartDTO {
|
||||
const item = this.items.find((i) => i.id === itemId);
|
||||
const price = this.getPriceForPurchaseOption(itemId, this.purchaseOption);
|
||||
const availability = this.getAvailabilityWithPurchaseOption(itemId, purchaseOption);
|
||||
const availability = this.getAvailabilityWithPurchaseOption(
|
||||
itemId,
|
||||
purchaseOption,
|
||||
);
|
||||
|
||||
if (!isItemDTO(item, this.type)) {
|
||||
throw new Error('Invalid item');
|
||||
@@ -802,8 +970,12 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
availability: { ...availability.data, price },
|
||||
destination,
|
||||
itemType: item.type,
|
||||
product: { ...item.product, catalogProductNumber: item?.product?.catalogProductNumber ?? String(item.id) },
|
||||
promotion: { points: item.promoPoints },
|
||||
product: {
|
||||
...item.product,
|
||||
catalogProductNumber:
|
||||
item?.product?.catalogProductNumber ?? String(item.id),
|
||||
},
|
||||
promotion: { value: item.promoPoints },
|
||||
// retailPrice: {
|
||||
// value: price.value.value,
|
||||
// currency: price.value.currency,
|
||||
@@ -813,10 +985,16 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
};
|
||||
}
|
||||
|
||||
getUpdateShoppingCartItemDTOForItem(itemId: number, purchaseOption: PurchaseOption): UpdateShoppingCartItemDTO {
|
||||
getUpdateShoppingCartItemDTOForItem(
|
||||
itemId: number,
|
||||
purchaseOption: PurchaseOption,
|
||||
): UpdateShoppingCartItemDTO {
|
||||
const item = this.items.find((i) => i.id === itemId);
|
||||
const price = this.getPriceForPurchaseOption(itemId, this.purchaseOption);
|
||||
const availability = this.getAvailabilityWithPurchaseOption(itemId, purchaseOption);
|
||||
const availability = this.getAvailabilityWithPurchaseOption(
|
||||
itemId,
|
||||
purchaseOption,
|
||||
);
|
||||
|
||||
if (!isShoppingCartItemDTO(item, this.type)) {
|
||||
throw new Error('Invalid item');
|
||||
@@ -856,7 +1034,9 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
const payloads = this.selectedItemIds.map((itemId) =>
|
||||
this.getAddToShoppingCartDTOForItem(itemId, purchaseOption),
|
||||
);
|
||||
await this._service.addItemToShoppingCart(this.processId, payloads).toPromise();
|
||||
await this._service
|
||||
.addItemToShoppingCart(this.processId, payloads)
|
||||
.toPromise();
|
||||
} else if (type === 'update') {
|
||||
const payloads = this.selectedItemIds.map((itemId) =>
|
||||
this.getUpdateShoppingCartItemDTOForItem(itemId, purchaseOption),
|
||||
@@ -864,8 +1044,13 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||
|
||||
for (const itemId of this.selectedItemIds) {
|
||||
const item = this.items.find((i) => i.id === itemId);
|
||||
const payload = this.getUpdateShoppingCartItemDTOForItem(itemId, purchaseOption);
|
||||
await this._service.updateItemInShoppingCart(this.processId, item.id, payload).toPromise();
|
||||
const payload = this.getUpdateShoppingCartItemDTOForItem(
|
||||
itemId,
|
||||
purchaseOption,
|
||||
);
|
||||
await this._service
|
||||
.updateItemInShoppingCart(this.processId, item.id, payload)
|
||||
.toPromise();
|
||||
}
|
||||
} else {
|
||||
throw new Error('Invalid type');
|
||||
|
||||
@@ -22,12 +22,21 @@ import { UiErrorModalComponent, UiModalService } from '@ui/modal';
|
||||
import { CacheService } from '@core/cache';
|
||||
import { isEqual } from 'lodash';
|
||||
import { BehaviorSubject, combineLatest, Subscription } from 'rxjs';
|
||||
import { debounceTime, first, map, switchMap, withLatestFrom } from 'rxjs/operators';
|
||||
import {
|
||||
debounceTime,
|
||||
first,
|
||||
map,
|
||||
switchMap,
|
||||
withLatestFrom,
|
||||
} from 'rxjs/operators';
|
||||
import { ArticleSearchService } from '../article-search.store';
|
||||
import { AddedToCartModalComponent } from './added-to-cart-modal/added-to-cart-modal.component';
|
||||
import { SearchResultItemComponent } from './search-result-item.component';
|
||||
import { ProductCatalogNavigationService } from '@shared/services/navigation';
|
||||
import { Filter, FilterInputGroupMainComponent } from '@shared/components/filter';
|
||||
import {
|
||||
Filter,
|
||||
FilterInputGroupMainComponent,
|
||||
} from '@shared/components/filter';
|
||||
import { DomainAvailabilityService, ItemData } from '@domain/availability';
|
||||
import { asapScheduler } from 'rxjs';
|
||||
import { ShellService } from '@shared/shell';
|
||||
@@ -39,8 +48,11 @@ import { ShellService } from '@shared/shell';
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
standalone: false,
|
||||
})
|
||||
export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
@ViewChildren(SearchResultItemComponent) listItems: QueryList<SearchResultItemComponent>;
|
||||
export class ArticleSearchResultsComponent
|
||||
implements OnInit, OnDestroy, AfterViewInit
|
||||
{
|
||||
@ViewChildren(SearchResultItemComponent)
|
||||
listItems: QueryList<SearchResultItemComponent>;
|
||||
@ViewChild(CdkVirtualScrollViewport, { static: false })
|
||||
scrollContainer: CdkVirtualScrollViewport;
|
||||
|
||||
@@ -59,7 +71,9 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
|
||||
selectedItems$ = combineLatest([this.results$, this.selectedItemIds$]).pipe(
|
||||
map(([items, selectedItemIds]) => {
|
||||
return items?.filter((item) => selectedItemIds?.find((selectedItemId) => item.id === selectedItemId));
|
||||
return items?.filter((item) =>
|
||||
selectedItemIds?.find((selectedItemId) => item.id === selectedItemId),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -81,7 +95,10 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
return this._environment.matchDesktopLarge();
|
||||
}
|
||||
|
||||
hasFilter$ = combineLatest([this.searchService.filter$, this.searchService.defaultSettings$]).pipe(
|
||||
hasFilter$ = combineLatest([
|
||||
this.searchService.filter$,
|
||||
this.searchService.defaultSettings$,
|
||||
]).pipe(
|
||||
map(([filter, defaultFilter]) => {
|
||||
const filterQueryParams = filter?.getQueryParams();
|
||||
return !isEqual(
|
||||
@@ -100,11 +117,15 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
}
|
||||
|
||||
get filterQueryParams() {
|
||||
return this.cleanupQueryParams(this.searchService?.filter?.getQueryParams());
|
||||
return this.cleanupQueryParams(
|
||||
this.searchService?.filter?.getQueryParams(),
|
||||
);
|
||||
}
|
||||
|
||||
get primaryOutletActive$() {
|
||||
return this._environment.matchDesktop$.pipe(map((matches) => matches && this.route.outlet === 'primary'));
|
||||
return this._environment.matchDesktop$.pipe(
|
||||
map((matches) => matches && this.route.outlet === 'primary'),
|
||||
);
|
||||
}
|
||||
|
||||
private readonly SCROLL_INDEX_TOKEN = 'CATALOG_RESULTS_LIST_SCROLL_INDEX';
|
||||
@@ -129,28 +150,42 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
|
||||
ngOnInit() {
|
||||
this.subscriptions.add(
|
||||
combineLatest([this.application.activatedProcessId$, this.route.queryParams])
|
||||
combineLatest([
|
||||
this.application.activatedProcessId$,
|
||||
this.route.queryParams,
|
||||
])
|
||||
.pipe(
|
||||
debounceTime(0),
|
||||
switchMap(([processId, queryParams]) =>
|
||||
this.application
|
||||
.getSelectedBranch$(processId)
|
||||
.pipe(map((selectedBranch) => ({ processId, queryParams, selectedBranch }))),
|
||||
this.application.getSelectedBranch$(processId).pipe(
|
||||
map((selectedBranch) => ({
|
||||
processId,
|
||||
queryParams,
|
||||
selectedBranch,
|
||||
})),
|
||||
),
|
||||
),
|
||||
)
|
||||
.subscribe(async ({ processId, queryParams, selectedBranch }) => {
|
||||
const processChanged = processId !== this.searchService.processId;
|
||||
|
||||
const branchChanged = selectedBranch?.id !== this.searchService?.selectedBranch?.id;
|
||||
const branchChanged =
|
||||
selectedBranch?.id !== this.searchService?.selectedBranch?.id;
|
||||
|
||||
if (processChanged) {
|
||||
if (!!this.searchService.processId && this.searchService.filter instanceof Filter) {
|
||||
if (
|
||||
!!this.searchService.processId &&
|
||||
this.searchService.filter instanceof Filter
|
||||
) {
|
||||
this.cacheCurrentData(
|
||||
this.searchService.processId,
|
||||
this.searchService.filter.getQueryParams(),
|
||||
this.searchService?.selectedBranch?.id,
|
||||
);
|
||||
this.updateBreadcrumbs(this.searchService.processId, this.searchService.filter.getQueryParams());
|
||||
this.updateBreadcrumbs(
|
||||
this.searchService.processId,
|
||||
this.searchService.filter.getQueryParams(),
|
||||
);
|
||||
}
|
||||
this.searchService.setProcess(processId);
|
||||
}
|
||||
@@ -169,9 +204,20 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
this.scrollToItem(await this._getScrollIndexFromCache());
|
||||
}
|
||||
|
||||
if (!isEqual(cleanQueryParams, this.cleanupQueryParams(this.searchService.filter.getQueryParams()))) {
|
||||
if (
|
||||
!isEqual(
|
||||
cleanQueryParams,
|
||||
this.cleanupQueryParams(
|
||||
this.searchService.filter.getQueryParams(),
|
||||
),
|
||||
)
|
||||
) {
|
||||
await this.searchService.setDefaultFilter(queryParams);
|
||||
const data = await this.getCachedData(processId, queryParams, selectedBranch?.id);
|
||||
const data = await this.getCachedData(
|
||||
processId,
|
||||
queryParams,
|
||||
selectedBranch?.id,
|
||||
);
|
||||
|
||||
if (data.items?.length > 0) {
|
||||
this.searchService.setItems(data.items);
|
||||
@@ -179,21 +225,29 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
}
|
||||
if (
|
||||
data.items?.length === 0 &&
|
||||
this.route?.parent?.children?.find((childRoute) => childRoute?.outlet === 'side')?.snapshot?.routeConfig
|
||||
?.path !== 'filter'
|
||||
this.route?.parent?.children?.find(
|
||||
(childRoute) => childRoute?.outlet === 'side',
|
||||
)?.snapshot?.routeConfig?.path !== 'filter'
|
||||
) {
|
||||
this.search({ clear: true });
|
||||
} else {
|
||||
const selectedItemIds: Array<string> = queryParams?.selected_item_ids?.split(',') ?? [];
|
||||
const selectedItemIds: Array<string> =
|
||||
queryParams?.selected_item_ids?.split(',') ?? [];
|
||||
for (const id of selectedItemIds) {
|
||||
if (id) {
|
||||
this.searchService.setSelected({ selected: true, itemId: Number(id) });
|
||||
this.searchService.setSelected({
|
||||
selected: true,
|
||||
itemId: Number(id),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const process = await this.application.getProcessById$(processId).pipe(first()).toPromise();
|
||||
const process = await this.application
|
||||
.getProcessById$(processId)
|
||||
.pipe(first())
|
||||
.toPromise();
|
||||
if (process) {
|
||||
await this.updateBreadcrumbs(processId, queryParams);
|
||||
await this.createBreadcrumb(processId, queryParams);
|
||||
@@ -240,7 +294,10 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
})
|
||||
.navigate();
|
||||
}
|
||||
} else if (searchCompleted?.clear || this.route.outlet === 'primary') {
|
||||
} else if (
|
||||
searchCompleted?.clear ||
|
||||
this.route.outlet === 'primary'
|
||||
) {
|
||||
const ean = this.route?.snapshot?.params?.ean;
|
||||
|
||||
if (ean) {
|
||||
@@ -253,7 +310,9 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
.navigate();
|
||||
} else {
|
||||
await this._navigationService
|
||||
.getArticleSearchResultsPath(processId, { queryParams: params })
|
||||
.getArticleSearchResultsPath(processId, {
|
||||
queryParams: params,
|
||||
})
|
||||
.navigate();
|
||||
}
|
||||
}
|
||||
@@ -266,7 +325,9 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
this.searchService.searchStarted.subscribe(async (options) => {
|
||||
if (!options?.clear) {
|
||||
const queryParams = {
|
||||
...this.cleanupQueryParams(this.searchService.filter.getQueryParams()),
|
||||
...this.cleanupQueryParams(
|
||||
this.searchService.filter.getQueryParams(),
|
||||
),
|
||||
main_qs: this.sharedFilterInputGroupMain?.uiInput?.value,
|
||||
};
|
||||
|
||||
@@ -281,11 +342,19 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
}
|
||||
|
||||
private _addScrollIndexToCache(index: number): void {
|
||||
this.cache.set<number>({ processId: this.getProcessId(), token: this.SCROLL_INDEX_TOKEN }, index);
|
||||
this.cache.set<number>(
|
||||
{ processId: this.getProcessId(), token: this.SCROLL_INDEX_TOKEN },
|
||||
index,
|
||||
);
|
||||
}
|
||||
|
||||
private async _getScrollIndexFromCache(): Promise<number> {
|
||||
return (await this.cache.get<number>({ processId: this.getProcessId(), token: this.SCROLL_INDEX_TOKEN })) ?? 0;
|
||||
return (
|
||||
(await this.cache.get<number>({
|
||||
processId: this.getProcessId(),
|
||||
token: this.SCROLL_INDEX_TOKEN,
|
||||
})) ?? 0
|
||||
);
|
||||
}
|
||||
|
||||
async scrollToItem(i?: number) {
|
||||
@@ -303,12 +372,14 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
}
|
||||
|
||||
scrolledIndexChange(index: number) {
|
||||
const completeListFetched = this.searchService.items.length === this.searchService.hits;
|
||||
const completeListFetched =
|
||||
this.searchService.items.length === this.searchService.hits;
|
||||
|
||||
if (
|
||||
index &&
|
||||
!completeListFetched &&
|
||||
this.searchService.items.length <= this.scrollContainer?.getRenderedRange()?.end
|
||||
this.searchService.items.length <=
|
||||
this.scrollContainer?.getRenderedRange()?.end
|
||||
) {
|
||||
this.search({ clear: false });
|
||||
}
|
||||
@@ -326,7 +397,10 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
this.searchService.filter.getQueryParams(),
|
||||
this.searchService?.selectedBranch?.id,
|
||||
);
|
||||
await this.updateBreadcrumbs(this.searchService.processId, this.searchService.filter.getQueryParams());
|
||||
await this.updateBreadcrumbs(
|
||||
this.searchService.processId,
|
||||
this.searchService.filter.getQueryParams(),
|
||||
);
|
||||
|
||||
this.unselectAll();
|
||||
}
|
||||
@@ -345,7 +419,15 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
return clean;
|
||||
}
|
||||
|
||||
search({ filter, clear = false, orderBy = false }: { filter?: Filter; clear?: boolean; orderBy?: boolean }) {
|
||||
search({
|
||||
filter,
|
||||
clear = false,
|
||||
orderBy = false,
|
||||
}: {
|
||||
filter?: Filter;
|
||||
clear?: boolean;
|
||||
orderBy?: boolean;
|
||||
}) {
|
||||
if (filter) {
|
||||
this.sharedFilterInputGroupMain.cancelAutocomplete();
|
||||
}
|
||||
@@ -354,19 +436,28 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
}
|
||||
|
||||
getDetailsPath(itemId: number) {
|
||||
return this._navigationService.getArticleDetailsPath({ processId: this.application.activatedProcessId, itemId })
|
||||
.path;
|
||||
return this._navigationService.getArticleDetailsPath({
|
||||
processId: this.application.activatedProcessId,
|
||||
itemId,
|
||||
}).path;
|
||||
}
|
||||
|
||||
async updateBreadcrumbs(
|
||||
processId: number = this.searchService.processId,
|
||||
queryParams: Record<string, string> = this.searchService.filter?.getQueryParams(),
|
||||
queryParams: Record<
|
||||
string,
|
||||
string
|
||||
> = this.searchService.filter?.getQueryParams(),
|
||||
) {
|
||||
const selected_item_ids = this.searchService?.selectedItemIds?.toString();
|
||||
|
||||
if (queryParams) {
|
||||
const crumbs = await this.breadcrumb
|
||||
.getBreadcrumbsByKeyAndTags$(processId, ['catalog', 'filter', 'results'])
|
||||
.getBreadcrumbsByKeyAndTags$(processId, [
|
||||
'catalog',
|
||||
'filter',
|
||||
'results',
|
||||
])
|
||||
.pipe(first())
|
||||
.toPromise();
|
||||
|
||||
@@ -382,13 +473,18 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
}
|
||||
}
|
||||
|
||||
async createBreadcrumb(processId: number, queryParams: Record<string, string>) {
|
||||
async createBreadcrumb(
|
||||
processId: number,
|
||||
queryParams: Record<string, string>,
|
||||
) {
|
||||
if (queryParams) {
|
||||
const name = queryParams.main_qs ? queryParams.main_qs : 'Alle Artikel';
|
||||
await this.breadcrumb.addBreadcrumbIfNotExists({
|
||||
key: processId,
|
||||
name,
|
||||
path: this._navigationService.getArticleSearchResultsPath(processId, { queryParams }).path,
|
||||
path: this._navigationService.getArticleSearchResultsPath(processId, {
|
||||
queryParams,
|
||||
}).path,
|
||||
params: queryParams,
|
||||
section: 'customer',
|
||||
tags: ['catalog', 'filter', 'results'],
|
||||
@@ -405,8 +501,16 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
crumbs?.forEach((crumb) => this.breadcrumb.removeBreadcrumb(crumb.id));
|
||||
}
|
||||
|
||||
cacheCurrentData(processId: number, params: Record<string, string> = {}, branchId: number) {
|
||||
const qparams = this.cleanupQueryParams({ ...params, processId: String(processId), branchId: String(branchId) });
|
||||
cacheCurrentData(
|
||||
processId: number,
|
||||
params: Record<string, string> = {},
|
||||
branchId: number,
|
||||
) {
|
||||
const qparams = this.cleanupQueryParams({
|
||||
...params,
|
||||
processId: String(processId),
|
||||
branchId: String(branchId),
|
||||
});
|
||||
|
||||
this.cache.set(qparams, {
|
||||
items: this.searchService.items,
|
||||
@@ -414,8 +518,16 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
});
|
||||
}
|
||||
|
||||
async getCachedData(processId: number, params: Record<string, string> = {}, branchId: number) {
|
||||
const qparams = this.cleanupQueryParams({ ...params, processId: String(processId), branchId: String(branchId) });
|
||||
async getCachedData(
|
||||
processId: number,
|
||||
params: Record<string, string> = {},
|
||||
branchId: number,
|
||||
) {
|
||||
const qparams = this.cleanupQueryParams({
|
||||
...params,
|
||||
processId: String(processId),
|
||||
branchId: String(branchId),
|
||||
});
|
||||
const cacheData = await this.cache.get<{
|
||||
items: ItemDTO[];
|
||||
hits: number;
|
||||
@@ -452,7 +564,12 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
}
|
||||
|
||||
unselectAll() {
|
||||
this.listItems.forEach((listItem) => this.searchService.setSelected({ selected: false, itemId: listItem.item.id }));
|
||||
this.listItems.forEach((listItem) =>
|
||||
this.searchService.setSelected({
|
||||
selected: false,
|
||||
itemId: listItem.item.id,
|
||||
}),
|
||||
);
|
||||
this.searchService.patchState({ selectedItemIds: [] });
|
||||
}
|
||||
|
||||
@@ -474,39 +591,46 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
availability: {
|
||||
availabilityType: item?.catalogAvailability?.status,
|
||||
price: item?.catalogAvailability?.price,
|
||||
supplierProductNumber: item?.ids?.dig ? String(item?.ids?.dig) : item?.product?.supplierProductNumber,
|
||||
supplierProductNumber: item?.ids?.dig
|
||||
? String(item?.ids?.dig)
|
||||
: item?.product?.supplierProductNumber,
|
||||
},
|
||||
product: {
|
||||
catalogProductNumber: String(item?.id),
|
||||
...item?.product,
|
||||
},
|
||||
itemType: item?.type,
|
||||
promotion: { points: item?.promoPoints },
|
||||
promotion: { value: item?.promoPoints },
|
||||
};
|
||||
}
|
||||
|
||||
async addItemsToCart(item?: ItemDTO) {
|
||||
const selectedItems = !item ? await this.selectedItems$.pipe(first()).toPromise() : [item];
|
||||
const selectedItems = !item
|
||||
? await this.selectedItems$.pipe(first()).toPromise()
|
||||
: [item];
|
||||
const items: AddToShoppingCartDTO[] = [];
|
||||
|
||||
const canAddItemsPayload = [];
|
||||
|
||||
for (const item of selectedItems) {
|
||||
const isDownload = item?.product?.format === 'EB' || item?.product?.format === 'DL';
|
||||
const isDownload =
|
||||
item?.product?.format === 'EB' || item?.product?.format === 'DL';
|
||||
const price = item?.catalogAvailability?.price;
|
||||
const shoppingCartItem: AddToShoppingCartDTO = {
|
||||
quantity: 1,
|
||||
availability: {
|
||||
availabilityType: item?.catalogAvailability?.status,
|
||||
price,
|
||||
supplierProductNumber: item?.ids?.dig ? String(item.ids?.dig) : item?.product?.supplierProductNumber,
|
||||
supplierProductNumber: item?.ids?.dig
|
||||
? String(item.ids?.dig)
|
||||
: item?.product?.supplierProductNumber,
|
||||
},
|
||||
product: {
|
||||
catalogProductNumber: String(item?.id),
|
||||
...item?.product,
|
||||
},
|
||||
itemType: item.type,
|
||||
promotion: { points: item?.promoPoints },
|
||||
promotion: { value: item?.promoPoints },
|
||||
};
|
||||
|
||||
if (isDownload) {
|
||||
@@ -519,9 +643,14 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
.getDownloadAvailability({ item: downloadItem })
|
||||
.pipe(first())
|
||||
.toPromise();
|
||||
shoppingCartItem.destination = { data: { target: 16, logistician: downloadAvailability?.logistician } };
|
||||
shoppingCartItem.destination = {
|
||||
data: { target: 16, logistician: downloadAvailability?.logistician },
|
||||
};
|
||||
if (downloadAvailability) {
|
||||
shoppingCartItem.availability = { ...shoppingCartItem.availability, ...downloadAvailability };
|
||||
shoppingCartItem.availability = {
|
||||
...shoppingCartItem.availability,
|
||||
...downloadAvailability,
|
||||
};
|
||||
}
|
||||
canAddItemsPayload.push({
|
||||
availabilities: [{ ...item.catalogAvailability, format: 'DL' }],
|
||||
@@ -546,7 +675,10 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
if (response) {
|
||||
const cantAdd = (response as any)?.filter((r) => r.status >= 2);
|
||||
if (cantAdd?.length > 0) {
|
||||
this.openModal({ itemLength: cantAdd.length, canAddMessage: cantAdd[0].message });
|
||||
this.openModal({
|
||||
itemLength: cantAdd.length,
|
||||
canAddMessage: cantAdd[0].message,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -571,7 +703,15 @@ export class ArticleSearchResultsComponent implements OnInit, OnDestroy, AfterVi
|
||||
}
|
||||
}
|
||||
|
||||
openModal({ itemLength, canAddMessage, error }: { itemLength: number; canAddMessage?: string; error?: Error }) {
|
||||
openModal({
|
||||
itemLength,
|
||||
canAddMessage,
|
||||
error,
|
||||
}: {
|
||||
itemLength: number;
|
||||
canAddMessage?: string;
|
||||
error?: Error;
|
||||
}) {
|
||||
const modal = this._uiModal.open({
|
||||
title:
|
||||
!error && !canAddMessage
|
||||
|
||||
@@ -114,15 +114,21 @@ export class CheckoutDummyStore extends ComponentStore<CheckoutDummyState> {
|
||||
|
||||
readonly processId$ = this._application.activatedProcessId$;
|
||||
|
||||
readonly customer$ = this.processId$.pipe(switchMap((processId) => this._checkoutService.getBuyer({ processId })));
|
||||
readonly customer$ = this.processId$.pipe(
|
||||
switchMap((processId) => this._checkoutService.getBuyer({ processId })),
|
||||
);
|
||||
|
||||
readonly customerFeatures$ = this.processId$.pipe(
|
||||
switchMap((processId) => this._checkoutService.getCustomerFeatures({ processId })),
|
||||
switchMap((processId) =>
|
||||
this._checkoutService.getCustomerFeatures({ processId }),
|
||||
),
|
||||
);
|
||||
|
||||
readonly customerFilter$ = this.customerFeatures$.pipe(
|
||||
withLatestFrom(this.processId$),
|
||||
switchMap(([customerFeatures, processId]) => this._checkoutService.canSetCustomer({ processId, customerFeatures })),
|
||||
switchMap(([customerFeatures, processId]) =>
|
||||
this._checkoutService.canSetCustomer({ processId, customerFeatures }),
|
||||
),
|
||||
map((res) => res.filter),
|
||||
);
|
||||
|
||||
@@ -169,7 +175,11 @@ export class CheckoutDummyStore extends ComponentStore<CheckoutDummyState> {
|
||||
tapResponse(
|
||||
(res) => {
|
||||
const item = res.result[0];
|
||||
if (!!item && item?.product?.format !== 'EB' && item?.product?.format !== 'DL') {
|
||||
if (
|
||||
!!item &&
|
||||
item?.product?.format !== 'EB' &&
|
||||
item?.product?.format !== 'DL'
|
||||
) {
|
||||
this.patchState({
|
||||
item: res.result[0],
|
||||
message: '',
|
||||
@@ -229,12 +239,22 @@ export class CheckoutDummyStore extends ComponentStore<CheckoutDummyState> {
|
||||
updateCart = this.effect((cb$: Observable<Function>) =>
|
||||
cb$.pipe(
|
||||
tap((_) => this.patchState({ fetching: true })),
|
||||
withLatestFrom(this.processId$, this.addToCartItem$, this.shoppingCartItemId$),
|
||||
withLatestFrom(
|
||||
this.processId$,
|
||||
this.addToCartItem$,
|
||||
this.shoppingCartItemId$,
|
||||
),
|
||||
switchMap(([cb, processId, newItem, shoppingCartItemId]) => {
|
||||
const availability = newItem.availability;
|
||||
const quantity = newItem.quantity;
|
||||
const destination = newItem.destination;
|
||||
return this.updateCartRequest({ processId, shoppingCartItemId, availability, quantity, destination }).pipe(
|
||||
return this.updateCartRequest({
|
||||
processId,
|
||||
shoppingCartItemId,
|
||||
availability,
|
||||
quantity,
|
||||
destination,
|
||||
}).pipe(
|
||||
tapResponse(
|
||||
(res) => {
|
||||
this.patchState({
|
||||
@@ -270,7 +290,10 @@ export class CheckoutDummyStore extends ComponentStore<CheckoutDummyState> {
|
||||
}
|
||||
|
||||
addToCartRequest(processId: number, newItem: AddToShoppingCartDTO) {
|
||||
return this._checkoutService.addItemToShoppingCart({ processId, items: [newItem] });
|
||||
return this._checkoutService.addItemToShoppingCart({
|
||||
processId,
|
||||
items: [newItem],
|
||||
});
|
||||
}
|
||||
|
||||
updateCartRequest({
|
||||
@@ -297,7 +320,11 @@ export class CheckoutDummyStore extends ComponentStore<CheckoutDummyState> {
|
||||
});
|
||||
}
|
||||
|
||||
async createAddToCartItem(control: UntypedFormGroup, branch: BranchDTO, update?: boolean) {
|
||||
async createAddToCartItem(
|
||||
control: UntypedFormGroup,
|
||||
branch: BranchDTO,
|
||||
update?: boolean,
|
||||
) {
|
||||
let item: ItemDTO;
|
||||
const quantity = Number(control.get('quantity').value);
|
||||
const price = this._createPriceDTO(control);
|
||||
@@ -305,7 +332,11 @@ export class CheckoutDummyStore extends ComponentStore<CheckoutDummyState> {
|
||||
// Check if item exists or ean inside the control changed in the meantime
|
||||
if (!!this.item && this.item.product.ean === control.get('ean').value) {
|
||||
item = this.item;
|
||||
promoPoints = await this._getPromoPoints({ itemId: item.id, quantity, price: price.value.value });
|
||||
promoPoints = await this._getPromoPoints({
|
||||
itemId: item.id,
|
||||
quantity,
|
||||
price: price.value.value,
|
||||
});
|
||||
} else {
|
||||
item = undefined;
|
||||
}
|
||||
@@ -316,21 +347,33 @@ export class CheckoutDummyStore extends ComponentStore<CheckoutDummyState> {
|
||||
quantity,
|
||||
availability,
|
||||
product,
|
||||
promotion: item ? { points: promoPoints } : undefined,
|
||||
promotion: item ? { value: promoPoints } : undefined,
|
||||
destination: {
|
||||
data: { target: 1, targetBranch: { id: branch?.id } },
|
||||
},
|
||||
itemType: this.item?.type ?? this.get((s) => s.shoppingCartItem)?.itemType,
|
||||
itemType:
|
||||
this.item?.type ?? this.get((s) => s.shoppingCartItem)?.itemType,
|
||||
};
|
||||
|
||||
if (update) {
|
||||
const existingItem = this.get((s) => s.shoppingCartItem);
|
||||
this.patchState({ addToCartItem: newItem, shoppingCartItemId: existingItem?.id });
|
||||
this.patchState({
|
||||
addToCartItem: newItem,
|
||||
shoppingCartItemId: existingItem?.id,
|
||||
});
|
||||
}
|
||||
this.patchState({ addToCartItem: newItem });
|
||||
}
|
||||
|
||||
private async _getPromoPoints({ itemId, quantity, price }: { itemId: number; quantity: number; price: number }) {
|
||||
private async _getPromoPoints({
|
||||
itemId,
|
||||
quantity,
|
||||
price,
|
||||
}: {
|
||||
itemId: number;
|
||||
quantity: number;
|
||||
price: number;
|
||||
}) {
|
||||
let points: number;
|
||||
try {
|
||||
points = await this._catalogService
|
||||
@@ -371,7 +414,13 @@ export class CheckoutDummyStore extends ComponentStore<CheckoutDummyState> {
|
||||
};
|
||||
}
|
||||
|
||||
private _createAvailabilityDTO({ price, control }: { price: PriceDTO; control: UntypedFormGroup }): AvailabilityDTO {
|
||||
private _createAvailabilityDTO({
|
||||
price,
|
||||
control,
|
||||
}: {
|
||||
price: PriceDTO;
|
||||
control: UntypedFormGroup;
|
||||
}): AvailabilityDTO {
|
||||
return {
|
||||
availabilityType: 1024,
|
||||
supplier: {
|
||||
@@ -383,7 +432,13 @@ export class CheckoutDummyStore extends ComponentStore<CheckoutDummyState> {
|
||||
};
|
||||
}
|
||||
|
||||
private _createProductDTO({ item, control }: { item?: ItemDTO; control: UntypedFormGroup }): ProductDTO {
|
||||
private _createProductDTO({
|
||||
item,
|
||||
control,
|
||||
}: {
|
||||
item?: ItemDTO;
|
||||
control: UntypedFormGroup;
|
||||
}): ProductDTO {
|
||||
const formValues: Partial<ProductDTO> = {
|
||||
ean: control.get('ean').value,
|
||||
name: control.get('name').value,
|
||||
|
||||
Reference in New Issue
Block a user