Loyalty feature
* Merge with master updates
This commit is contained in:
commit
1446b7204e
9 changed files with 438 additions and 388 deletions
|
@ -195,7 +195,7 @@ class RetailCrmEvent
|
|||
|
||||
$orderCompany = null;
|
||||
|
||||
if ("Y" == $optionCorpClient && $optionsContragentType[$arOrder['PERSON_TYPE_ID']] == 'legal-entity') {
|
||||
if ("Y" === $optionCorpClient && $optionsContragentType[$arOrder['PERSON_TYPE_ID']] == 'legal-entity') {
|
||||
//corparate cliente
|
||||
$nickName = '';
|
||||
$address = '';
|
||||
|
|
|
@ -376,18 +376,6 @@ class RetailCrmOrder
|
|||
$optionsContragentType = RetailcrmConfigProvider::getContragentTypes();
|
||||
$optionsCustomFields = RetailcrmConfigProvider::getCustomFields();
|
||||
|
||||
$getSite = function ($key) use ($optionsSitesList) {
|
||||
if ($optionsSitesList) {
|
||||
if (array_key_exists($key, $optionsSitesList) && $optionsSitesList[$key] != null) {
|
||||
return $optionsSitesList[$key];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
$api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
|
||||
|
||||
$arParams = array(
|
||||
|
@ -417,7 +405,7 @@ class RetailCrmOrder
|
|||
$arCustomerCorporate = array();
|
||||
$order = self::orderObjToArr($id);
|
||||
$user = Bitrix\Main\UserTable::getById($order['USER_ID'])->fetch();
|
||||
$site = $getSite($order['LID']);
|
||||
$site = RetailCrmOrder::getSite($order['LID'], $optionsSitesList);
|
||||
|
||||
if (true === $site) {
|
||||
continue;
|
||||
|
@ -485,48 +473,7 @@ class RetailCrmOrder
|
|||
}
|
||||
|
||||
if (count($resOrders) > 0) {
|
||||
$uploadItems = function ($pack, $method) use ($getSite, $api, $optionsSitesList) {
|
||||
$uploaded = array();
|
||||
|
||||
foreach ($pack as $key => $itemLoad) {
|
||||
$site = $getSite($key);
|
||||
|
||||
if (true === $site) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/** @var \RetailCrm\Response\ApiResponse|bool $response */
|
||||
$response = RCrmActions::apiMethod(
|
||||
$api,
|
||||
$method,
|
||||
__METHOD__,
|
||||
$itemLoad,
|
||||
$site
|
||||
);
|
||||
|
||||
if ($response === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($response instanceof \RetailCrm\Response\ApiResponse) {
|
||||
if ($response->offsetExists('uploadedCustomers')) {
|
||||
$uploaded = array_merge($uploaded, $response['uploadedCustomers']);
|
||||
}
|
||||
|
||||
if ($response->offsetExists('uploadedOrders')) {
|
||||
$uploaded = array_merge($uploaded, $response['uploadedOrders']);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($optionsSitesList) > 1) {
|
||||
time_nanosleep(0, 250000000);
|
||||
}
|
||||
}
|
||||
|
||||
return $uploaded;
|
||||
};
|
||||
|
||||
if (false === $uploadItems($resCustomers, 'customersUpload')) {
|
||||
if (false === RetailCrmOrder::uploadCustomersList($resCustomers, $api, $optionsSitesList)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -593,7 +540,7 @@ class RetailCrmOrder
|
|||
}
|
||||
}
|
||||
|
||||
if (false === $uploadItems($resOrders, 'ordersUpload')) {
|
||||
if (false === RetailCrmOrder::uploadOrdersList($resOrders, $api, $optionsSitesList)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -607,6 +554,111 @@ class RetailCrmOrder
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $resCustomers
|
||||
* @param RetailCrm\ApiClient $api
|
||||
* @param array $optionsSitesList
|
||||
*
|
||||
* @return array|false
|
||||
*/
|
||||
public static function uploadCustomersList($resCustomers, $api, $optionsSitesList)
|
||||
{
|
||||
return RetailCrmOrder::uploadItems(
|
||||
$resCustomers,
|
||||
'customersUpload',
|
||||
'uploadedCustomers',
|
||||
$api,
|
||||
$optionsSitesList
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $resOrders
|
||||
* @param RetailCrm\ApiClient $api
|
||||
* @param array $optionsSitesList
|
||||
*
|
||||
* @return array|false
|
||||
*/
|
||||
public static function uploadOrdersList($resOrders, $api, $optionsSitesList)
|
||||
{
|
||||
return RetailCrmOrder::uploadItems(
|
||||
$resOrders,
|
||||
'ordersUpload',
|
||||
'uploadedOrders',
|
||||
$api,
|
||||
$optionsSitesList
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param array $optionsSitesList
|
||||
*
|
||||
* @return false|mixed|null
|
||||
*/
|
||||
public static function getSite($key, $optionsSitesList)
|
||||
{
|
||||
if ($optionsSitesList) {
|
||||
if (array_key_exists($key, $optionsSitesList) && $optionsSitesList[$key] != null) {
|
||||
return $optionsSitesList[$key];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $pack
|
||||
* @param string $method
|
||||
* @param string $keyResponse
|
||||
* @param RetailCrm\ApiClient $api
|
||||
* @param array $optionsSitesList
|
||||
*
|
||||
* @return array|false
|
||||
*/
|
||||
public static function uploadItems($pack, $method, $keyResponse, $api, $optionsSitesList)
|
||||
{
|
||||
$uploaded = array();
|
||||
$sizePack = 50;
|
||||
|
||||
foreach ($pack as $key => $itemLoad) {
|
||||
$site = RetailCrmOrder::getSite($key, $optionsSitesList);
|
||||
|
||||
if (true === $site) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$chunkList = array_chunk($itemLoad, $sizePack, true);
|
||||
|
||||
foreach ($chunkList as $chunk) {
|
||||
time_nanosleep(0, 250000000);
|
||||
|
||||
/** @var \RetailCrm\Response\ApiResponse|bool $response */
|
||||
$response = RCrmActions::apiMethod(
|
||||
$api,
|
||||
$method,
|
||||
__METHOD__,
|
||||
$chunk,
|
||||
$site
|
||||
);
|
||||
|
||||
if ($response === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($response instanceof \RetailCrm\Response\ApiResponse) {
|
||||
if ($response->offsetExists($keyResponse)) {
|
||||
$uploaded = array_merge($uploaded, $response[$keyResponse]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $uploaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if provided order array is corporate order data
|
||||
*
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -27,7 +27,7 @@ class EventsHandlers
|
|||
{
|
||||
AddMessage2Log('OnBeforeSalePaymentSetFieldHandler work! ' . $event->getDebugInfo());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
|
@ -35,7 +35,7 @@ class EventsHandlers
|
|||
{
|
||||
AddMessage2Log('OnBeforeEndBufferContentHandler work! ');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Bitrix\Main\Event $event
|
||||
*/
|
||||
|
@ -43,7 +43,7 @@ class EventsHandlers
|
|||
{
|
||||
AddMessage2Log('OnSaleOrderBeforeSavedHandler work! ' . $event->getDebugInfo());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Bitrix\Main\Event $event
|
||||
*/
|
||||
|
@ -51,7 +51,7 @@ class EventsHandlers
|
|||
{
|
||||
AddMessage2Log('OnSaleOrderPaidHandler work! '. $event->getDebugInfo());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Bitrix\Main\Event $event
|
||||
*/
|
||||
|
@ -59,7 +59,7 @@ class EventsHandlers
|
|||
{
|
||||
AddMessage2Log('OnSaleStatusOrderChangeHandler work! '. $event->getDebugInfo());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Bitrix\Main\Event $event
|
||||
*/
|
||||
|
@ -67,7 +67,7 @@ class EventsHandlers
|
|||
{
|
||||
AddMessage2Log('OnSaleOrderSavedHandler work! '. $event->getDebugInfo());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Bitrix\Main\Event $event
|
||||
*/
|
||||
|
@ -75,7 +75,7 @@ class EventsHandlers
|
|||
{
|
||||
AddMessage2Log('OnSaleOrderCanceledHandler work! '. $event->getDebugInfo());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Bitrix\Main\Event $event
|
||||
*/
|
||||
|
@ -83,7 +83,7 @@ class EventsHandlers
|
|||
{
|
||||
AddMessage2Log('OnSaleOrderDeletedHandler work! '. $event->getDebugInfo());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $arResult
|
||||
* @param $arUserResult
|
||||
|
|
|
@ -87,12 +87,12 @@ class ServiceLocator
|
|||
}
|
||||
|
||||
/**
|
||||
* Get or create service (instantiates service if it wasn't created earlier; $name must be FQN).
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
* Get or create service (instantiates service if it wasn't created earlier; $name must be FQN).
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getOrCreate(string $name)
|
||||
{
|
||||
$service = static::$services[$name];
|
||||
|
@ -104,7 +104,7 @@ class ServiceLocator
|
|||
|
||||
return $service;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets service into ServiceContainer.
|
||||
*
|
||||
|
|
|
@ -24,6 +24,7 @@ class PersonTypeRepository extends AbstractRepository
|
|||
/**
|
||||
* @param array $select
|
||||
* @param array $where
|
||||
*
|
||||
* @return \Bitrix\Main\Type\Collection|null|Bitrix\Sale\Internals\EO_PersonType_Collection
|
||||
* @throws \Bitrix\Main\ArgumentException
|
||||
* @throws \Bitrix\Main\ObjectPropertyException
|
||||
|
|
|
@ -41,6 +41,7 @@ class ToModuleRepository extends AbstractRepository
|
|||
/**
|
||||
* @param array $select
|
||||
* @param array $where
|
||||
*
|
||||
* @return \Bitrix\Main\Type\Collection|Intaro\RetailCrm\Model\Bitrix\ORM\EO_ToModule_Collection|null
|
||||
* @throws \Bitrix\Main\ArgumentException
|
||||
* @throws \Bitrix\Main\ObjectPropertyException
|
||||
|
|
|
@ -40,7 +40,7 @@ class UserRepository extends AbstractRepository
|
|||
|
||||
return Deserializer::deserializeArray($fields, User::class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @param array $select
|
||||
|
|
|
@ -9,7 +9,7 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
class ClientFactoryTest extends TestCase
|
||||
{
|
||||
public function testCreacteClientAdapter(): void
|
||||
public function testCreateClientAdapter(): void
|
||||
{
|
||||
$client = ClientFactory::createClientAdapter();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue