dev #12928
доработал корзину под работу с терминалами, добавил очистку коризны
This commit is contained in:
parent
266601e59b
commit
1cebb09849
@ -3,8 +3,7 @@
|
||||
<div class="elementor-menu-cart__products woocommerce-mini-cart cart woocommerce-cart-form__contents"
|
||||
[ngStyle]="{margin: !order.products.length && 0}">
|
||||
<div *ngFor="let product of order.products; let last = last">
|
||||
<div
|
||||
class="elementor-menu-cart__product woocommerce-cart-form__cart-item cart_item"
|
||||
<div class="elementor-menu-cart__product woocommerce-cart-form__cart-item cart_item"
|
||||
style="grid-template-columns: 70px auto;">
|
||||
|
||||
<div class="elementor-menu-cart__product-image product-thumbnail">
|
||||
@ -53,6 +52,9 @@
|
||||
</div>
|
||||
<hr *ngIf="!last">
|
||||
</div>
|
||||
<button *ngIf="order.products.length != 0" class="clear-cart" (click)="confirmClearCart()">
|
||||
Очистить корзину
|
||||
</button>
|
||||
</div>
|
||||
<div *ngIf="order.products.length != 0" class="elementor-menu-cart__bottom-info">
|
||||
<div class="elementor-menu-cart__subtotal">
|
||||
@ -68,6 +70,25 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p-toast position="bottom-center" key="c" (onClose)="onReject()" [baseZIndex]="5000">
|
||||
<ng-template let-message pTemplate="message">
|
||||
<div class="flex flex-column" style="flex: 1">
|
||||
<div class="text-center">
|
||||
<i class="pi pi-exclamation-triangle" style="font-size: 3rem"></i>
|
||||
<h4>{{message.summary}}</h4>
|
||||
<p style="font-weight: 600;">{{message.detail}}</p>
|
||||
</div>
|
||||
<div class="grid p-fluid">
|
||||
<div class="col-6">
|
||||
<button type="button" pButton (click)="onConfirm()" label="Да" class="p-button-success">Да</button>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<button type="button" pButton (click)="onReject()" label="Нет" class="p-button-secondary">Нет</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-toast>
|
||||
</div>
|
||||
|
||||
<app-user-data-order *ngIf="orderConfirmed" (orderSubmitted)="orderSubmitted()"></app-user-data-order>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -26,6 +26,8 @@ export class CartService {
|
||||
|
||||
public cartCount$ = new Subject<number>();
|
||||
|
||||
public selectedTerminal$ = new Subject<Object>();
|
||||
|
||||
|
||||
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));
|
||||
|
||||
@ -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<OrderProduct[]> {
|
||||
const allData = await lastValueFrom(this.wpJsonService.getAllData())
|
||||
async getProducts(cart: Cart): Promise<OrderProduct[]> {
|
||||
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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user