1
0
mirror of synced 2024-11-25 06:46:08 +03:00

ref #91505 Исправлены ошибки при работе с программой лояльности (#313)

This commit is contained in:
Uryvskiy Dima 2023-09-01 10:10:38 +03:00 committed by GitHub
parent 4f438b6f0f
commit 0a6c409e11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 262 additions and 90 deletions

View File

@ -1,3 +1,6 @@
## 2023-08-31 v.6.4.4
- Исправлены ошибки при работе с программой лояльности
## 2023-08-29 v.6.4.3
- Добавлена валидация валют при установке и настройке модуля

View File

@ -310,11 +310,11 @@ class ApiClient
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @return ApiResponse
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersCorporateCompanies(
$id,
@ -371,7 +371,7 @@ class ApiClient
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @return \RetailCrm\Response\ApiResponse
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
@ -403,11 +403,11 @@ class ApiClient
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @return ApiResponse
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersCorporateContacts(
$id,
@ -443,11 +443,11 @@ class ApiClient
* @param int $page (default: null)
* @param int $limit (default: null)
*
* @throws \InvalidArgumentException
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
* @throws \InvalidArgumentException
*/
public function customersCorporateList(array $filter = [], $page = null, $limit = null)
{
@ -476,11 +476,11 @@ class ApiClient
* @param int $page (default: null)
* @param int $limit (default: null)
*
* @throws \InvalidArgumentException
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
* @throws \InvalidArgumentException
*/
public function customersCorporateNotesList(array $filter = [], $page = null, $limit = null)
{
@ -508,11 +508,11 @@ class ApiClient
* @param array $note (default: array())
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
* @throws \InvalidArgumentException
*/
public function customersCorporateNotesCreate($note, $site = null)
{
@ -534,11 +534,11 @@ class ApiClient
*
* @param integer $id
*
* @throws \InvalidArgumentException
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
* @throws \InvalidArgumentException
*/
public function customersCorporateNotesDelete($id)
{
@ -564,11 +564,11 @@ class ApiClient
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @return ApiResponse
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersCorporateAddresses(
$id,
@ -605,7 +605,7 @@ class ApiClient
* @param string $by (default: 'externalId')
* @param null $site (default: null)
*
* @return \RetailCrm\Response\ApiResponse
* @return ApiResponse
*/
public function customersCorporateAddressesCreate($id, array $address = [], $by = 'externalId', $site = null): ApiResponse
{
@ -626,11 +626,11 @@ class ApiClient
* @param string $addressBy (default: 'externalId')
* @param string $site (default: null)
*
* @return ApiResponse
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function customersCorporateAddressesEdit(
$customerId,
@ -670,11 +670,11 @@ class ApiClient
* @param string $by (default: 'externalId')
* @param string $site (default: null)
*
* @throws \InvalidArgumentException
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
* @throws \InvalidArgumentException
*/
public function customersCorporateCompaniesCreate($id, array $company = [], $by = 'externalId', $site = null)
{
@ -696,7 +696,7 @@ class ApiClient
* @param string $companyBy (default: 'externalId')
* @param string $site (default: null)
*
* @return \RetailCrm\Response\ApiResponse
* @return ApiResponse
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
@ -732,7 +732,7 @@ class ApiClient
* @param string $contactBy (default: 'externalId')
* @param string $site (default: null)
*
* @return \RetailCrm\Response\ApiResponse
* @return ApiResponse
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
@ -765,7 +765,7 @@ class ApiClient
* @param string $by (default: 'externalId')
* @param null $site (default: null)
*
* @return \RetailCrm\Response\ApiResponse
* @return ApiResponse
*/
public function customersCorporateEdit(
array $params,
@ -2883,7 +2883,8 @@ class ApiClient
/**
* @param array $request
* @param int $checkId
* @return \RetailCrm\Response\ApiResponse
*
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
*/
public function checkStatusPlVerification(array $request, int $checkId): ApiResponse
@ -2897,7 +2898,8 @@ class ApiClient
/**
* @param array $request
* @return \RetailCrm\Response\ApiResponse
*
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
*/
public function loyaltyOrderApply(array $request): ApiResponse
@ -2915,7 +2917,8 @@ class ApiClient
/**
* @param array $request
* @return \RetailCrm\Response\ApiResponse
*
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
*/
public function loyaltyOrderCalculate(array $request): ApiResponse
@ -2932,7 +2935,7 @@ class ApiClient
}
/**
* @return \RetailCrm\Response\ApiResponse
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
*/
public function getCredentials(): ApiResponse
@ -2945,7 +2948,8 @@ class ApiClient
/**
* @param array $request
* @return \RetailCrm\Response\ApiResponse
*
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
*/
public function createLoyaltyAccount(array $request): ApiResponse
@ -2962,7 +2966,8 @@ class ApiClient
/**
* @param int $loyaltyId
* @return \RetailCrm\Response\ApiResponse
*
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
*/
public function activateLoyaltyAccount(int $loyaltyId): ApiResponse
@ -2975,7 +2980,8 @@ class ApiClient
/**
* @param array $request
* @return \RetailCrm\Response\ApiResponse
*
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
*/
public function sendVerificationCode(array $request): ApiResponse
@ -2991,7 +2997,8 @@ class ApiClient
/**
* @param array $request
* @return \RetailCrm\Response\ApiResponse
*
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
*/
public function getLoyaltyAccounts(array $request): ApiResponse
@ -3005,7 +3012,8 @@ class ApiClient
/**
* @param int $loyaltyId
* @return \RetailCrm\Response\ApiResponse
*
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
*/
public function getLoyaltyLoyalty(int $loyaltyId): ApiResponse
@ -3017,7 +3025,7 @@ class ApiClient
}
/**
* @return \RetailCrm\Response\ApiResponse
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
*/
public function getLoyaltyLoyalties(): ApiResponse
@ -3028,11 +3036,21 @@ class ApiClient
);
}
/**
* @param int $accountId
*
* @return ApiResponse
*/
public function getLoyaltyAccount(int $accountId): ApiResponse
{
return $this->client->makeRequest('/loyalty/account/' . $accountId, Client::METHOD_GET);
}
/**
* @param array $request
* @param int $accountId
*
* @return \RetailCrm\Response\ApiResponse
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
*/
public function editLoyaltyAccount(array $request, int $accountId): ApiResponse
@ -3049,7 +3067,7 @@ class ApiClient
/**
* @param array $request
* @return \RetailCrm\Response\ApiResponse
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
*/
protected function confirmLpVerificationBySMS(array $request): ApiResponse
@ -3063,7 +3081,7 @@ class ApiClient
/**
* @param array $request
* @return \RetailCrm\Response\ApiResponse
* @return ApiResponse
* @throws \RetailCrm\Exception\CurlException
*/
public function sendSmsForLpVerification(array $request): ApiResponse

View File

@ -391,14 +391,6 @@ class RetailCrmOrder
$order['payments'] = $payments;
}
if (!empty($arParams['crmOrder']['privilegeType'])) {
$order['privilegeType'] = $arParams['crmOrder']['privilegeType'];
} elseif (ConfigProvider::getLoyaltyProgramStatus() === 'Y' && LoyaltyAccountService::getLoyaltyPersonalStatus()) {
$order['privilegeType'] = 'loyalty_level';
} else {
$order['privilegeType'] = 'none';
}
//send
if (function_exists('retailCrmBeforeOrderSend')) {
$newResOrder = retailCrmBeforeOrderSend($order, $arOrder);
@ -427,6 +419,9 @@ class RetailCrmOrder
/** @var \Intaro\RetailCrm\Component\ApiClient\ClientAdapter $client */
$client = ClientFactory::createClientAdapter();
// Check and set privilegeType
$order['privilegeType'] = LoyaltyAccountService::getPrivilegeType($client, $arParams);
if ($send) {
if ($methodApi === 'ordersCreate') {
if (isset($arParams['customerCorporate']) && !empty($order['contact']['externalId'])) {

View File

@ -1 +1 @@
- Добавлена валидация валют при установке и настройке модуля
- Исправлены ошибки при работе с программой лояльности

View File

@ -1,6 +1,6 @@
<?php
$arModuleVersion = [
'VERSION' => '6.4.3',
'VERSION_DATE' => '2023-08-29 16:00:00'
'VERSION' => '6.4.4',
'VERSION_DATE' => '2023-09-01 10:00:00'
];

View File

@ -20,7 +20,8 @@ use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountCreateReque
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountEditRequest;
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountRequest;
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountEditResponse;
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountResponse;
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountGetResponse;
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountsResponse;
use Intaro\RetailCrm\Model\Api\Request\Loyalty\LoyaltyCalculateRequest;
use Intaro\RetailCrm\Model\Api\Request\Order\Loyalty\OrderLoyaltyApplyRequest;
use Intaro\RetailCrm\Model\Api\Request\SmsVerification\SmsVerificationConfirmRequest;
@ -33,7 +34,7 @@ use Intaro\RetailCrm\Model\Api\Response\Order\Loyalty\OrderLoyaltyApplyResponse;
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationConfirmResponse;
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusRequest;
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusResponse;
use RetailCrm\Response\ApiResponse;
use ReflectionException;
/**
* Trait LoyaltyTrait
@ -42,8 +43,10 @@ use RetailCrm\Response\ApiResponse;
trait LoyaltyTrait
{
/**
* @param \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusRequest $request
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusResponse|null
* @param SmsVerificationStatusRequest $request
*
* @return SmsVerificationStatusResponse|null
* @throws ReflectionException
*/
public function checkStatusPlVerification(SmsVerificationStatusRequest $request): ?SmsVerificationStatusResponse
{
@ -54,8 +57,10 @@ trait LoyaltyTrait
}
/**
* @param \Intaro\RetailCrm\Model\Api\Request\Order\Loyalty\OrderLoyaltyApplyRequest $request
* @return mixed
* @param OrderLoyaltyApplyRequest $request
*
* @return OrderLoyaltyApplyResponse|null
* @throws ReflectionException
*/
public function loyaltyOrderApply(OrderLoyaltyApplyRequest $request): ?OrderLoyaltyApplyResponse
{
@ -66,8 +71,10 @@ trait LoyaltyTrait
}
/**
* @param \Intaro\RetailCrm\Model\Api\Request\Loyalty\LoyaltyCalculateRequest $request
* @return mixed
* @param LoyaltyCalculateRequest $request
*
* @return LoyaltyCalculateResponse|null
* @throws ReflectionException
*/
public function loyaltyCalculate(LoyaltyCalculateRequest $request): ?LoyaltyCalculateResponse
{
@ -78,8 +85,36 @@ trait LoyaltyTrait
}
/**
* @param \Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountCreateRequest $request
* @return \Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountCreateResponse|null
* @param int $accountId
*
* @return LoyaltyAccountGetResponse|null
*/
public function getLoyaltyAccount(int $accountId): ?LoyaltyAccountGetResponse
{
$response = $this->client->getLoyaltyAccount($accountId);
return Deserializer::deserializeArray($response->getResponseBody(), LoyaltyAccountGetResponse::class);
}
/**
* @param LoyaltyAccountRequest $request
*
* @return LoyaltyAccountsResponse|null
* @throws ReflectionException
*/
public function getLoyaltyAccounts(LoyaltyAccountRequest $request): ?LoyaltyAccountsResponse
{
$serialized = Serializer::serializeArray($request);
$response = $this->client->getLoyaltyAccounts($serialized);
return Deserializer::deserializeArray($response->getResponseBody(), LoyaltyAccountsResponse::class);
}
/**
* @param LoyaltyAccountCreateRequest $request
*
* @return LoyaltyAccountCreateResponse|null
* @throws ReflectionException
*/
public function createLoyaltyAccount(LoyaltyAccountCreateRequest $request): ?LoyaltyAccountCreateResponse
{
@ -90,8 +125,24 @@ trait LoyaltyTrait
}
/**
* @param \Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountActivateRequest $request
* @return \Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountActivateResponse|null
* @param LoyaltyAccountEditRequest $request
*
* @return LoyaltyAccountEditResponse|null
* @throws ReflectionException
*/
public function editLoyaltyAccount(LoyaltyAccountEditRequest $request): ?LoyaltyAccountEditResponse
{
$serialized = Serializer::serializeArray($request);
$response = $this->client->editLoyaltyAccount($serialized, $request->id);
return Deserializer::deserializeArray($response->getResponseBody(), LoyaltyAccountEditResponse::class);
}
/**
* @param LoyaltyAccountActivateRequest $request
*
* @return LoyaltyAccountActivateResponse|null
* @throws ReflectionException
*/
public function activateLoyaltyAccount(LoyaltyAccountActivateRequest $request): ?LoyaltyAccountActivateResponse
{
@ -101,9 +152,12 @@ trait LoyaltyTrait
return Deserializer::deserializeArray($response->getResponseBody(), LoyaltyAccountActivateResponse::class);
}
/**
* @param \Intaro\RetailCrm\Model\Api\Request\SmsVerification\SmsVerificationConfirmRequest $request
* @return \Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountActivateResponse|null
* @param SmsVerificationConfirmRequest $request
*
* @return LoyaltyAccountActivateResponse|null
* @throws ReflectionException
*/
public function sendVerificationCode(SmsVerificationConfirmRequest $request): ?SmsVerificationConfirmResponse
{
@ -113,22 +167,10 @@ trait LoyaltyTrait
return Deserializer::deserializeArray($response->getResponseBody(), SmsVerificationConfirmResponse::class);
}
/**
* @param \Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountRequest $request
* @return \Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountResponse|null
*/
public function getLoyaltyAccounts(LoyaltyAccountRequest $request): ?LoyaltyAccountResponse
{
$serialized = Serializer::serializeArray($request);
$response = $this->client->getLoyaltyAccounts($serialized);
return Deserializer::deserializeArray($response->getResponseBody(), LoyaltyAccountResponse::class);
}
/**
* @param int $loyaltyId
*
* @return \Intaro\RetailCrm\Model\Api\Response\Loyalty\LoyaltyLoyaltyResponse|null
* @return LoyaltyLoyaltyResponse|null
*/
public function getLoyaltyLoyalty(int $loyaltyId): ?LoyaltyLoyaltyResponse
{
@ -138,7 +180,7 @@ trait LoyaltyTrait
}
/**
* @return \Intaro\RetailCrm\Model\Api\Response\Loyalty\LoyaltyLoyaltiesResponse|null
* @return LoyaltyLoyaltiesResponse|null
*/
public function getLoyaltyLoyalties(): ?LoyaltyLoyaltiesResponse
{
@ -146,18 +188,4 @@ trait LoyaltyTrait
return Deserializer::deserializeArray($response->getResponseBody(), LoyaltyLoyaltiesResponse::class);
}
/**
* @param \Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountEditRequest $request
*
* @return \Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountEditResponse|null
* @throws \ReflectionException
*/
public function editLoyaltyAccount(LoyaltyAccountEditRequest $request): ?LoyaltyAccountEditResponse
{
$serialized = Serializer::serializeArray($request);
$response = $this->client->editLoyaltyAccount($serialized, $request->id);
return Deserializer::deserializeArray($response->getResponseBody(), LoyaltyAccountEditResponse::class);
}
}

View File

@ -45,10 +45,10 @@ class LoyaltyAccount
/**
* Программа лояльности
*
* @var \Intaro\RetailCrm\Model\Api\Loyalty
* @var Loyalty
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\Loyalty")
* @Mapping\SerializedName("$loyalty")
* @Mapping\SerializedName("loyalty")
*/
public $loyalty;

View File

@ -0,0 +1,33 @@
<?php
namespace Intaro\RetailCrm\Model\Api\Response\Loyalty\Account;
use Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Model\Api\LoyaltyAccount;
use Intaro\RetailCrm\Model\Api\Response\AbstractApiResponseModel;
/**
* Class LoyaltyAccountResponse
*
* @package Intaro\RetailCrm\Model\Api\Request\Loyalty\Account
*/
class LoyaltyAccountGetResponse extends AbstractApiResponseModel
{
/**
* Результат запроса (успешный/неуспешный)
*
* @var bool $success
*
* @Mapping\Type("boolean")
* @Mapping\SerializedName("success")
*/
public $success;
/**
* @var LoyaltyAccount $loyaltyAccount
*
* @Mapping\Type("Intaro\RetailCrm\Model\Api\LoyaltyAccount")
* @Mapping\SerializedName("loyaltyAccount")
*/
public $loyaltyAccount;
}

View File

@ -14,14 +14,15 @@
namespace Intaro\RetailCrm\Model\Api\Response\Loyalty\Account;
use Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Model\Api\PaginationResponse;
use Intaro\RetailCrm\Model\Api\Response\AbstractApiResponseModel;
/**
* Class LoyaltyAccountResponse
* Class LoyaltyAccountsResponse
*
* @package Intaro\RetailCrm\Model\Api\Request\Loyalty\Account
*/
class LoyaltyAccountResponse extends AbstractApiResponseModel
class LoyaltyAccountsResponse extends AbstractApiResponseModel
{
/**
* Результат запроса (успешный/неуспешный)
@ -34,7 +35,7 @@ class LoyaltyAccountResponse extends AbstractApiResponseModel
public $success;
/**
* @var \Intaro\RetailCrm\Model\Api\PaginationResponse
* @var PaginationResponse
*
* @Mapping\Type("\Intaro\RetailCrm\Model\Api\PaginationResponse")
* @Mapping\SerializedName("pagination")

View File

@ -14,6 +14,7 @@
namespace Intaro\RetailCrm\Service;
use CUser;
use Logger;
use DateTime;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Factory\ClientFactory;
@ -215,11 +216,104 @@ class LoyaltyAccountService
public static function getLoyaltyPersonalStatus(): bool
{
global $USER;
$userFields = CUser::GetByID($USER->GetID())->Fetch();
return isset($userFields['UF_EXT_REG_PL_INTARO']) && $userFields['UF_EXT_REG_PL_INTARO'] === '1';
}
/**
* Возвращает ID аккаунта в программе лояльности
*
* @return int|null
*/
public static function getLoyaltyAccountId(): ?int
{
global $USER;
$userFields = CUser::GetByID($USER->GetID())->Fetch();
return $userFields['UF_LP_ID_INTARO'] ?? null;
}
/**
* Метод возвращает значение для поля 'privilegeType'. Валидация поля происходит по кейсам:
* 1. Программа лояльност не работает с корп. клиентами.
* 2. Участие клиента не найдено в CRM, соответственно либо нет участия, либо нет клиента.
* 3. Участие клиента найдено, но не активно (поле status = deactivated).
* 4. Программа лояльности деактивирована в CRM.
*
* @param $client
* @param array $arParams
*
* @return string
*/
public static function getPrivilegeType($client, array $arParams = []): string
{
$file = 'loyaltyStatus';
$privilegeType = 'none';
if (!empty($arParams['customerCorporate']['privilegeType'])) {
$privilegeType = $arParams['crmOrder']['privilegeType'];
} elseif (ConfigProvider::getLoyaltyProgramStatus() === 'Y' && self::getLoyaltyPersonalStatus()) {
$privilegeType = 'loyalty_level';
}
if (!empty($arParams['customerCorporate']) || !empty($arParams['orderCompany'])) {
return 'none';
}
if ($privilegeType === 'none') {
return 'none';
}
$loyaltyAccountId = self::getLoyaltyAccountId();
if ($loyaltyAccountId === null) {
Logger::getInstance()->write('Участие клиента не найдено', $file);
return 'none';
}
$loyaltyAccount = $client->getLoyaltyAccount($loyaltyAccountId)->loyaltyAccount ?? null;
if ($loyaltyAccount === null) {
Logger::getInstance()->write('Участие клиента c ID: ' . $loyaltyAccountId . ' не найдено', $file);
return 'none';
}
if ($loyaltyAccount->status === 'deactivated') {
Logger::getInstance()->write('Участие клиента c ID: ' . $loyaltyAccountId . ' деактивированно', $file);
return 'none';
}
$loyaltyId = $loyaltyAccount->loyalty->id ?? null;
if ($loyaltyId === null) {
Logger::getInstance()->write('Программа лояльности не найдена', $file);
return 'none';
}
$loyalty = $client->getLoyaltyLoyalty($loyaltyId)->loyalty ?? null;
if ($loyalty === null) {
Logger::getInstance()->write('Программа лояльности c ID: ' . $loyaltyId . ' не найдена', $file);
return 'none';
}
if (!$loyalty->active) {
Logger::getInstance()->write('Программа лояльности c ID: ' . $loyaltyId . ' деактивированна', $file);
return 'none';
}
return $privilegeType;
}
/**
* @return array|null
* @throws \ReflectionException