1
0
mirror of synced 2024-11-22 13:26:10 +03:00
bitrix-module/intaro.retailcrm/lib/repository/buyerprofilerepository.php
Сергей Чазов 34e8105583
Loyalty (#241)
* Loyalty program
* fix dot bug for shops-exoprt option
* delete credantials request from services
* add CurlException for credentials catch
* add catching CurlException
* edit error msgs
* add supportind double bonuses
* add any step for bonus-input field in sale.order.ajax template
* recalculate bonuses
* fix bonus rounded
* strtoupper for params in icml
* change delivery service code
2022-03-02 15:40:53 +03:00

85 lines
2.1 KiB
PHP

<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Model\Api
* @author RetailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Repository;
use Bitrix\Sale\OrderUserProperties;
use Intaro\RetailCrm\Component\Json\Deserializer;
use Intaro\RetailCrm\Component\Json\Serializer;
use Intaro\RetailCrm\Model\Bitrix\BuyerProfile;
/**
* Class UserRepository
*
* @package Intaro\RetailCrm\Repository
*/
class BuyerProfileRepository extends AbstractRepository
{
/**
* Returns BuyerProfile by id
*
* @param int $id
*
* @return \Intaro\RetailCrm\Model\Bitrix\BuyerProfile|null
*/
public static function getById(int $id): ?BuyerProfile
{
$result = OrderUserProperties::getList(['filter' => ['ID' => $id]])->fetch();
if (!$result) {
return null;
}
return static::deserialize($result);
}
/**
* Returns true if provided BuyerProfile exists
*
* @param \Intaro\RetailCrm\Model\Bitrix\BuyerProfile $buyerProfile
*
* @return bool
*/
public static function isProfileExists(BuyerProfile $buyerProfile): bool
{
$profileData = Serializer::serializeArray($buyerProfile);
$found = static::findProfileByData($profileData);
return !empty($found);
}
/**
* Returns array with buyer profile if one was found. Returns empty array otherwise.
*
* @param array $profileData
*
* @return array
*/
private static function findProfileByData(array $profileData): array
{
return OrderUserProperties::getList(array(
"filter" => $profileData
))->fetch();
}
/**
* @param array $buyerProfileData
*
* @return \Intaro\RetailCrm\Model\Bitrix\BuyerProfile
*/
private static function deserialize(array $buyerProfileData): BuyerProfile
{
return Deserializer::deserializeArray($buyerProfileData, BuyerProfile::class);
}
}