renamed calculateBonus to getLoyaltyCalculate etc
This commit is contained in:
parent
a6a3215179
commit
c2fef176d7
11 changed files with 197 additions and 165 deletions
|
@ -1,6 +1,11 @@
|
|||
<?php
|
||||
|
||||
use Bitrix\Main\Context\Culture;
|
||||
use Bitrix\Catalog\Model\Event;
|
||||
use Bitrix\Main\UserTable;
|
||||
use Bitrix\Sale\Order;
|
||||
use Intaro\RetailCrm\Component\ConfigProvider;
|
||||
use Intaro\RetailCrm\Model\Api\Response\OrdersCreateResponse;
|
||||
use Intaro\RetailCrm\Model\Api\Response\OrdersEditResponse;
|
||||
use Intaro\RetailCrm\Service\ManagerService;
|
||||
use Bitrix\Sale\Payment;
|
||||
use RetailCrm\ApiClient;
|
||||
|
@ -31,22 +36,22 @@ class RetailCrmEvent
|
|||
if (isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!$arFields['RESULT']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$optionsSitesList = RetailcrmConfigProvider::getSitesList();
|
||||
$api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
|
||||
$resultOrder = RetailCrmUser::customerEdit($arFields, $api, $optionsSitesList);
|
||||
|
||||
|
||||
if (!$resultOrder) {
|
||||
RCrmActions::eventLog('RetailCrmEvent::OnAfterUserUpdate', 'RetailCrmUser::customerEdit', 'error update customer');
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* onUpdateOrder
|
||||
*
|
||||
|
@ -59,19 +64,19 @@ class RetailCrmEvent
|
|||
$GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = true;
|
||||
|
||||
|
||||
if (($arFields['CANCELED'] === 'Y')
|
||||
&& (sizeof($arFields['BASKET_ITEMS']) == 0)
|
||||
&& (sizeof($arFields['ORDER_PROP']) == 0)
|
||||
) {
|
||||
$GLOBALS['ORDER_DELETE_USER_ADMIN'] = true;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* orderDelete
|
||||
*
|
||||
|
@ -80,12 +85,12 @@ class RetailCrmEvent
|
|||
public function orderDelete($event)
|
||||
{
|
||||
$GLOBALS['RETAILCRM_ORDER_DELETE'] = true;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $event
|
||||
* @param \Bitrix\Sale\Order|\Bitrix\Main\Event $event
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Bitrix\Main\ObjectPropertyException
|
||||
|
@ -94,38 +99,18 @@ class RetailCrmEvent
|
|||
*/
|
||||
public function orderSave($event)
|
||||
{
|
||||
if (true == $GLOBALS['ORDER_DELETE_USER_ADMIN']) {
|
||||
return false;
|
||||
if (!$this->checkConfig()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] === false
|
||||
&& $GLOBALS['RETAILCRM_ORDER_DELETE'] === true
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($GLOBALS['RETAIL_CRM_HISTORY'] === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CModule::IncludeModule('iblock')) {
|
||||
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'iblock', 'module not found');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CModule::IncludeModule('sale')) {
|
||||
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'sale', 'module not found');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$arOrder = $this->getOrderArray($event);
|
||||
|
||||
if (!CModule::IncludeModule('catalog')) {
|
||||
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'catalog', 'module not found');
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//exists getParameter("ENTITY")
|
||||
if (method_exists($event, 'getId')) {
|
||||
$obOrder = $event;
|
||||
|
@ -133,14 +118,14 @@ class RetailCrmEvent
|
|||
$obOrder = $event->getParameter('ENTITY');
|
||||
} else {
|
||||
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'events', 'event error');
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$arOrder = RetailCrmOrder::orderObjToArr($obOrder);
|
||||
|
||||
|
||||
$api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
|
||||
|
||||
|
||||
//params
|
||||
$optionsOrderTypes = RetailcrmConfigProvider::getOrderTypes();
|
||||
$optionsDelivTypes = RetailcrmConfigProvider::getDeliveryTypes();
|
||||
|
@ -152,10 +137,10 @@ class RetailCrmEvent
|
|||
$optionsLegalDetails = RetailcrmConfigProvider::getLegalDetails();
|
||||
$optionsContragentType = RetailcrmConfigProvider::getContragentTypes();
|
||||
$optionsCustomFields = RetailcrmConfigProvider::getCustomFields();
|
||||
|
||||
|
||||
//corp cliente swich
|
||||
$optionCorpClient = RetailcrmConfigProvider::getCorporateClientStatus();
|
||||
|
||||
|
||||
$arParams = RCrmActions::clearArr([
|
||||
'optionsOrderTypes' => $optionsOrderTypes,
|
||||
'optionsDelivTypes' => $optionsDelivTypes,
|
||||
|
@ -168,7 +153,7 @@ class RetailCrmEvent
|
|||
'optionsSitesList' => $optionsSitesList,
|
||||
'optionsCustomFields' => $optionsCustomFields,
|
||||
]);
|
||||
|
||||
|
||||
//many sites?
|
||||
if ($optionsSitesList) {
|
||||
if (array_key_exists($arOrder['LID'], $optionsSitesList) && $optionsSitesList[$arOrder['LID']] !== null) {
|
||||
|
@ -179,7 +164,7 @@ class RetailCrmEvent
|
|||
} elseif (!$optionsSitesList) {
|
||||
$site = null;
|
||||
}
|
||||
|
||||
|
||||
//new order?
|
||||
$orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $arOrder['ID'], $site);
|
||||
if (isset($orderCrm['order'])) {
|
||||
|
@ -188,7 +173,7 @@ class RetailCrmEvent
|
|||
} else {
|
||||
$methodApi = 'ordersCreate';
|
||||
}
|
||||
|
||||
|
||||
$orderCompany = null;
|
||||
if ('Y' === $optionCorpClient) {
|
||||
if (true === RetailCrmCorporateClient::isCorpTookExternalId((string) $arOrder['USER_ID'], $api)) {
|
||||
|
@ -207,34 +192,34 @@ class RetailCrmEvent
|
|||
$userCorp = [];
|
||||
$corpName = RetailcrmConfigProvider::getCorporateClientName();
|
||||
$corpAddress = RetailcrmConfigProvider::getCorporateClientAddress();
|
||||
|
||||
|
||||
foreach ($arOrder['PROPS']['properties'] as $prop) {
|
||||
if ($prop['CODE'] === $corpName) {
|
||||
$nickName = $prop['VALUE'][0];
|
||||
}
|
||||
|
||||
|
||||
if ($prop['CODE'] === $corpAddress) {
|
||||
$address = $prop['VALUE'][0];
|
||||
}
|
||||
|
||||
|
||||
if (!empty($optionsLegalDetails)
|
||||
&& $search = array_search($prop['CODE'], $optionsLegalDetails[$arOrder['PERSON_TYPE_ID']])
|
||||
) {
|
||||
$contragent[$search] = $prop['VALUE'][0];//legal order data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($contragentType)) {
|
||||
$contragent['contragentType'] = $contragentType;
|
||||
}
|
||||
|
||||
|
||||
$customersCorporate = false;
|
||||
$response = $api->customersCorporateList(['companyName' => $nickName]);
|
||||
|
||||
|
||||
if ($response && $response->getStatusCode() == 200) {
|
||||
$customersCorporate = $response['customersCorporate'];
|
||||
$singleCorp = reset($customersCorporate);
|
||||
|
||||
|
||||
if (!empty($singleCorp)) {
|
||||
$userCorp['customerCorporate'] = $singleCorp;
|
||||
$companiesResponse = $api->customersCorporateCompanies(
|
||||
|
@ -245,7 +230,7 @@ class RetailCrmEvent
|
|||
'id',
|
||||
$site
|
||||
);
|
||||
|
||||
|
||||
if ($companiesResponse && $companiesResponse->isSuccessful()) {
|
||||
$orderCompany = array_reduce(
|
||||
$companiesResponse['companies'],
|
||||
|
@ -253,7 +238,7 @@ class RetailCrmEvent
|
|||
if (is_array($item) && $item['name'] === $nickName) {
|
||||
$carry = $item;
|
||||
}
|
||||
|
||||
|
||||
return $carry;
|
||||
},
|
||||
null
|
||||
|
@ -266,35 +251,35 @@ class RetailCrmEvent
|
|||
'ApiClient::customersCorporateList',
|
||||
'error during fetching corporate customers'
|
||||
);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//user
|
||||
$userCrm = RCrmActions::apiMethod($api, 'customersGet', __METHOD__, $arOrder['USER_ID'], $site);
|
||||
|
||||
|
||||
if (!isset($userCrm['customer'])) {
|
||||
$arUser = Bitrix\Main\UserTable::getById($arOrder['USER_ID'])->fetch();
|
||||
|
||||
|
||||
if (!empty($address)) {
|
||||
$arUser['PERSONAL_STREET'] = $address;
|
||||
}
|
||||
|
||||
|
||||
$resultUser = RetailCrmUser::customerSend($arUser, $api, 'individual', true, $site);
|
||||
|
||||
|
||||
if (!$resultUser) {
|
||||
RCrmActions::eventLog(
|
||||
__CLASS__ . '::' . __METHOD__,
|
||||
'RetailCrmUser::customerSend',
|
||||
'error during creating customer'
|
||||
);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$userCrm = ['customer' => ['externalId' => $arOrder['USER_ID']]];
|
||||
}
|
||||
|
||||
|
||||
if (!isset($userCorp['customerCorporate'])) {
|
||||
$resultUserCorp = RetailCrmCorporateClient::clientSend(
|
||||
$arOrder,
|
||||
|
@ -304,23 +289,23 @@ class RetailCrmEvent
|
|||
false,
|
||||
$site
|
||||
);
|
||||
|
||||
|
||||
Logger::getInstance()->write($resultUserCorp, 'resultUserCorp');
|
||||
|
||||
|
||||
if (!$resultUserCorp) {
|
||||
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'RetailCrmCorporateClient::clientSend', 'error during creating client');
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$arParams['customerCorporate'] = $resultUserCorp;
|
||||
$arParams['orderCompany'] = $resultUserCorp['mainCompany'] ?? null;
|
||||
|
||||
|
||||
$customerCorporateAddress = [];
|
||||
$customerCorporateCompany = [];
|
||||
$addressResult = null;
|
||||
$companyResult = null;
|
||||
|
||||
|
||||
if (!empty($address)) {
|
||||
//TODO address builder add
|
||||
$customerCorporateAddress = [
|
||||
|
@ -328,24 +313,24 @@ class RetailCrmEvent
|
|||
'isMain' => true,
|
||||
'text' => $address,
|
||||
];
|
||||
|
||||
|
||||
$addressResult = $api->customersCorporateAddressesCreate($resultUserCorp['id'], $customerCorporateAddress, 'id', $site);
|
||||
}
|
||||
|
||||
|
||||
$customerCorporateCompany = [
|
||||
'name' => $nickName,
|
||||
'isMain' => true,
|
||||
'contragent' => $contragent,
|
||||
];
|
||||
|
||||
|
||||
if (!empty($addressResult)) {
|
||||
$customerCorporateCompany['address'] = [
|
||||
'id' => $addressResult['id'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
$companyResult = $api->customersCorporateCompaniesCreate($resultUserCorp['id'], $customerCorporateCompany, 'id', $site);
|
||||
|
||||
|
||||
$customerCorporateContact = [
|
||||
'isMain' => true,
|
||||
'customer' => [
|
||||
|
@ -353,26 +338,26 @@ class RetailCrmEvent
|
|||
'site' => $site,
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
if (!empty($companyResult)) {
|
||||
$orderCompany = [
|
||||
'id' => $companyResult['id'],
|
||||
];
|
||||
|
||||
|
||||
$customerCorporateContact['companies'] = [
|
||||
[
|
||||
'company' => $orderCompany,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
$api->customersCorporateContactsCreate(
|
||||
$resultUserCorp['id'],
|
||||
$customerCorporateContact,
|
||||
'id',
|
||||
$site
|
||||
);
|
||||
|
||||
|
||||
$arParams['orderCompany'] = array_merge(
|
||||
$customerCorporateCompany,
|
||||
['id' => $companyResult['id']]
|
||||
|
@ -385,14 +370,14 @@ class RetailCrmEvent
|
|||
$api,
|
||||
$site = null
|
||||
);
|
||||
|
||||
|
||||
$arParams['customerCorporate'] = $userCorp['customerCorporate'];
|
||||
|
||||
|
||||
if (!empty($orderCompany)) {
|
||||
$arParams['orderCompany'] = $orderCompany;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$arParams['contactExId'] = $userCrm['customer']['externalId'];
|
||||
} else {
|
||||
//user
|
||||
|
@ -402,7 +387,7 @@ class RetailCrmEvent
|
|||
$resultUser = RetailCrmUser::customerSend($arUser, $api, $optionsContragentType[$arOrder['PERSON_TYPE_ID']], true, $site);
|
||||
if (!$resultUser) {
|
||||
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'RetailCrmUser::customerSend', 'error during creating customer');
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -413,16 +398,16 @@ class RetailCrmEvent
|
|||
}
|
||||
//order
|
||||
$resultOrder = RetailCrmOrder::orderSend($arOrder, $api, $arParams, true, $site, $methodApi);
|
||||
|
||||
|
||||
if (!$resultOrder) {
|
||||
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'RetailCrmOrder::orderSend', 'error during creating order');
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Bitrix\Sale\Payment $event
|
||||
*
|
||||
|
@ -433,22 +418,22 @@ class RetailCrmEvent
|
|||
public function paymentSave(Payment $event)
|
||||
{
|
||||
$apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0);
|
||||
|
||||
|
||||
/** @var \Bitrix\Sale\Order $order */
|
||||
$order = $event->getCollection()->getOrder();
|
||||
|
||||
|
||||
if ((isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY'])
|
||||
|| $apiVersion !== 'v5'
|
||||
|| $order->isNew()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$optionsSitesList = RetailcrmConfigProvider::getSitesList();
|
||||
$optionsPaymentTypes = RetailcrmConfigProvider::getPaymentTypes();
|
||||
$optionsPayStatuses = RetailcrmConfigProvider::getPayment();
|
||||
$integrationPaymentTypes = RetailcrmConfigProvider::getIntegrationPaymentTypes();
|
||||
|
||||
|
||||
$arPayment = [
|
||||
'ID' => $event->getId(),
|
||||
'ORDER_ID' => $event->getField('ORDER_ID'),
|
||||
|
@ -458,7 +443,7 @@ class RetailCrmEvent
|
|||
'LID' => $order->getSiteId(),
|
||||
'DATE_PAID' => $event->getField('DATE_PAID'),
|
||||
];
|
||||
|
||||
|
||||
if ($optionsSitesList) {
|
||||
if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) {
|
||||
$site = $optionsSitesList[$arPayment['LID']];
|
||||
|
@ -468,14 +453,14 @@ class RetailCrmEvent
|
|||
} elseif (!$optionsSitesList) {
|
||||
$site = null;
|
||||
}
|
||||
|
||||
|
||||
$api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
|
||||
$orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $arPayment['ORDER_ID'], $site);
|
||||
|
||||
|
||||
if (isset($orderCrm['order'])) {
|
||||
$payments = $orderCrm['order']['payments'];
|
||||
}
|
||||
|
||||
|
||||
if ($payments) {
|
||||
foreach ($payments as $payment) {
|
||||
if (isset($payment['externalId'])) {
|
||||
|
@ -488,16 +473,16 @@ class RetailCrmEvent
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($arPayment['PAY_SYSTEM_ID']) && isset($optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']])) {
|
||||
$paymentToCrm = [
|
||||
'type' => $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']],
|
||||
];
|
||||
|
||||
|
||||
if (!empty($arPayment['ID'])) {
|
||||
$paymentToCrm['externalId'] = RCrmActions::generatePaymentExternalId($arPayment['ID']);
|
||||
}
|
||||
|
||||
|
||||
$isIntegrationPayment
|
||||
= RetailCrmService::isIntegrationPayment($arPayment['PAY_SYSTEM_ID'] ?? null);
|
||||
|
||||
|
@ -509,15 +494,15 @@ class RetailCrmEvent
|
|||
$paymentToCrm['paidAt'] = $arPayment['DATE_PAID'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($optionsPayStatuses[$arPayment['PAID']]) && !$isIntegrationPayment) {
|
||||
$paymentToCrm['status'] = $optionsPayStatuses[$arPayment['PAID']];
|
||||
}
|
||||
|
||||
|
||||
if (!empty($arPayment['ORDER_ID'])) {
|
||||
$paymentToCrm['order']['externalId'] = $arPayment['ORDER_ID'];
|
||||
}
|
||||
|
||||
|
||||
if (RetailcrmConfigProvider::shouldSendPaymentAmount()) {
|
||||
$paymentToCrm['amount'] = $arPayment['SUM'];
|
||||
}
|
||||
|
@ -525,9 +510,9 @@ class RetailCrmEvent
|
|||
RCrmActions::eventLog('RetailCrmEvent::paymentSave', 'payments', 'OrderID = ' . $arPayment['ID'] . '. Payment not found.');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$arPaymentExtId = RCrmActions::generatePaymentExternalId($arPayment['ID']);
|
||||
|
||||
|
||||
if (array_key_exists($arPaymentExtId, $paymentsExternalIds)) {
|
||||
$paymentData = $paymentsExternalIds[$arPaymentExtId];
|
||||
} elseif (array_key_exists($arPayment['ID'], $paymentsExternalIds)) {
|
||||
|
@ -535,7 +520,7 @@ class RetailCrmEvent
|
|||
} else {
|
||||
$paymentData = [];
|
||||
}
|
||||
|
||||
|
||||
if (empty($paymentData)) {
|
||||
RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site);
|
||||
} elseif ($paymentData['type'] == $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) {
|
||||
|
@ -547,7 +532,7 @@ class RetailCrmEvent
|
|||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$paymentToCrm['externalId'] = $paymentData['externalId'];
|
||||
RCrmActions::apiMethod($api, 'paymentEditByExternalId', __METHOD__, $paymentToCrm, $site);
|
||||
} elseif ($paymentData['type'] != $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) {
|
||||
|
@ -559,10 +544,10 @@ class RetailCrmEvent
|
|||
);
|
||||
RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Bitrix\Sale\Payment $event
|
||||
*
|
||||
|
@ -571,22 +556,22 @@ class RetailCrmEvent
|
|||
public function paymentDelete(Payment $event): void
|
||||
{
|
||||
$apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0);
|
||||
|
||||
|
||||
if ((isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY'])
|
||||
|| $apiVersion != 'v5'
|
||||
|| !$event->getId()
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$optionsSitesList = RetailcrmConfigProvider::getSitesList();
|
||||
|
||||
|
||||
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
|
||||
|
||||
$arPayment = [
|
||||
'ID' => $event->getId(),
|
||||
'ORDER_ID' => $event->getField('ORDER_ID'),
|
||||
'LID' => $event->getCollection()->getOrder()->getSiteId(),
|
||||
];
|
||||
|
||||
|
||||
if ($optionsSitesList) {
|
||||
if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) {
|
||||
$site = $optionsSitesList[$arPayment['LID']];
|
||||
|
@ -596,12 +581,12 @@ class RetailCrmEvent
|
|||
} elseif (!$optionsSitesList) {
|
||||
$site = null;
|
||||
}
|
||||
|
||||
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
|
||||
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
|
||||
$api = new ApiClient($api_host, $api_key);
|
||||
|
||||
$apiHost = ConfigProvider::getApiUrl();
|
||||
$apiKey = ConfigProvider::getApiKey();
|
||||
$api = new RetailCrm\ApiClient($apiHost, $apiKey);
|
||||
$orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $arPayment['ORDER_ID'], $site);
|
||||
|
||||
|
||||
if (isset($orderCrm['order']['payments']) && $orderCrm['order']['payments']) {
|
||||
foreach ($orderCrm['order']['payments'] as $payment) {
|
||||
if (isset($payment['externalId'])
|
||||
|
@ -613,4 +598,50 @@ class RetailCrmEvent
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function checkConfig(): bool
|
||||
{
|
||||
if (true == $GLOBALS['ORDER_DELETE_USER_ADMIN']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] === false
|
||||
&& $GLOBALS['RETAILCRM_ORDER_DELETE'] === true
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($GLOBALS['RETAIL_CRM_HISTORY'] === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!RetailcrmDependencyLoader::loadDependencies()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Bitrix\Sale\Order|\Bitrix\Main\Event $event
|
||||
*
|
||||
* @throws \Bitrix\Main\SystemException
|
||||
*/
|
||||
private function getOrderArray($event): ?array
|
||||
{
|
||||
if ($event instanceof Order) {
|
||||
$obOrder = $event;
|
||||
} elseif ($event instanceof Event) {
|
||||
$obOrder = $event->getParameter('ENTITY');
|
||||
} else {
|
||||
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'events', 'event error');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return RetailCrmOrder::orderObjToArr($obOrder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use Intaro\RetailCrm\Repository\AgreementRepository;
|
|||
use Intaro\RetailCrm\Service\CustomerService;
|
||||
use Intaro\RetailCrm\Service\LoyaltyService;
|
||||
|
||||
/** RetailCRM loyalty program start */
|
||||
try {
|
||||
Loader::includeModule('intaro.retailcrm');
|
||||
|
||||
|
@ -18,37 +19,33 @@ try {
|
|||
|
||||
global $USER;
|
||||
|
||||
if ($arResult['LOYALTY_STATUS'] === 'Y' && $USER->IsAuthorized()) {
|
||||
if ('Y' === $arResult['LOYALTY_STATUS'] && $USER->IsAuthorized()) {
|
||||
/** @var CustomerService $customerService */
|
||||
$customerService = ServiceLocator::get(CustomerService::class);
|
||||
$customer = $customerService->createModel($USER->GetID());
|
||||
|
||||
$customerService->createCustomer($customer);
|
||||
|
||||
/* @var LoyaltyService $service*/
|
||||
$service = ServiceLocator::get(LoyaltyService::class);
|
||||
/* @var LoyaltyService $service */
|
||||
$service = ServiceLocator::get(LoyaltyService::class);
|
||||
$arResult['LP_REGISTER'] = $service->checkRegInLp();
|
||||
}
|
||||
|
||||
try {
|
||||
$agreementPersonalData = AgreementRepository::getFirstByWhere(
|
||||
['AGREEMENT_TEXT'],
|
||||
[
|
||||
['CODE', '=', 'AGREEMENT_PERSONAL_DATA_CODE'],
|
||||
]
|
||||
);
|
||||
$agreementLoyaltyProgram = AgreementRepository::getFirstByWhere(
|
||||
['AGREEMENT_TEXT'],
|
||||
[
|
||||
['CODE', '=', 'AGREEMENT_LOYALTY_PROGRAM_CODE'],
|
||||
]
|
||||
);
|
||||
$arResult['AGREEMENT_PERSONAL_DATA'] = $agreementPersonalData['AGREEMENT_TEXT'];
|
||||
$arResult['AGREEMENT_LOYALTY_PROGRAM'] = $agreementLoyaltyProgram['AGREEMENT_TEXT'];
|
||||
} catch (ObjectPropertyException | ArgumentException | SystemException $e) {
|
||||
AddMessage2Log($e->getMessage());
|
||||
}
|
||||
$agreementPersonalData = AgreementRepository::getFirstByWhere(
|
||||
['AGREEMENT_TEXT'],
|
||||
[
|
||||
['CODE', '=', 'AGREEMENT_PERSONAL_DATA_CODE'],
|
||||
]
|
||||
);
|
||||
$agreementLoyaltyProgram = AgreementRepository::getFirstByWhere(
|
||||
['AGREEMENT_TEXT'],
|
||||
[
|
||||
['CODE', '=', 'AGREEMENT_LOYALTY_PROGRAM_CODE'],
|
||||
]
|
||||
);
|
||||
$arResult['AGREEMENT_PERSONAL_DATA'] = $agreementPersonalData['AGREEMENT_TEXT'];
|
||||
$arResult['AGREEMENT_LOYALTY_PROGRAM'] = $agreementLoyaltyProgram['AGREEMENT_TEXT'];
|
||||
} catch (Throwable $exception) {
|
||||
AddMessage2Log($exception->getMessage());
|
||||
}
|
||||
|
||||
/** RetailCRM loyalty program end */
|
||||
|
|
|
@ -75,7 +75,7 @@ if ($arResult["SHOW_SMS_FIELD"] == true) {
|
|||
|
||||
<div class="bx-auth-reg">
|
||||
<?php if ($USER->IsAuthorized()): ?>
|
||||
<?php if ($arResult['LOYALTY_STATUS'] === 'Y'): ?>
|
||||
<?php if ('Y' === $arResult['LOYALTY_STATUS']): ?>
|
||||
<?php $this->addExternalJs(SITE_TEMPLATE_PATH . '/script.js'); ?>
|
||||
<div id="regBody">
|
||||
<?php if (isset($arResult['LP_REGISTER']['msg'])) { ?>
|
||||
|
|
|
@ -24,7 +24,9 @@ try {
|
|||
|
||||
$customer = UserRepository::getById($USER->GetID());
|
||||
|
||||
if ($arResult['LOYALTY_STATUS'] === 'Y'
|
||||
if (
|
||||
$arResult['LOYALTY_STATUS'] === 'Y'
|
||||
&& null !== $customer->getLoyalty()
|
||||
&& $customer->getLoyalty()->getIdInLoyalty() > 0
|
||||
) {
|
||||
/* @var LoyaltyService $service */
|
||||
|
@ -43,7 +45,7 @@ try {
|
|||
$arResult['LL_PRIVILEGE_SIZE'] = $response->loyaltyLevel->privilegeSize;
|
||||
$arResult['LL_PRIVILEGE_SIZE_PROMO'] = $response->loyaltyLevel->privilegeSizePromo;
|
||||
$arResult['LOYALTY_LEVEL_TYPE'] = $response->loyaltyLevel->type;
|
||||
$arResult['NEXT_LEVEL_SUM'] = (int)$response->nextLevelSum === 0 ? '-' : $response->nextLevelSum;
|
||||
$arResult['NEXT_LEVEL_SUM'] = (int) $response->nextLevelSum === 0 ? '-' : $response->nextLevelSum;
|
||||
$arResult['ORDERS_SUM'] = $response->ordersSum;
|
||||
}
|
||||
|
||||
|
@ -52,5 +54,5 @@ try {
|
|||
require_once __DIR__ . '/register.php';
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
die(GetMessage('CARD_NOT_LINKED'));
|
||||
die(GetMessage('MODULE_NOT_INSTALL'));
|
||||
}
|
||||
|
|
|
@ -21,32 +21,32 @@ $arResult['LOYALTY_STATUS'] = ConfigProvider::getLoyaltyProgramStatus();
|
|||
|
||||
global $USER;
|
||||
|
||||
if ($arResult['LOYALTY_STATUS'] === 'Y' && $USER->IsAuthorized()) {
|
||||
if ('Y' === $arResult['LOYALTY_STATUS'] && $USER->IsAuthorized()) {
|
||||
/** @var CustomerService $customerService */
|
||||
$customerService = ServiceLocator::get(CustomerService::class);
|
||||
$customer = $customerService->createModel($USER->GetID());
|
||||
$customer = $customerService->createModel($USER->GetID());
|
||||
|
||||
$customerService->createCustomer($customer);
|
||||
|
||||
/* @var LoyaltyService $service*/
|
||||
$service = ServiceLocator::get(LoyaltyService::class);
|
||||
$service = ServiceLocator::get(LoyaltyService::class);
|
||||
$arResult['LP_REGISTER'] = $service->checkRegInLp();
|
||||
}
|
||||
|
||||
try {
|
||||
$agreementPersonalData = AgreementRepository::getFirstByWhere(
|
||||
$agreementPersonalData = AgreementRepository::getFirstByWhere(
|
||||
['AGREEMENT_TEXT'],
|
||||
[
|
||||
['CODE', '=', 'AGREEMENT_PERSONAL_DATA_CODE'],
|
||||
]
|
||||
);
|
||||
$agreementLoyaltyProgram = AgreementRepository::getFirstByWhere(
|
||||
$agreementLoyaltyProgram = AgreementRepository::getFirstByWhere(
|
||||
['AGREEMENT_TEXT'],
|
||||
[
|
||||
['CODE', '=', 'AGREEMENT_LOYALTY_PROGRAM_CODE'],
|
||||
]
|
||||
);
|
||||
$arResult['AGREEMENT_PERSONAL_DATA'] = $agreementPersonalData['AGREEMENT_TEXT'];
|
||||
$arResult['AGREEMENT_PERSONAL_DATA'] = $agreementPersonalData['AGREEMENT_TEXT'];
|
||||
$arResult['AGREEMENT_LOYALTY_PROGRAM'] = $agreementLoyaltyProgram['AGREEMENT_TEXT'];
|
||||
} catch (ObjectPropertyException | ArgumentException | SystemException $e) {
|
||||
AddMessage2Log($e->getMessage());
|
||||
|
|
|
@ -639,7 +639,7 @@
|
|||
url: this.ajaxUrl,
|
||||
data: this.getData(data),
|
||||
onsuccess: BX.delegate(function(result) {
|
||||
BX.ajax.runAction('intaro:retailcrm.api.loyalty.basket.calculateBasketBonuses',
|
||||
BX.ajax.runAction('intaro:retailcrm.api.loyalty.basket.addLoyaltyToBasket',
|
||||
{
|
||||
method: 'POST',
|
||||
data: {
|
||||
|
|
|
@ -15,7 +15,7 @@ use Intaro\RetailCrm\Component\ServiceLocator;
|
|||
use Intaro\RetailCrm\Model\Api\Response\Loyalty\LoyaltyCalculateResponse;
|
||||
use Intaro\RetailCrm\Service\LoyaltyService;
|
||||
|
||||
/** RetailCRM loyalty program Start*/
|
||||
/** RetailCRM loyalty program start*/
|
||||
try {
|
||||
Main\Loader::includeModule('intaro.retailcrm');
|
||||
|
||||
|
@ -26,16 +26,16 @@ try {
|
|||
$service = ServiceLocator::get(LoyaltyService::class);
|
||||
|
||||
if ($arResult['LOYALTY_STATUS'] === 'Y' && $arResult['PERSONAL_LOYALTY_STATUS'] === true) {
|
||||
$calculate = $service->calculateBonus($arResult['BASKET_ITEM_RENDER_DATA']);
|
||||
$calculate = $service->getLoyaltyCalculate($arResult['BASKET_ITEM_RENDER_DATA']);
|
||||
|
||||
if ($calculate instanceof LoyaltyCalculateResponse && $calculate->success) {
|
||||
$arResult = $service->calculateBasket($arResult, $calculate);
|
||||
$arResult = $service->addLoyaltyToBasket($arResult, $calculate);
|
||||
}
|
||||
}
|
||||
} catch (Throwable $exception) {
|
||||
AddMessage2Log($exception->getMessage());
|
||||
}
|
||||
/** RetailCRM loyalty program End*/
|
||||
/** RetailCRM loyalty program end */
|
||||
|
||||
$defaultParams = [
|
||||
'TEMPLATE_THEME' => 'blue',
|
||||
|
|
|
@ -17,7 +17,7 @@ if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
|
|||
* @var SaleOrderAjax $component
|
||||
*/
|
||||
|
||||
/** RetailCRM loyalty program Start*/
|
||||
/** RetailCRM loyalty program start */
|
||||
try {
|
||||
Loader::includeModule('intaro.retailcrm');
|
||||
|
||||
|
@ -29,7 +29,7 @@ try {
|
|||
$service = ServiceLocator::get(LoyaltyService::class);
|
||||
|
||||
/** @var LoyaltyCalculateResponse $calculate */
|
||||
$calculate = $service->calculateBonus($arResult['BASKET_ITEMS']);
|
||||
$calculate = $service->getLoyaltyCalculate($arResult['BASKET_ITEMS']);
|
||||
|
||||
if ($calculate instanceof LoyaltyCalculateResponse && $calculate->success) {
|
||||
$arResult = $service->calculateOrderBasket($arResult, $calculate);
|
||||
|
@ -45,7 +45,7 @@ try {
|
|||
} catch (Throwable $exception) {
|
||||
AddMessage2Log($exception->getMessage());
|
||||
}
|
||||
/** RetailCRM loyalty program End*/
|
||||
/** RetailCRM loyalty program end */
|
||||
|
||||
$component = $this->__component;
|
||||
|
||||
|
|
|
@ -202,8 +202,7 @@ class EventsHandlers
|
|||
self::$disableSaleHandler = false;
|
||||
}
|
||||
} catch (Throwable $exception) {
|
||||
$logger = Logger::getInstance();
|
||||
$logger->write(GetMessage('CAN_NOT_SAVE_ORDER') . $exception->getMessage(), 'uploadApiErrors');
|
||||
Logger::getInstance()->write(GetMessage('CAN_NOT_SAVE_ORDER') . $exception->getMessage(), 'uploadApiErrors');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,21 +37,24 @@ class Basket extends Controller
|
|||
*/
|
||||
public function __construct(Request $request = null)
|
||||
{
|
||||
/** @var LoyaltyService */
|
||||
$this->service = ServiceLocator::get(LoyaltyService::class);
|
||||
parent::__construct($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет данные, полученные при расчете привилегии, в массив корзины
|
||||
*
|
||||
* @param array $basketData
|
||||
* @return array
|
||||
*/
|
||||
public function calculateBasketBonusesAction(array $basketData): array
|
||||
public function addLoyaltyToBasketAction(array $basketData): array
|
||||
{
|
||||
$calculateBasket = [];
|
||||
$calculate = $this->service->calculateBonus($basketData['BASKET_ITEM_RENDER_DATA']);
|
||||
$calculate = $this->service->getLoyaltyCalculate($basketData['BASKET_ITEM_RENDER_DATA']);
|
||||
|
||||
if ($calculate->success) {
|
||||
$calculateBasket = $this->service->calculateBasket($basketData, $calculate);
|
||||
$calculateBasket = $this->service->addLoyaltyToBasket($basketData, $calculate);
|
||||
}
|
||||
|
||||
return $calculateBasket;
|
||||
|
|
|
@ -42,7 +42,7 @@ class Order extends Controller
|
|||
{
|
||||
/** @var LoyaltyService $service */
|
||||
$service = ServiceLocator::get(LoyaltyService::class);
|
||||
$response = $service->calculateBonus($basketItems, $inputBonuses);
|
||||
$response = $service->getLoyaltyCalculate($basketItems, $inputBonuses);
|
||||
|
||||
if ($response instanceof LoyaltyCalculateResponse) {
|
||||
if ($response->success && count($response->order->items) > 0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue