diff --git a/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.ts b/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.ts index e23805d..f9a10de 100644 --- a/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.ts +++ b/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.ts @@ -45,7 +45,7 @@ export class GuestCardComponent implements OnInit { .subscribe({ next: (value) => { this.customerInfo = value.customer_info; - this.cookiesService.setCookie('phone-number', this.customerInfo.phone.substr(2)) + this.cookiesService.setCookie('phone-number', this.customerInfo?.phone?.substr(2)) this.getPurchases().subscribe((value) => { this.purchases = this.loyaltyProgram.filterPurchases(value[this.customerInfo?.id]) this.lastPurchase = this.loyaltyProgram.getLastPurchase(this.purchases) diff --git a/angular/src/app/services/loyalty-program.service.ts b/angular/src/app/services/loyalty-program.service.ts index 8ffa6a3..f6646d7 100644 --- a/angular/src/app/services/loyalty-program.service.ts +++ b/angular/src/app/services/loyalty-program.service.ts @@ -109,6 +109,9 @@ export class LoyaltyProgramService { getBalanceAmount(loyaltyPrograms: any[]) { return (loyaltyPrograms || []).reduce((accumulator, currentValue) => { + if (currentValue.wallet.name !== 'Федеральная программа лояльности') { + return accumulator + } return accumulator + currentValue.balance; }, 0); } diff --git a/angular/src/app/services/wp-json.service.ts b/angular/src/app/services/wp-json.service.ts index 4e91efe..534cb02 100644 --- a/angular/src/app/services/wp-json.service.ts +++ b/angular/src/app/services/wp-json.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import {environment} from "../../environments/environment"; import {HttpClient, HttpHeaders} from "@angular/common/http"; import {CookiesService} from "./cookies.service"; -import {Observable} from "rxjs"; +import {Observable, of, switchMap} from "rxjs"; import {JsonRpcBody} from "./jsonrpc.service"; import {DeliveryType, AcceptedOrder, Product} from "../interface/data"; import {ActivatedRoute} from "@angular/router"; @@ -43,7 +43,21 @@ export class WpJsonService { } getCustomerInfo(systemId: string, token: string, url: string): Observable { - return this._request(`customer_info/${systemId}/${token}/`, 'GET', null, false, url) + return this._request(`customer_info/${systemId}/${token}/`, 'GET', null, false, url).pipe( + switchMap((response) => { + if (response.customer_info.errorCode !== 'Customer_CustomerNotFound') { + return of(response) + } else { + return this.newCustomer(systemId, token, url).pipe( + switchMap(() => this.getCustomerInfo(systemId, token, url)) + ) + } + }) + ) + } + + newCustomer(systemId: string, token: string, url: string): Observable { + return this._request(`new_customer/${systemId}/${token}/`, 'GET', null, false, url) } getTransactions(systemId: string, token: string, url: string, delta?: number): Observable {