From 673afcf2b120015e9ceb831812a95ed1e0c028ab Mon Sep 17 00:00:00 2001 From: gofnnp Date: Tue, 2 May 2023 11:05:23 +0400 Subject: [PATCH] =?UTF-8?q?dev=20#14066=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0=D1=80=D0=BE=D0=B2=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=BD=D1=8B=D1=85=20=D0=B7=D0=B0=D0=B2=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product-modal.component.html | 37 +++++++++++++++++++ .../product-modal/product-modal.component.ts | 24 +++++++++++- .../app/pages/account/account.component.html | 2 +- .../pages/products/products.component.html | 2 +- angular/src/app/services/cart.service.ts | 3 ++ 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/angular/src/app/components/product-modal/product-modal.component.html b/angular/src/app/components/product-modal/product-modal.component.html index 10ae47b..70fc19c 100644 --- a/angular/src/app/components/product-modal/product-modal.component.html +++ b/angular/src/app/components/product-modal/product-modal.component.html @@ -55,3 +55,40 @@ + + + +
+
+ +

{{ message.summary }}

+

{{ message.detail }}

+
+
+
+ +
+
+ +
+
+
+
+
diff --git a/angular/src/app/components/product-modal/product-modal.component.ts b/angular/src/app/components/product-modal/product-modal.component.ts index 5255a9d..f9eed5a 100644 --- a/angular/src/app/components/product-modal/product-modal.component.ts +++ b/angular/src/app/components/product-modal/product-modal.component.ts @@ -6,6 +6,7 @@ import { CartProduct } from 'src/app/models/cart-product'; import { CartService } from 'src/app/services/cart.service'; import { WpJsonService } from 'src/app/services/wp-json.service'; import { ChangeValue } from '../change-quantity/change-quantity.component'; +import { CookiesService } from 'src/app/services/cookies.service'; @Component({ selector: 'app-product-modal', @@ -18,7 +19,8 @@ export class ProductModalComponent implements OnInit { public modifiersGroups!: ModifiersGroup[]; public modifiers!: Modifier[]; public cartProduct!: CartProduct; - public isValidate: boolean = false + public isValidate: boolean = false; + private selectedTerminal: any; constructor( public dialogRef: DynamicDialogRef, @@ -26,12 +28,14 @@ export class ProductModalComponent implements OnInit { private wpJsonService: WpJsonService, private cartService: CartService, private messageService: MessageService, + private cookiesService: CookiesService ) { } ngOnInit(): void { this.product = this.config.data.product this.modifiersGroups = this.config.data.modifiersGroups this.modifiers = this.config.data.modifiers + this.selectedTerminal = this.config.data.selectedTerminal this.cartProduct = new CartProduct(this.product.id, this.product.name, this.modifiersFilter(), this.modifiers, this.product.price); } @@ -93,10 +97,24 @@ export class ProductModalComponent implements OnInit { } + onReject() { + this.messageService.clear('cC'); + } + + onConfirm() { + this.cartService.clearCart() + this.cartService.changeTerminal(this.config.data.selectedTerminal) + this.cartService.addToCart(this.cartProduct); + this.messageService.clear('cC'); + this.dialogRef.close(); + } + addToCart(event: Event) { if (event) { event.preventDefault() } + const cookiesTerminal = JSON.parse(this.cookiesService.getItem('selectedTerminal') || '') + for (let modifiersGroup of this.cartProduct.modifiers) { const isValidModifier = modifiersGroup.allQuantity < modifiersGroup.restrictions.minQuantity if (isValidModifier) { @@ -108,6 +126,10 @@ export class ProductModalComponent implements OnInit { return } } + if (this.selectedTerminal.id !== cookiesTerminal?.id) { + this.messageService.add({ key: 'cC', sticky: true, severity: 'warn', summary: 'В заказе могут быть товары только из одного магазина, очистить корзину для создания нового заказа?' }); + return + } this.cartService.changeTerminal(this.config.data.selectedTerminal) this.cartService.addToCart(this.cartProduct); this.dialogRef.close(); diff --git a/angular/src/app/pages/account/account.component.html b/angular/src/app/pages/account/account.component.html index d46f1c2..424be70 100644 --- a/angular/src/app/pages/account/account.component.html +++ b/angular/src/app/pages/account/account.component.html @@ -4,7 +4,7 @@ 'auth-page': showAuthoriztion }" > - +
- diff --git a/angular/src/app/services/cart.service.ts b/angular/src/app/services/cart.service.ts index a3cfd3c..728dfd9 100644 --- a/angular/src/app/services/cart.service.ts +++ b/angular/src/app/services/cart.service.ts @@ -91,6 +91,9 @@ export class CartService { } changeTerminal(terminal: any) { + if (this.cartCount) { + return; + } this.cookieService.setCookie('selectedTerminal', JSON.stringify(terminal)); this.selectedTerminal$.next(terminal) }