From 6c283812e7a05e02dd3c6ec938edb5cbb58fef22 Mon Sep 17 00:00:00 2001 From: gofnnp Date: Wed, 17 May 2023 12:12:25 +0400 Subject: [PATCH] =?UTF-8?q?dev=20#14318=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8E=20=D1=8E=D0=B7=D0=B5=D1=80=D0=B0=20=D0=B2=20?= =?UTF-8?q?=D0=B0=D0=B9=D0=BA=D0=BE=D0=BA=D0=B0=D1=80=D0=B4,=20=D0=B5?= =?UTF-8?q?=D1=81=D0=BB=D0=B8=20=D0=B5=D0=B3=D0=BE=20=D0=BD=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/guest-card/guest-card.component.html | 2 +- .../pages/guest-card/guest-card.component.ts | 2 +- .../app/services/loyalty-program.service.ts | 3 +++ angular/src/app/services/wp-json.service.ts | 18 ++++++++++++++++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.html b/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.html index dce7733..c628b48 100644 --- a/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.html +++ b/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.html @@ -15,7 +15,7 @@
{ 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 f78813d..1aded35 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 {