From 1cebb09849be23433ce84b28c259679b0994c84e Mon Sep 17 00:00:00 2001 From: gofnnp Date: Tue, 8 Nov 2022 10:36:41 +0400 Subject: [PATCH] =?UTF-8?q?dev=20#12928=20=D0=B4=D0=BE=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D0=BB=20=D0=BA=D0=BE=D1=80=D0=B7=D0=B8=D0=BD?= =?UTF-8?q?=D1=83=20=D0=BF=D0=BE=D0=B4=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D1=83=20=D1=81=20=D1=82=D0=B5=D1=80=D0=BC=D0=B8=D0=BD=D0=B0?= =?UTF-8?q?=D0=BB=D0=B0=D0=BC=D0=B8,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BE=D1=87=D0=B8=D1=81=D1=82=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BA=D0=BE=D1=80=D0=B8=D0=B7=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/app/pages/cart/cart.component.html | 25 +++++++++++++++++-- .../src/app/pages/cart/cart.component.scss | 10 ++++++++ angular/src/app/pages/cart/cart.component.ts | 18 ++++++++++++- angular/src/app/services/cart.service.ts | 7 ++++++ angular/src/app/services/order.service.ts | 8 ++++-- 5 files changed, 63 insertions(+), 5 deletions(-) diff --git a/angular/src/app/pages/cart/cart.component.html b/angular/src/app/pages/cart/cart.component.html index 49b63c4..c8cac11 100644 --- a/angular/src/app/pages/cart/cart.component.html +++ b/angular/src/app/pages/cart/cart.component.html @@ -3,8 +3,7 @@
-
@@ -53,6 +52,9 @@

+
@@ -68,6 +70,25 @@
+ + +
+
+ +

{{message.summary}}

+

{{message.detail}}

+
+
+
+ +
+
+ +
+
+
+
+
diff --git a/angular/src/app/pages/cart/cart.component.scss b/angular/src/app/pages/cart/cart.component.scss index a22c9ae..24616e0 100644 --- a/angular/src/app/pages/cart/cart.component.scss +++ b/angular/src/app/pages/cart/cart.component.scss @@ -202,4 +202,14 @@ margin: 14px auto; border-top: solid #d1d1d1 1px; } + + .clear-cart { + padding: 8px; + border: none; + border-radius: 4px; + background: #d7120b; + color: #fff; + margin: 32px auto; + display: block; + } } \ No newline at end of file diff --git a/angular/src/app/pages/cart/cart.component.ts b/angular/src/app/pages/cart/cart.component.ts index b3f3465..93fef85 100644 --- a/angular/src/app/pages/cart/cart.component.ts +++ b/angular/src/app/pages/cart/cart.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit } from '@angular/core'; +import { MessageService } from 'primeng/api'; import { Order } from 'src/app/models/order'; import { OrderProduct } from 'src/app/models/order-product'; import { CartService, ProductAmountAction } from 'src/app/services/cart.service'; @@ -17,7 +18,8 @@ export class CartComponent implements OnInit { constructor( private orderService: OrderService, - private cartService: CartService + private cartService: CartService, + private messageService: MessageService, ) { } ngOnInit(): void { @@ -58,4 +60,18 @@ export class CartComponent implements OnInit { } + confirmClearCart() { + this.messageService.add({ key: 'c', sticky: true, severity: 'warn', summary: 'Вы уверены, что хотите очистить корзину?' }); + } + + onReject() { + this.messageService.clear('c'); + } + + onConfirm() { + this.cartService.clearCart() + this.loadCart() + this.messageService.clear('c'); + } + } diff --git a/angular/src/app/services/cart.service.ts b/angular/src/app/services/cart.service.ts index 5d407ac..c77e68f 100644 --- a/angular/src/app/services/cart.service.ts +++ b/angular/src/app/services/cart.service.ts @@ -26,6 +26,8 @@ export class CartService { public cartCount$ = new Subject(); + public selectedTerminal$ = new Subject(); + getCart(){ return this._getCartProducts(); @@ -89,6 +91,11 @@ export class CartService { this.cartCount$.next(cart.products.length); } + changeTerminal(terminal: any) { + this.cookieService.setCookie('selectedTerminal', JSON.stringify(terminal)); + this.selectedTerminal$.next(terminal) + } + clearCart(){ this.cart = {products: []}; this.cookieService.setCookie('cart', JSON.stringify(this.cart)); diff --git a/angular/src/app/services/order.service.ts b/angular/src/app/services/order.service.ts index a9b8eb9..04790b6 100644 --- a/angular/src/app/services/order.service.ts +++ b/angular/src/app/services/order.service.ts @@ -52,13 +52,17 @@ export class OrderService { const info = await lastValueFrom(forkJoin([additionalInfo, tokenData, products])); const token = this.cookiesService.getItem('token') this.order = new Order({products: products, userData: info[0]?.data, phone: info[1].data?.mobile_number, token: token}); + } else if (this.order) { + this.order.products.length = 0 } } return this.order; + } - async getProducts(cart: Cart): Promise { - const allData = await lastValueFrom(this.wpJsonService.getAllData()) + async getProducts(cart: Cart): Promise { + const terminal = JSON.parse(this.cookiesService.getItem('selectedTerminal') || 'null') || this.cartService.selectedTerminal$ + const allData = await lastValueFrom(this.wpJsonService.getAllData(`${terminal.label}${terminal.id}`)) const products: OrderProduct[] = [] for (let i = 0; i < cart.products.length; i++) { const productSub = allData.products.find((product: any) => product.id === cart.products[i].id)