From 4f2bc1a1b1c5ae06dc1ab02d3fd1fd2fda8cfead Mon Sep 17 00:00:00 2001 From: RenCurs <34103666+RenCurs@users.noreply.github.com> Date: Mon, 19 Apr 2021 15:38:09 +0300 Subject: [PATCH] Remove status from integration payment (#192) --- .../classes/general/RCrmActions.php | 1 - .../general/RetailcrmConfigProvider.php | 35 ++++++++ .../classes/general/RetailcrmConstants.php | 1 + .../classes/general/events/RetailCrmEvent.php | 14 +++- .../general/order/RetailCrmOrder_v5.php | 5 +- .../general/services/RetailCrmService.php | 44 ++++++++++- intaro.retailcrm/install/index.php | 21 +++-- intaro.retailcrm/install/step2.php | 9 ++- intaro.retailcrm/lang/en/install/step2.php | 2 + intaro.retailcrm/lang/en/options.php | 2 + intaro.retailcrm/lang/ru/install/step2.php | 2 + intaro.retailcrm/lang/ru/options.php | 2 + intaro.retailcrm/options.php | 43 ++++++---- .../general/order/RetailCrmOrderTest.php | 79 +++++++++++++++++++ 14 files changed, 226 insertions(+), 34 deletions(-) diff --git a/intaro.retailcrm/classes/general/RCrmActions.php b/intaro.retailcrm/classes/general/RCrmActions.php index b1898d53..586bb64d 100644 --- a/intaro.retailcrm/classes/general/RCrmActions.php +++ b/intaro.retailcrm/classes/general/RCrmActions.php @@ -464,7 +464,6 @@ class RCrmActions case 'paymentEditByExternalId': return self::proxy($api, 'ordersPaymentEdit', $method, array($params, 'externalId', $site)); - default: return self::proxy($api, $methodApi, $method, array($params, $site)); } diff --git a/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php b/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php index 40f623e3..68e88ba0 100644 --- a/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php +++ b/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php @@ -66,6 +66,9 @@ class RetailcrmConfigProvider /** @var array $paymentTypes */ private static $paymentTypes; + /** @var array $integrationPayment */ + private static $integrationPayment; + /** @var array $paymentStatuses */ private static $paymentStatuses; @@ -295,6 +298,38 @@ class RetailcrmConfigProvider return static::$paymentTypes; } + /** + * getIntegrationPaymentTypes + * + * @return array + */ + public static function getIntegrationPaymentTypes(): array + { + if (self::isEmptyNotZero(static::$integrationPayment)) { + static::$integrationPayment = static::getUnserializedOption(RetailcrmConstants::CRM_INTEGRATION_PAYMENT); + } + + return static::$integrationPayment; + } + + /** + * setIntegrationPaymentTypes + * @param $integrationPayment + */ + public static function setIntegrationPaymentTypes($integrationPayment) + { + static::setOption(RetailcrmConstants::CRM_INTEGRATION_PAYMENT, serialize(RCrmActions::clearArr($integrationPayment))); + } + + /** + * setIntegrationDelivery + * @param $deliveryIntegrationCode + */ + public static function setIntegrationDelivery($deliveryIntegrationCode) + { + static::setOption(RetailcrmConstants::CRM_INTEGRATION_DELIVERY, serialize(RCrmActions::clearArr($deliveryIntegrationCode))); + } + /** * setPaymentTypes * diff --git a/intaro.retailcrm/classes/general/RetailcrmConstants.php b/intaro.retailcrm/classes/general/RetailcrmConstants.php index 88ae0376..dbde20cd 100644 --- a/intaro.retailcrm/classes/general/RetailcrmConstants.php +++ b/intaro.retailcrm/classes/general/RetailcrmConstants.php @@ -28,6 +28,7 @@ class RetailcrmConstants const CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr'; const CRM_DELIVERY_SERVICES_ARR = 'deliv_services_arr'; const CRM_PAYMENT_TYPES = 'pay_types_arr'; + const CRM_INTEGRATION_PAYMENT = 'integration_payment'; const CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; const CRM_PAYMENT = 'payment_arr'; //order payment Y/N const CRM_ORDER_LAST_ID = 'order_last_id'; diff --git a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php index 4723e3ab..e1d7db8d 100644 --- a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php +++ b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php @@ -441,6 +441,7 @@ class RetailCrmEvent $optionsSitesList = RetailcrmConfigProvider::getSitesList(); $optionsPaymentTypes = RetailcrmConfigProvider::getPaymentTypes(); $optionsPayStatuses = RetailcrmConfigProvider::getPayment(); + $integrationPaymentTypes = RetailcrmConfigProvider::getIntegrationPaymentTypes(); $arPayment = array( 'ID' => $event->getId(), @@ -462,9 +463,7 @@ class RetailCrmEvent $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 RetailCrm\ApiClient($api_host, $api_key); + $api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); $orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $arPayment['ORDER_ID'], $site); if (isset($orderCrm['order'])) { @@ -531,6 +530,15 @@ class RetailCrmEvent if (empty($paymentData)) { RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site); } elseif ($paymentData['type'] == $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) { + if (in_array($paymentData['type'], $integrationPaymentTypes)) { + RCrmActions::eventLog( + 'RetailCrmEvent::paymentSave', + 'payments', + 'OrderID = ' . $arPayment['ID'] . '. Integration payment detected, which is not editable.' + ); + return false; + } + $paymentToCrm['externalId'] = $paymentData['externalId']; RCrmActions::apiMethod($api, 'paymentEditByExternalId', __METHOD__, $paymentToCrm, $site); } elseif ($paymentData['type'] != $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) { diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php index 436000fd..068cfc4a 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php @@ -252,6 +252,7 @@ class RetailCrmOrder $order['weight'] = $weight; } + $integrationPayment = RetailcrmConfigProvider::getIntegrationPaymentTypes(); //payments $payments = array(); foreach ($arFields['PAYMENTS'] as $payment) { @@ -269,7 +270,9 @@ class RetailCrmOrder } if (!empty($arParams['optionsPayment'][$payment['PAID']])) { - $pm['status'] = $arParams['optionsPayment'][$payment['PAID']]; + if (array_search($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']], $integrationPayment) === false) { + $pm['status'] = $arParams['optionsPayment'][$payment['PAID']]; + } } if (RetailcrmConfigProvider::shouldSendPaymentAmount()) { diff --git a/intaro.retailcrm/classes/general/services/RetailCrmService.php b/intaro.retailcrm/classes/general/services/RetailCrmService.php index c05715fd..c6e08aac 100644 --- a/intaro.retailcrm/classes/general/services/RetailCrmService.php +++ b/intaro.retailcrm/classes/general/services/RetailCrmService.php @@ -13,10 +13,10 @@ class RetailCrmService public static function unsetIntegrationDeliveryFields(array $order): array { $integrationDelivery = RetailcrmConfigProvider::getCrmIntegrationDelivery(); - + if (isset($order['delivery']['code'])) { $deliveryCode = $order['delivery']['code']; - + if (!empty($integrationDelivery[$deliveryCode]) && $integrationDelivery[$deliveryCode] !== 'sdek' && $integrationDelivery[$deliveryCode] !== 'dpd' @@ -32,7 +32,7 @@ class RetailCrmService unset($order['delivery']['address']); unset($order['delivery']['data']); } - + switch ($integrationDelivery[$deliveryCode]) { case "sdek": unset($order['weight']); @@ -71,7 +71,43 @@ class RetailCrmService break; } } - + return $order; } + + /** + * @param array $data + * + * @return array + */ + public static function selectIntegrationDeliveries(array $data): array + { + $result = []; + + foreach ($data as $elem) { + if (!empty($elem['integrationCode'])) { + $result[$elem['code']] = $elem['integrationCode']; + } + } + + return $result; + } + + /** + * @param array $data + * + * @return array + */ + public static function selectIntegrationPayments(array $data): array + { + $result = []; + + foreach ($data as $elem) { + if (!empty($elem['integrationModule'])) { + $result[] = $elem['code']; + } + } + + return $result; + } } diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index 082f3b55..a0433735 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -144,14 +144,14 @@ class intaro_retailcrm extends CModule include($this->INSTALL_PATH . '/../classes/general/services/RetailCrmService.php'); $version = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_VERSION, 0); - if ($version == 'v4') { - include($this->INSTALL_PATH . '/../classes/general/ApiClient_v4.php'); - include($this->INSTALL_PATH . '/../classes/general/order/RetailCrmOrder_v4.php'); - include($this->INSTALL_PATH . '/../classes/general/history/RetailCrmHistory_v4.php'); - } elseif ($version == 'v5') { + if ($version == 'v5') { include($this->INSTALL_PATH . '/../classes/general/ApiClient_v5.php'); include($this->INSTALL_PATH . '/../classes/general/order/RetailCrmOrder_v5.php'); include($this->INSTALL_PATH . '/../classes/general/history/RetailCrmHistory_v5.php'); + } elseif ($version == 'v4') { + include($this->INSTALL_PATH . '/../classes/general/ApiClient_v4.php'); + include($this->INSTALL_PATH . '/../classes/general/order/RetailCrmOrder_v4.php'); + include($this->INSTALL_PATH . '/../classes/general/history/RetailCrmHistory_v4.php'); } $step = intval($_REQUEST['step']); @@ -387,6 +387,17 @@ class intaro_retailcrm extends CModule $delivTypes[$delivType['code']] = $delivType; } } + + $this->loadDeps(); + + RetailcrmConfigProvider::setIntegrationDelivery( + RetailCrmService::selectIntegrationDeliveries($arResult['deliveryTypesList']) + ); + + RetailcrmConfigProvider::setIntegrationPaymentTypes( + RetailCrmService::selectIntegrationPayments($arResult['paymentTypesList']) + ); + $arResult['deliveryTypesList'] = $delivTypes; //bitrix personTypes diff --git a/intaro.retailcrm/install/step2.php b/intaro.retailcrm/install/step2.php index 91851bb3..abb23c7a 100644 --- a/intaro.retailcrm/install/step2.php +++ b/intaro.retailcrm/install/step2.php @@ -233,7 +233,8 @@ else{