parent
a6c0f98ec6
commit
673afcf2b1
@ -55,3 +55,40 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-toast
|
||||
position="bottom-center"
|
||||
key="cC"
|
||||
(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>
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
'auth-page': showAuthoriztion
|
||||
}"
|
||||
>
|
||||
<button class="logout" color="warn" mat-stroked-button (click)="logout()">Выйти</button>
|
||||
<button *ngIf="!showAuthoriztion" class="logout" color="warn" mat-stroked-button (click)="logout()">Выйти</button>
|
||||
<div *ngIf="!showAuthoriztion; else authEl" class="account-page">
|
||||
<div *ngIf="showAuthoriztion" class="top-left-attribute"></div>
|
||||
<app-bonus-program
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<button mat-stroked-button [disabled]="!!cartService.cartCount" (click)="showTerminals()">
|
||||
<button mat-stroked-button (click)="showTerminals()">
|
||||
{{ selectedTerminal.label }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user