From a43881166b97e7d75b546452d679c0fc614fc43c Mon Sep 17 00:00:00 2001 From: DanielWeiser <46303277+DanielWeiser@users.noreply.github.com> Date: Wed, 22 Jul 2020 15:11:27 +0300 Subject: [PATCH] Unset integration delivery fields on orders edit method --- .../classes/general/RCrmActions.php | 3 +- .../classes/general/RetailcrmConstants.php | 1 + .../classes/general/icml/RetailCrmICML.php | 3 +- .../general/order/RetailCrmOrder_v5.php | 4 ++ .../general/services/RetailCrmService.php | 39 ++++++++++++ intaro.retailcrm/include.php | 3 +- intaro.retailcrm/options.php | 14 +++-- .../general/services/RetailCrmServiceTest.php | 62 +++++++++++++++++++ 8 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 intaro.retailcrm/classes/general/services/RetailCrmService.php create mode 100644 tests/classes/general/services/RetailCrmServiceTest.php diff --git a/intaro.retailcrm/classes/general/RCrmActions.php b/intaro.retailcrm/classes/general/RCrmActions.php index 450b8d7f..7f29adaf 100644 --- a/intaro.retailcrm/classes/general/RCrmActions.php +++ b/intaro.retailcrm/classes/general/RCrmActions.php @@ -510,6 +510,7 @@ class RCrmActions 'params' => $params ), 'uploadApiErrors'); } else { + self::eventLog( __CLASS__ . '::' . $method, 'RetailCrm\ApiClient::' . $methodApi, @@ -520,7 +521,7 @@ class RCrmActions 'methodApi' => $methodApi, 'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '', 'errors' => !empty($result['errors']) ? $result['errors'] : '', - 'params' => $params + 'params' => $params, ), 'apiErrors'); } diff --git a/intaro.retailcrm/classes/general/RetailcrmConstants.php b/intaro.retailcrm/classes/general/RetailcrmConstants.php index 2ce0b809..4dc323d5 100644 --- a/intaro.retailcrm/classes/general/RetailcrmConstants.php +++ b/intaro.retailcrm/classes/general/RetailcrmConstants.php @@ -75,4 +75,5 @@ class RetailcrmConstants const CRM_CATALOG_BASE_PRICE = 'catalog_base_price'; const CRM_ORDER_DIMENSIONS = 'order_dimensions'; const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED'; + const CRM_INTEGRATION_DELIVERY = 'integration_delivery'; } diff --git a/intaro.retailcrm/classes/general/icml/RetailCrmICML.php b/intaro.retailcrm/classes/general/icml/RetailCrmICML.php index c7dff1f9..719d22ef 100644 --- a/intaro.retailcrm/classes/general/icml/RetailCrmICML.php +++ b/intaro.retailcrm/classes/general/icml/RetailCrmICML.php @@ -380,7 +380,8 @@ class RetailCrmICML // Set filter $filter = array( - "IBLOCK_ID" => $id + "IBLOCK_ID" => $id, + "ACTIVE" => 'Y', ); $order = array("id"); $arNavStatParams = array( diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php index b900eb8a..b68b253e 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php @@ -297,6 +297,10 @@ class RetailCrmOrder } } + if ('ordersEdit' === $methodApi) { + $order = RetailCrmService::unsetIntegrationDeliveryFields($order); + } + $normalizer = new RestNormalizer(); $order = $normalizer->normalize($order, 'orders'); diff --git a/intaro.retailcrm/classes/general/services/RetailCrmService.php b/intaro.retailcrm/classes/general/services/RetailCrmService.php new file mode 100644 index 00000000..4820f9a7 --- /dev/null +++ b/intaro.retailcrm/classes/general/services/RetailCrmService.php @@ -0,0 +1,39 @@ + 'classes/general/BuilderBase.php', 'AddressBuilder' => 'classes/general/AddressBuilder.php', 'AbstractBuilder' => 'classes/general/AbstractBuilder.php', - 'BaseModel' => 'classes/general/Model/BaseModel.php' + 'BaseModel' => 'classes/general/Model/BaseModel.php', + 'RetailCrmService' => 'classes/general/services/RetailCrmService.php', ) ); diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index dc89209e..3d6bb143 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -607,13 +607,17 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { echo CAdminMessage::ShowMessage(GetMessage('ERR_JSON')); } - $delivTypes = array(); - foreach ($arResult['deliveryTypesList'] as $delivType) { - if ($delivType['active'] === true) { - $delivTypes[$delivType['code']] = $delivType; + $deliveryTypes = array(); + $deliveryIntegrationCode = array(); + foreach ($arResult['deliveryTypesList'] as $deliveryType) { + if ($deliveryType['active'] === true) { + $deliveryTypes[$deliveryType['code']] = $deliveryType; + $deliveryIntegrationCode[$deliveryType['code']] = $deliveryType['integrationCode']; } } - $arResult['deliveryTypesList'] = $delivTypes; + + $arResult['deliveryTypesList'] = $deliveryTypes; + COption::SetOptionString($mid, RetailcrmConstants::CRM_INTEGRATION_DELIVERY, serialize(RCrmActions::clearArr($deliveryIntegrationCode))); //bitrix orderTypesList -- personTypes $arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']); diff --git a/tests/classes/general/services/RetailCrmServiceTest.php b/tests/classes/general/services/RetailCrmServiceTest.php new file mode 100644 index 00000000..dc01b8fa --- /dev/null +++ b/tests/classes/general/services/RetailCrmServiceTest.php @@ -0,0 +1,62 @@ + '5958C', + 'externalId' => '8', + 'createdAt' => '2020-06-22 16:47:49', + 'customer' => array ( + 'externalId' => '3', + ), + 'orderType' => 'eshop-individual', + 'status' => 'prepayed', + 'delivery' => array ( + 'cost' => '0', + 'address' => array ( + 'text' => 'ул. Первомайская 41', + ), + 'code' => 'boxberry', + ), + 'contragent' => array ( + 'contragentType' => 'individual', + ), + 'discountManualAmount' => '0', + 'discountManualPercent' => '0', + 'items' => array ( + array ( + 'externalIds' => array ( + array ( + 'code' => 'bitrix', + 'value' => '0_88', + ), + ), + 'quantity' => '1', + 'offer' => array ( + 'externalId' => '88', + 'xmlId' => '248', + ), + 'productName' => 'Agustí Torelló Mata GR Barrica 2011', + 'id' => '9072', + 'discountManualPercent' => '0', + 'discountManualAmount' => '0', + 'initialPrice' => '21.25', + ), + ), + ); + + public function testOnUnsetIntegrationDeliveryFields() + { + $newParams = RetailCrmService::unsetIntegrationDeliveryFields($this->paramsExample); + $expectedArray = $this->paramsExample; + unset($expectedArray['firstName']); + unset($expectedArray['lastName']); + unset($expectedArray['delivery']['address']); + unset($expectedArray['delivery']['cost']); + + $this->assertEquals($newParams, $expectedArray); + } +}