This commit is contained in:
sdarbinyan
2026-06-21 23:13:01 +04:00
parent 1b2a5af2be
commit 3b802b7c7b
13 changed files with 510 additions and 33 deletions

View File

@@ -3,9 +3,10 @@ import { DecimalPipe } from '@angular/common';
import { Router, RouterLink } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { CartService, ApiService, LanguageService, AuthService } from '../../services';
import { Item, CartItem } from '../../models';
import { Item, CartItem, DeliveryOption } from '../../models';
import { interval, of, Subscription } from 'rxjs';
import { catchError, exhaustMap, take, timeout } from 'rxjs/operators';
import { DeliverySelectorComponent } from '../../components/delivery-selector/delivery-selector.component';
import { EmptyCartIconComponent } from '../../components/empty-cart-icon/empty-cart-icon.component';
import { TelegramLoginComponent } from '../../components/telegram-login/telegram-login.component';
import { environment } from '../../../environments/environment';
@@ -17,7 +18,7 @@ import { PAYMENT_POLL_INTERVAL_MS, PAYMENT_MAX_CHECKS, PAYMENT_TIMEOUT_CLOSE_MS,
@Component({
selector: 'app-cart',
imports: [DecimalPipe, RouterLink, FormsModule, EmptyCartIconComponent, TelegramLoginComponent, LangRoutePipe, TranslatePipe],
imports: [DecimalPipe, RouterLink, FormsModule, EmptyCartIconComponent, DeliverySelectorComponent, TelegramLoginComponent, LangRoutePipe, TranslatePipe],
templateUrl: './cart.component.html',
styleUrls: ['./cart.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
@@ -29,6 +30,7 @@ export class CartComponent implements OnDestroy {
totalDeliveryPrice;
totalWithDelivery;
hasDeliveryPrice;
allRequiredDeliveriesSelected;
termsAccepted = false;
isnovo = environment.theme === 'novo';
@@ -74,6 +76,7 @@ export class CartComponent implements OnDestroy {
this.totalDeliveryPrice = this.cartService.totalDeliveryPrice;
this.totalWithDelivery = this.cartService.totalWithDelivery;
this.hasDeliveryPrice = this.cartService.hasDeliveryPrice;
this.allRequiredDeliveriesSelected = this.cartService.allRequiredDeliveriesSelected;
}
requestLogin(): void {
@@ -148,8 +151,18 @@ export class CartComponent implements OnDestroy {
itemName(item: Item): string { return getTranslatedField(item, 'name', this.langService.currentLanguage()); }
itemDesc(item: Item): string { return getTranslatedField(item, 'simpleDescription', this.langService.currentLanguage()); }
get currentCurrency(): string { return this.langService.currentCurrency(); }
get isCheckoutDisabled(): boolean { return !this.termsAccepted || !this.isAuthenticated() || !this.allRequiredDeliveriesSelected(); }
selectDelivery(itemID: number, selectedDelivery: DeliveryOption | null): void {
this.cartService.setSelectedDelivery(itemID, selectedDelivery);
}
checkout(): void {
if (!this.allRequiredDeliveriesSelected()) {
alert(this.i18n.t('cart.deliveryRequired'));
return;
}
if (!this.termsAccepted) {
alert(this.i18n.t('cart.acceptTerms'));
return;
@@ -348,7 +361,8 @@ export class CartComponent implements OnDestroy {
? item.price * (1 - item.discount / 100)
: item.price,
currency: item.currency,
quantity: item.quantity
quantity: item.quantity,
...(item.selectedDelivery ? { delivery: item.selectedDelivery } : {})
}))
};
@@ -416,7 +430,8 @@ export class CartComponent implements OnDestroy {
? item.price * (1 - item.discount / 100)
: item.price,
currency: item.currency,
quantity: item.quantity
quantity: item.quantity,
...(item.selectedDelivery ? { delivery: item.selectedDelivery } : {})
}))
};
@@ -476,7 +491,7 @@ export class CartComponent implements OnDestroy {
return `order_${timestamp}_${random}`;
}
private buildPaymentItems(): Array<{ itemID: number; price: number; name: string }> {
private buildPaymentItems(): Array<{ itemID: number; price: number; name: string; quantity: number; delivery?: DeliveryOption }> {
return this.items().map((item: CartItem) => {
const unitPrice = item.discount > 0
? item.price * (1 - item.discount / 100)
@@ -489,6 +504,8 @@ export class CartComponent implements OnDestroy {
itemID: item.itemID,
price: unitPrice * item.quantity,
name,
quantity: item.quantity,
...(item.selectedDelivery ? { delivery: item.selectedDelivery } : {}),
};
});
}