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)