#1323 Dialog um Hindernismeldung erweitern

Co-authored-by: n.righi@paragon-data.de <n.righi@paragon-data.de>
This commit is contained in:
Lorenz Hilpert
2021-01-25 13:39:42 +01:00
parent 4d1350dc97
commit c999697645
9 changed files with 108 additions and 38 deletions

View File

@@ -13,7 +13,7 @@ export class CartService {
throw new Error('Not Implemented');
}
getCardId(processId: number): Observable<number> {
getCartId(processId: number): Observable<number> {
throw new Error('Not Implemented');
}

View File

@@ -133,9 +133,9 @@ export class CustomerDetailsComponent implements OnInit {
this.process.updateName(this.application.activatedProcessId, customer.lastName);
// Set Customer For Process
const customerAdded: any = await this.checkoutService.setCustomer(this.application.activatedProcessId, customer);
if (!customerAdded.ok) {
this.modal.open({ content: UiDebugModalComponent, data: customerAdded });
const canAdd = await this.checkoutService.setCustomer(this.application.activatedProcessId, customer);
if (!canAdd) {
return;
}

View File

@@ -98,7 +98,8 @@
<div class="modal-step-2" *ngIf="!stepOne || isDownload">
<div class="header">
<h1>Artikel wurde dem Warenkorb hinzugefügt</h1>
<h1 *ngIf="canAddItem">Artikel wurde dem Warenkorb hinzugefügt</h1>
<h1 *ngIf="!canAddItem">Artikel kann dem Warenkorb nicht hinzugefügt werden</h1>
<lib-icon (click)="closeModal()" class="close-icon" height="21px" name="close" alt="close"></lib-icon>
</div>
<div class="modal-body">
@@ -123,8 +124,10 @@
<div class="product-information">
<span class="book-title">{{ book.product.contributors }} - {{ book.product.name }}</span>
<span>
<span class="can-add-hint" *ngIf="!canAddItem"
>Leider können wir den Service mit den bereits ausgewählten Services im Warenkorb nicht kombinieren.</span
>
<span class="book-format">
<lib-icon class="order-book-icon" width="18px" height="18px" name="Icon_{{ book.product.format }}" alt="book-icon"></lib-icon>
{{ book.product.formatDetail }}
</span>

View File

@@ -172,7 +172,7 @@
// SECOND STEP DESIGN
.modal-step-2 {
height: 420px;
height: auto;
justify-content: flex-start;
.header {
@@ -244,7 +244,15 @@
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
margin-bottom: 25px;
}
.book-format {
margin-top: 25px;
}
.can-add-hint {
@apply text-dark-goldenrod text-card-sub;
margin-top: 8px;
}
.order-book-icon {
@@ -327,7 +335,6 @@
align-items: center;
width: 93%;
margin-top: 25px;
margin-bottom: 20px;
}
.img-truck-b2b {

View File

@@ -88,6 +88,8 @@ export class ProductCheckoutComponent implements OnInit, OnDestroy {
confirmationBtnText = 'Fortfahren';
canAddItem: boolean = true;
// Trigger other functionality if needed
@Output() closed: EventEmitter<boolean> = new EventEmitter();
@@ -513,13 +515,13 @@ export class ProductCheckoutComponent implements OnInit, OnDestroy {
map((response) => {
if (response && response.av) {
const preferredSupplier = response.av.find((av) => av && av.preferred === 1);
if (preferredSupplier) {
this.currentAvailability = preferredSupplier;
this.checkCanAdd();
this._pikUpPrice = preferredSupplier.price.value.value;
}
this.shoppingCartService.canAddItem(undefined, this.currentAvailability);
const eligibleAvailabilities = response.av
.filter((availability) => allowedAvailabilityStatusCodes(availability.status) && availability.qty)
.map((availability) => availability.qty);
@@ -546,6 +548,7 @@ export class ProductCheckoutComponent implements OnInit, OnDestroy {
let preferredQty = 0;
if (preferedAv) {
this.currentAvailability = preferedAv;
this.checkCanAdd();
this._deliveryPrice = preferedAv.price.value.value;
if (allowedAvailabilityStatusCodes(preferedAv.status)) {
preferredQty = preferedAv.qty;
@@ -564,14 +567,43 @@ export class ProductCheckoutComponent implements OnInit, OnDestroy {
return shippingAvailability;
} else if (this.deliveryType === DeliveryOption.DELIVERY_B2B) {
// TODO: Logik für Verfügbarkeit prüfen
const shippingB2bAvailability = await this.productAvailabilityService
.getShippingB2BAvailability(this.book, this.book.product.ean, +this.selectedBranch.branchNumber, numberOfItems)
.pipe(
map((response) => {
if (response && response.av) {
const preferedAv = response.av.find((t) => t && t.preferred === 1);
let preferredQty = 0;
if (preferedAv) {
this.currentAvailability = preferedAv;
this.checkCanAdd();
this._deliveryPrice = preferedAv.price.value.value;
if (allowedAvailabilityStatusCodes(preferedAv.status)) {
preferredQty = preferedAv.qty;
}
this.detectChanges();
}
if (preferredQty) {
return preferredQty;
}
return 0;
}
return 0;
})
)
.toPromise();
return shippingB2bAvailability;
}
this.shoppingCartService
.canAddItem(undefined, this.currentAvailability)
.then((result) => this.uiModal.open({ content: UiDebugModalComponent, data: { canAddItem: result } }));
return of(numberOfItems).toPromise();
}
async checkCanAdd() {
// TODO: Hindernissmeldung
this.canAddItem = await this.shoppingCartService.canAddItem(undefined, this.currentAvailability);
}
updateCart() {
this.store.dispatch(
new SetCartEntry(

View File

@@ -9,9 +9,19 @@ import { OLAAvailabilityDTO, StoreCheckoutService } from '@swagger/checkout';
import { CustomerSelectors } from '../core/store/selectors/customer.selectors';
import { StringDictionary } from '@cmf/core';
import { ApplicationService } from '@core/application';
import { CrmCustomerService } from '@domain/crm';
import { CustomerDTO } from '@swagger/crm';
import { UiDebugModalComponent, UiModalService } from '@ui/modal';
@Injectable()
export class CartRefactImp implements CartService {
constructor(private store: Store, private checkoutService: StoreCheckoutService, private applicationService: ApplicationService) {}
constructor(
private store: Store,
private checkoutService: StoreCheckoutService,
private applicationService: ApplicationService,
private customerService: CrmCustomerService,
private uiModal: UiModalService
) {}
getItems(processId: number): Observable<CartItem[]> {
return this.store.select(SharedSelectors.getCart).pipe(
@@ -41,12 +51,12 @@ export class CartRefactImp implements CartService {
);
}
getCardId(processId: number): Observable<number> {
getCartId(processId: number): Observable<number> {
return this.store.select(ProcessSelectors.getCurrentProcess).pipe(map((process) => process.cartId));
}
getRequiredCustomerTypes(processId: number): Observable<any> {
// return this.getCardId(processId).pipe(
// return this.getCartId(processId).pipe(
// switchMap((cartId) => {
// return this.checkoutService
// .StoreCheckoutCanAddBuyer({ shoppingCartId: cartId, payload: { customerFeatures: {} } })
@@ -94,37 +104,43 @@ export class CartRefactImp implements CartService {
}
async canAddItem(processId: number, availability: OLAAvailabilityDTO): Promise<boolean> {
const customer$ = await this.store.select(CustomerSelectors.getActiveUser).pipe(first()).toPromise();
const features$ = await this.store.select(CustomerSelectors.getCustomerFeatures).pipe(first()).toPromise();
const getCustomerIdByProcessIdFn = await this.store.select(CustomerSelectors.getActiveUser).pipe(first()).toPromise();
console.log({ processId }, { activatedProcessId: this.applicationService.activatedProcessId });
let customerId: number;
try {
customerId = getCustomerIdByProcessIdFn(processId || this.applicationService.activatedProcessId)?.id;
} catch (error) {}
const customerId = customer$(processId || this.applicationService.activatedProcessId)?.id;
console.log({ customerId });
let customer: CustomerDTO;
if (customerId) {
customer = await this.customerService
.getCustomer(customerId)
.pipe(map((res) => res.result))
.toPromise();
}
const customerFeatures: StringDictionary<string> = {};
if (customerId) {
const features = features$(customerId);
console.log({ features });
for (const feature of features) {
for (const feature of customer.features) {
customerFeatures[feature.key] = feature.key;
}
}
this.getCardId(processId || this.applicationService.activatedProcessId)
return this.getCartId(processId || this.applicationService.activatedProcessId)
.pipe(
first(),
switchMap((cartId) => {
return this.checkoutService
.StoreCheckoutCanAddItem({ shoppingCartId: cartId, payload: { customerFeatures, availabilities: [availability] } })
.pipe(tap((res) => console.log(res)));
.pipe(
map((res) => {
this.uiModal.open({ content: UiDebugModalComponent, data: res });
return res.result.ok;
})
);
})
)
.toPromise();
return false;
}
}

View File

@@ -5,9 +5,10 @@ import { CheckoutService } from '@domain/checkout';
import { Store } from '@ngxs/store';
import { PayerDTO, PayerType, ShippingAddressDTO, StoreCheckoutService } from '@swagger/checkout';
import { CustomerDTO, PayerDTO as CrmPayerDTO, ShippingAddressDTO as CrmShippingAddressDTO } from '@swagger/crm';
import { UiDebugModalComponent, UiModalService } from '@ui/modal';
import { Observable } from 'rxjs';
import { first, mergeMap } from 'rxjs/operators';
import { first, map, mergeMap } from 'rxjs/operators';
import {
RefactSetCustomer,
RefactSetCustomerBillingAddress,
@@ -18,11 +19,16 @@ import { CustomerSelectors } from '../core/store/selectors/customer.selectors';
@Injectable()
export class CheckoutRefactImp implements CheckoutService {
constructor(private store: Store, private checkoutService: StoreCheckoutService, private cartService: CartService) {}
constructor(
private store: Store,
private checkoutService: StoreCheckoutService,
private cartService: CartService,
private uiModal: UiModalService
) {}
async setCustomer(processId: number, customer: CustomerDTO): Promise<boolean> {
const response = await this.cartService
.getCardId(processId)
.getCartId(processId)
.pipe(
first(),
mergeMap((shoppingCartId) => {
@@ -39,7 +45,12 @@ export class CheckoutRefactImp implements CheckoutService {
this.store.dispatch(new SetActiveCustomer(customer.id));
this.store.dispatch(new RefactSetCustomer(customer));
}
return response.result as any;
if (!response.result.ok) {
this.uiModal.open({ content: UiDebugModalComponent, data: response });
}
return response.result.ok;
}
getCustomer(processId: number): Observable<CustomerDTO> {

View File

@@ -3,7 +3,7 @@ import { UiModalRef } from './defs';
@Component({
selector: 'ui-debug-modal',
template: `{{ modalRef.data | json }}`,
template: `<pre> {{ modalRef.data | json }} </pre>`,
})
export class UiDebugModalComponent implements OnInit {
constructor(public modalRef: UiModalRef) {}

View File

@@ -78,6 +78,7 @@ module.exports = {
'active-branch': '#596470',
'inactive-branch': '#9ca5b0',
'disabled-branch': '#c6cbd2',
'dark-goldenrod': '#be8100',
},
boxShadow: {
input: '0 6px 24px 0 rgba(214, 215, 217, 0.8)',