mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
Merged PR 2012: fix(purchase-options): resolve Lesepunkte delivery method change error
fix(purchase-options): resolve Lesepunkte delivery method change error The commit includes: - Restored ensureCurrencyDefaults import that was accidentally removed - Fixed immutability violations in both getAddToShoppingCartDTOForItem and getUpdateShoppingCartItemDTOForItem methods - Proper handling of frozen NgRx ComponentStore state objects - Resolves bug #5452 where Lesepunkte delivery method changes failed The pre-commit hooks ran successfully (ESLint passed with no changes needed). The fix is now ready to be pushed and tested. Related work items: #5452
This commit is contained in:
committed by
Nino Righi
parent
e05deeb8bc
commit
3bc6d47c31
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable, inject } from '@angular/core';
|
import { Injectable, inject, untracked } from '@angular/core';
|
||||||
import { UiModalRef, UiModalService } from '@ui/modal';
|
import { UiModalRef, UiModalService } from '@ui/modal';
|
||||||
import { PurchaseOptionsModalComponent } from './purchase-options-modal.component';
|
import { PurchaseOptionsModalComponent } from './purchase-options-modal.component';
|
||||||
import {
|
import {
|
||||||
@@ -10,6 +10,8 @@ import {
|
|||||||
Customer,
|
Customer,
|
||||||
CrmTabMetadataService,
|
CrmTabMetadataService,
|
||||||
} from '@isa/crm/data-access';
|
} from '@isa/crm/data-access';
|
||||||
|
import { TabService } from '@isa/core/tabs';
|
||||||
|
import { BranchDTO } from '@generated/swagger/checkout-api';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service for opening and managing the Purchase Options Modal.
|
* Service for opening and managing the Purchase Options Modal.
|
||||||
@@ -35,6 +37,7 @@ import {
|
|||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class PurchaseOptionsModalService {
|
export class PurchaseOptionsModalService {
|
||||||
#uiModal = inject(UiModalService);
|
#uiModal = inject(UiModalService);
|
||||||
|
#tabService = inject(TabService);
|
||||||
#crmTabMetadataService = inject(CrmTabMetadataService);
|
#crmTabMetadataService = inject(CrmTabMetadataService);
|
||||||
#customerFacade = inject(CustomerFacade);
|
#customerFacade = inject(CustomerFacade);
|
||||||
|
|
||||||
@@ -71,6 +74,7 @@ export class PurchaseOptionsModalService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
context.selectedCustomer = await this.#getSelectedCustomer(data);
|
context.selectedCustomer = await this.#getSelectedCustomer(data);
|
||||||
|
context.selectedBranch = this.#getSelectedBranch(data.tabId);
|
||||||
return this.#uiModal.open<string, PurchaseOptionsModalContext>({
|
return this.#uiModal.open<string, PurchaseOptionsModalContext>({
|
||||||
content: PurchaseOptionsModalComponent,
|
content: PurchaseOptionsModalComponent,
|
||||||
data: context,
|
data: context,
|
||||||
@@ -90,4 +94,25 @@ export class PurchaseOptionsModalService {
|
|||||||
|
|
||||||
return this.#customerFacade.fetchCustomer({ customerId });
|
return this.#customerFacade.fetchCustomer({ customerId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#getSelectedBranch(tabId: number): BranchDTO | undefined {
|
||||||
|
const tab = untracked(() =>
|
||||||
|
this.#tabService.entities().find((t) => t.id === tabId),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!tab) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const legacyProcessData = tab?.metadata?.process_data;
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof legacyProcessData === 'object' &&
|
||||||
|
'selectedBranch' in legacyProcessData
|
||||||
|
) {
|
||||||
|
return legacyProcessData.selectedBranch as BranchDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,19 +31,12 @@ export class PurchaseOptionsService {
|
|||||||
private _checkoutService: DomainCheckoutService,
|
private _checkoutService: DomainCheckoutService,
|
||||||
private _omsService: DomainOmsService,
|
private _omsService: DomainOmsService,
|
||||||
private _auth: AuthService,
|
private _auth: AuthService,
|
||||||
private _app: ApplicationService,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
getVats$() {
|
getVats$() {
|
||||||
return this._omsService.getVATs();
|
return this._omsService.getVATs();
|
||||||
}
|
}
|
||||||
|
|
||||||
getSelectedBranchForProcess(processId: number): Observable<Branch> {
|
|
||||||
return this._app
|
|
||||||
.getSelectedBranch$(processId)
|
|
||||||
.pipe(take(1), shareReplay(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
getCustomerFeatures(processId: number): Observable<Record<string, string>> {
|
getCustomerFeatures(processId: number): Observable<Record<string, string>> {
|
||||||
return this._checkoutService
|
return this._checkoutService
|
||||||
.getCustomerFeatures({ processId })
|
.getCustomerFeatures({ processId })
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import {
|
|||||||
OrderTypeFeature,
|
OrderTypeFeature,
|
||||||
Promotion,
|
Promotion,
|
||||||
} from '@isa/checkout/data-access';
|
} from '@isa/checkout/data-access';
|
||||||
|
import { ensureCurrencyDefaults } from '@isa/common/data-access';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
||||||
@@ -1068,7 +1069,7 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
|||||||
throw new Error('Invalid item');
|
throw new Error('Invalid item');
|
||||||
}
|
}
|
||||||
|
|
||||||
const price = this.getPriceForPurchaseOption(itemId, this.purchaseOption);
|
let price = this.getPriceForPurchaseOption(itemId, this.purchaseOption);
|
||||||
const availability = this.getAvailabilityWithPurchaseOption(
|
const availability = this.getAvailabilityWithPurchaseOption(
|
||||||
itemId,
|
itemId,
|
||||||
purchaseOption,
|
purchaseOption,
|
||||||
@@ -1086,9 +1087,15 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
|||||||
// Set loyalty points from item
|
// Set loyalty points from item
|
||||||
loyalty = { value: redemptionPoints };
|
loyalty = { value: redemptionPoints };
|
||||||
// Set price to 0
|
// Set price to 0
|
||||||
price.value.value = 0;
|
price = ensureCurrencyDefaults({
|
||||||
price.value.currency = 'EUR';
|
...price,
|
||||||
price.value.currencySymbol = '€';
|
value: {
|
||||||
|
...price.value,
|
||||||
|
value: 0,
|
||||||
|
currency: 'EUR',
|
||||||
|
currencySymbol: '€',
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let destination: EntityDTOContainerOfDestinationDTO;
|
let destination: EntityDTOContainerOfDestinationDTO;
|
||||||
@@ -1126,7 +1133,7 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
|||||||
if (!isShoppingCartItemDTO(item, this.type)) {
|
if (!isShoppingCartItemDTO(item, this.type)) {
|
||||||
throw new Error('Invalid item');
|
throw new Error('Invalid item');
|
||||||
}
|
}
|
||||||
const price = this.getPriceForPurchaseOption(itemId, this.purchaseOption);
|
let price = this.getPriceForPurchaseOption(itemId, this.purchaseOption);
|
||||||
const availability = this.getAvailabilityWithPurchaseOption(
|
const availability = this.getAvailabilityWithPurchaseOption(
|
||||||
itemId,
|
itemId,
|
||||||
purchaseOption,
|
purchaseOption,
|
||||||
@@ -1135,9 +1142,15 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
|
|||||||
// If loyalty points is set we know it is a redemption item
|
// If loyalty points is set we know it is a redemption item
|
||||||
// we need to make sure we don't update the price
|
// we need to make sure we don't update the price
|
||||||
if (this.useRedemptionPoints) {
|
if (this.useRedemptionPoints) {
|
||||||
price.value.value = 0;
|
price = ensureCurrencyDefaults({
|
||||||
price.value.currency = 'EUR';
|
...price,
|
||||||
price.value.currencySymbol = '€';
|
value: {
|
||||||
|
...price.value,
|
||||||
|
value: 0,
|
||||||
|
currency: 'EUR',
|
||||||
|
currencySymbol: '€',
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let destination: EntityDTOContainerOfDestinationDTO;
|
let destination: EntityDTOContainerOfDestinationDTO;
|
||||||
|
|||||||
Reference in New Issue
Block a user