Compare commits

...

1 Commits

Author SHA1 Message Date
Lorenz Hilpert
445817c22f hotfix(checkout): Chaning the Quantity in the cart used a wrink branch for "Rücklage"
- When chaning the quantity, the current destination branch will be used to update the quantity in the cart
2025-04-09 12:05:15 +02:00

View File

@@ -25,7 +25,10 @@ import { DomainPrinterService } from '@domain/printer';
import { CheckoutDummyComponent } from '../checkout-dummy/checkout-dummy.component'; import { CheckoutDummyComponent } from '../checkout-dummy/checkout-dummy.component';
import { CheckoutDummyData } from '../checkout-dummy/checkout-dummy-data'; import { CheckoutDummyData } from '../checkout-dummy/checkout-dummy-data';
import { PurchaseOptionsModalService } from '@modal/purchase-options'; import { PurchaseOptionsModalService } from '@modal/purchase-options';
import { CheckoutNavigationService, ProductCatalogNavigationService } from '@shared/services/navigation'; import {
CheckoutNavigationService,
ProductCatalogNavigationService,
} from '@shared/services/navigation';
import { EnvironmentService } from '@core/environment'; import { EnvironmentService } from '@core/environment';
import { CheckoutReviewStore } from './checkout-review.store'; import { CheckoutReviewStore } from './checkout-review.store';
import { ToasterService } from '@shared/shell'; import { ToasterService } from '@shared/shell';
@@ -59,8 +62,11 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
map((items) => items?.filter((item) => item?.features?.orderType === undefined)), map((items) => items?.filter((item) => item?.features?.orderType === undefined)),
); );
trackByGroupedItems: TrackByFunction<{ orderType: string; destination: DestinationDTO; items: ShoppingCartItemDTO[] }> = (_, item) => trackByGroupedItems: TrackByFunction<{
item?.orderType + item?.destination?.id; orderType: string;
destination: DestinationDTO;
items: ShoppingCartItemDTO[];
}> = (_, item) => item?.orderType + item?.destination?.id;
groupedItems$ = this._store.shoppingCartItems$.pipe( groupedItems$ = this._store.shoppingCartItems$.pipe(
takeUntil(this._store.orderCompleted), takeUntil(this._store.orderCompleted),
@@ -101,7 +107,9 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
grouped.push(group); grouped.push(group);
} }
return [...grouped].sort((a, b) => (a?.orderType === undefined ? -1 : b?.orderType === undefined ? 1 : 0)); return [...grouped].sort((a, b) =>
a?.orderType === undefined ? -1 : b?.orderType === undefined ? 1 : 0,
);
}, },
[] as { orderType: string; destination: DestinationDTO; items: ShoppingCartItemDTO[] }[], [] as { orderType: string; destination: DestinationDTO; items: ShoppingCartItemDTO[] }[],
), ),
@@ -134,7 +142,11 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
.getPromotionPoints({ .getPromotionPoints({
items, items,
}) })
.pipe(map((response) => Object.values(response.result).reduce((sum, points) => sum + points, 0))); .pipe(
map((response) =>
Object.values(response.result).reduce((sum, points) => sum + points, 0),
),
);
} else { } else {
return NEVER; return NEVER;
} }
@@ -148,7 +160,11 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
showQuantityControlSpinnerItemId: number; showQuantityControlSpinnerItemId: number;
quantityError$ = new BehaviorSubject<{ [key: string]: string }>({}); quantityError$ = new BehaviorSubject<{ [key: string]: string }>({});
primaryCtaLabel$ = combineLatest([this.payer$, this.buyer$, this.shoppingCartItemsWithoutOrderType$]).pipe( primaryCtaLabel$ = combineLatest([
this.payer$,
this.buyer$,
this.shoppingCartItemsWithoutOrderType$,
]).pipe(
map(([payer, buyer, shoppingCartItemsWithoutOrderType]) => { map(([payer, buyer, shoppingCartItemsWithoutOrderType]) => {
if (shoppingCartItemsWithoutOrderType?.length > 0) { if (shoppingCartItemsWithoutOrderType?.length > 0) {
return 'Kaufoptionen'; return 'Kaufoptionen';
@@ -182,7 +198,9 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
); );
get productSearchBasePath() { get productSearchBasePath() {
return this._productNavigationService.getArticleSearchBasePath(this.applicationService.activatedProcessId).path; return this._productNavigationService.getArticleSearchBasePath(
this.applicationService.activatedProcessId,
).path;
} }
get isDesktop$() { get isDesktop$() {
@@ -258,8 +276,14 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
}); });
} }
checkIfMultipleDestinationsForOrderTypeExist(targetBranch: BranchDTO, group: { items: ShoppingCartItemDTO[] }, i: number) { checkIfMultipleDestinationsForOrderTypeExist(
return i === 0 ? false : targetBranch.id !== group.items[i - 1].destination?.data?.targetBranch?.data.id; targetBranch: BranchDTO,
group: { items: ShoppingCartItemDTO[] },
i: number,
) {
return i === 0
? false
: targetBranch.id !== group.items[i - 1].destination?.data?.targetBranch?.data.id;
} }
async refreshAvailabilities() { async refreshAvailabilities() {
@@ -276,7 +300,9 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
await this.breadcrumb.addOrUpdateBreadcrumbIfNotExists({ await this.breadcrumb.addOrUpdateBreadcrumbIfNotExists({
key: this.applicationService.activatedProcessId, key: this.applicationService.activatedProcessId,
name: 'Warenkorb', name: 'Warenkorb',
path: this._navigationService.getCheckoutReviewPath(this.applicationService.activatedProcessId).path, path: this._navigationService.getCheckoutReviewPath(
this.applicationService.activatedProcessId,
).path,
tags: ['checkout', 'cart'], tags: ['checkout', 'cart'],
section: 'customer', section: 'customer',
}); });
@@ -284,7 +310,11 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
async removeBreadcrumbs() { async removeBreadcrumbs() {
const checkoutDummyCrumbs = await this.breadcrumb const checkoutDummyCrumbs = await this.breadcrumb
.getBreadcrumbsByKeyAndTags$(this.applicationService.activatedProcessId, ['checkout', 'cart', 'dummy']) .getBreadcrumbsByKeyAndTags$(this.applicationService.activatedProcessId, [
'checkout',
'cart',
'dummy',
])
.pipe(first()) .pipe(first())
.toPromise(); .toPromise();
checkoutDummyCrumbs.forEach(async (crumb) => { checkoutDummyCrumbs.forEach(async (crumb) => {
@@ -296,7 +326,13 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
this._store.notificationsControl = undefined; this._store.notificationsControl = undefined;
} }
openDummyModal({ data, changeDataFromCart = false }: { data?: CheckoutDummyData; changeDataFromCart?: boolean }) { openDummyModal({
data,
changeDataFromCart = false,
}: {
data?: CheckoutDummyData;
changeDataFromCart?: boolean;
}) {
this.uiModal.open({ this.uiModal.open({
content: CheckoutDummyComponent, content: CheckoutDummyComponent,
data: { ...data, changeDataFromCart }, data: { ...data, changeDataFromCart },
@@ -321,7 +357,8 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
content: PrintModalComponent, content: PrintModalComponent,
data: { data: {
printerType: 'Label', printerType: 'Label',
print: (printer) => this.domainPrinterService.printCart({ cartId: shoppingCart.id, printer }).toPromise(), print: (printer) =>
this.domainPrinterService.printCart({ cartId: shoppingCart.id, printer }).toPromise(),
} as PrintModalData, } as PrintModalData,
config: { config: {
panelClass: [], panelClass: [],
@@ -330,7 +367,13 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
}); });
} }
async updateItemQuantity({ shoppingCartItem, quantity }: { shoppingCartItem: ShoppingCartItemDTO; quantity: number }) { async updateItemQuantity({
shoppingCartItem,
quantity,
}: {
shoppingCartItem: ShoppingCartItemDTO;
quantity: number;
}) {
if (quantity === shoppingCartItem.quantity) { if (quantity === shoppingCartItem.quantity) {
return; return;
} }
@@ -355,6 +398,7 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
price: shoppingCartItem.availability.price, price: shoppingCartItem.availability.price,
}, },
quantity, quantity,
branch,
}) })
.toPromise(); .toPromise();
@@ -439,7 +483,9 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
} else if (availability) { } else if (availability) {
// Wenn das Ergebnis der Availability Abfrage keinen Preis zurückliefert (z.B. HFI Geschenkkarte), wird der Preis aus der // Wenn das Ergebnis der Availability Abfrage keinen Preis zurückliefert (z.B. HFI Geschenkkarte), wird der Preis aus der
// Availability vor der Abfrage verwendet // Availability vor der Abfrage verwendet
const updateAvailability = availability?.price ? availability : { ...availability, price: shoppingCartItem.availability?.price }; const updateAvailability = availability?.price
? availability
: { ...availability, price: shoppingCartItem.availability?.price };
await this.domainCheckoutService await this.domainCheckoutService
.updateItemInShoppingCart({ .updateItemInShoppingCart({
@@ -447,7 +493,11 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
shoppingCartItemId: shoppingCartItem.id, shoppingCartItemId: shoppingCartItem.id,
update: { update: {
quantity, quantity,
availability: this.compareDeliveryAndCatalogPrice(updateAvailability, orderType, shoppingCartItemPrice), availability: this.compareDeliveryAndCatalogPrice(
updateAvailability,
orderType,
shoppingCartItemPrice,
),
}, },
}) })
.toPromise(); .toPromise();
@@ -467,8 +517,15 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
} }
// Bei unbekannten Kunden und DIG Bestellung findet ein Vergleich der Preise statt // Bei unbekannten Kunden und DIG Bestellung findet ein Vergleich der Preise statt
compareDeliveryAndCatalogPrice(availability: AvailabilityDTO, orderType: string, shoppingCartItemPrice: number) { compareDeliveryAndCatalogPrice(
if (['Versand', 'DIG-Versand'].includes(orderType) && shoppingCartItemPrice < availability?.price?.value?.value) { availability: AvailabilityDTO,
orderType: string,
shoppingCartItemPrice: number,
) {
if (
['Versand', 'DIG-Versand'].includes(orderType) &&
shoppingCartItemPrice < availability?.price?.value?.value
) {
return { return {
...availability, ...availability,
price: { price: {
@@ -514,7 +571,10 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
async changeAddress() { async changeAddress() {
const processId = this.applicationService.activatedProcessId; const processId = this.applicationService.activatedProcessId;
const customer = await this.domainCheckoutService.getBuyer({ processId }).pipe(first()).toPromise(); const customer = await this.domainCheckoutService
.getBuyer({ processId })
.pipe(first())
.toPromise();
if (!customer) { if (!customer) {
this.navigateToCustomerSearch(processId); this.navigateToCustomerSearch(processId);
return; return;
@@ -525,7 +585,9 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
} }
async order() { async order() {
const shoppingCartItemsWithoutOrderType = await this.shoppingCartItemsWithoutOrderType$.pipe(first()).toPromise(); const shoppingCartItemsWithoutOrderType = await this.shoppingCartItemsWithoutOrderType$
.pipe(first())
.toPromise();
if (shoppingCartItemsWithoutOrderType?.length > 0) { if (shoppingCartItemsWithoutOrderType?.length > 0) {
this.showPurchasingListModal(shoppingCartItemsWithoutOrderType); this.showPurchasingListModal(shoppingCartItemsWithoutOrderType);
@@ -533,7 +595,10 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
} }
const processId = this.applicationService.activatedProcessId; const processId = this.applicationService.activatedProcessId;
const customer = await this.domainCheckoutService.getBuyer({ processId }).pipe(first()).toPromise(); const customer = await this.domainCheckoutService
.getBuyer({ processId })
.pipe(first())
.toPromise();
if (!customer) { if (!customer) {
this.navigateToCustomerSearch(processId); this.navigateToCustomerSearch(processId);
} else { } else {
@@ -577,7 +642,10 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
} }
async patchProcess(processId: number) { async patchProcess(processId: number) {
const process = await this.applicationService.getProcessById$(processId).pipe(first()).toPromise(); const process = await this.applicationService
.getProcessById$(processId)
.pipe(first())
.toPromise();
if (!!process) { if (!!process) {
this.applicationService.patchProcess(process.id, { this.applicationService.patchProcess(process.id, {
name: `${process.name} Bestellbestätigung`, name: `${process.name} Bestellbestätigung`,