#1530 Bugfix Update ShippingAddress on Multiple Destinations B2B With Target 2 and 16

This commit is contained in:
Nino Righi
2021-03-15 18:04:59 +01:00
committed by Lorenz Hilpert
parent 699fd7db45
commit 424939b5f3
2 changed files with 19 additions and 11 deletions

View File

@@ -13,6 +13,7 @@ import {
PayerDTO,
PaymentDTO,
PaymentType,
ResponseArgsOfDestinationDTO,
ShippingAddressDTO,
ShoppingCartDTO,
StoreCheckoutService,
@@ -21,7 +22,7 @@ import {
import { InputDTO } from '@swagger/crm';
import { DisplayOrderDTO, OrderCheckoutService } from '@swagger/oms';
import { isNullOrUndefined, memorize } from '@utils/common';
import { combineLatest, EMPTY, Observable, of } from 'rxjs';
import { combineLatest, EMPTY, Observable, of, zip } from 'rxjs';
import { filter, first, map, mergeMap, shareReplay, takeWhile, tap, withLatestFrom } from 'rxjs/operators';
import * as DomainCheckoutSelectors from './store/domain-checkout.selectors';
@@ -350,7 +351,7 @@ export class DomainCheckoutService {
const shippingAddressDestination$ = this.getCheckout({ processId }).pipe(
first(),
map((checkout) => checkout?.destinations?.find((dest) => dest.data.target === 2 || dest.data.target === 16)),
map((checkout) => checkout?.destinations?.filter((dest) => dest.data.target === 2 || dest.data.target === 16)),
shareReplay()
);
@@ -390,16 +391,22 @@ export class DomainCheckoutService {
shippingAddressDestination$,
this.getShippingAddress({ processId }).pipe(first()),
]).pipe(
mergeMap(([checkout, destination, shippingAddress]) => {
if (destination) {
const updatedDestination: DestinationDTO = { ...destination.data, shippingAddress: { ...shippingAddress } };
return this.storeCheckoutService.StoreCheckoutUpdateDestination({
checkoutId: checkout.id,
destinationId: destination.id,
destinationDTO: updatedDestination,
mergeMap(([checkout, destinations, shippingAddress]) => {
const obs: Observable<ResponseArgsOfDestinationDTO>[] = [];
if (destinations) {
destinations.forEach((destination) => {
const updatedDestination: DestinationDTO = { ...destination.data, shippingAddress: { ...shippingAddress } };
obs.push(
this.storeCheckoutService.StoreCheckoutUpdateDestination({
checkoutId: checkout.id,
destinationId: destination.id,
destinationDTO: updatedDestination,
})
);
});
return zip(...obs);
}
return of(destination);
return of(destinations);
}),
shareReplay()
);

View File

@@ -50,7 +50,8 @@ export class CheckoutReviewComponent {
takeUntil(this._orderCompleted),
map((items) =>
items.reduce((grouped, item) => {
let index = grouped.findIndex((g) => g?.orderType === item?.features?.orderType && g.destination?.id === item?.destination?.id);
// let index = grouped.findIndex((g) => g?.orderType === item?.features?.orderType && g.destination?.id === item?.destination?.id);
let index = grouped.findIndex((g) => g?.orderType === item?.features?.orderType);
let group = index !== -1 ? grouped[index] : undefined;
if (!group) {
group = { orderType: item.features.orderType, destination: item.destination?.data, items: [] };