From ec8f5ac661a3d27034f06b4f7bf0a39a6e7e4c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=A7=D0=B0=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2?= <45812598+Chazovs@users.noreply.github.com> Date: Mon, 28 Sep 2020 13:02:03 +0300 Subject: [PATCH] fix unseting delivery fields method (#141) --- .../general/RetailcrmConfigProvider.php | 12 ++- .../general/services/RetailCrmService.php | 72 +++++++++++++----- .../general/services/RetailCrmServiceTest.php | 74 ++++++------------- 3 files changed, 90 insertions(+), 68 deletions(-) diff --git a/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php b/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php index 5b750462..09639809 100644 --- a/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php +++ b/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php @@ -623,7 +623,17 @@ class RetailcrmConfigProvider { return COption::GetOptionString("main", "new_user_phone_required") === 'Y'; } - + + /** + * Return integration_delivery option + * + * @return mixed + */ + public static function getCrmIntegrationDelivery() + { + return static::getUnserializedOption(RetailcrmConstants::CRM_INTEGRATION_DELIVERY); + } + /** * Wraps Bitrix COption::GetOptionString(...) * diff --git a/intaro.retailcrm/classes/general/services/RetailCrmService.php b/intaro.retailcrm/classes/general/services/RetailCrmService.php index 4820f9a7..c05715fd 100644 --- a/intaro.retailcrm/classes/general/services/RetailCrmService.php +++ b/intaro.retailcrm/classes/general/services/RetailCrmService.php @@ -1,39 +1,77 @@ '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', - ), - ), - ); - + private $paramsExample = [ + 'delivery' => [ + 'code' => 'boxberry', + 'cost' => 'test', + 'address' => 'test', + 'data' => 'test', + ], + 'weight' => 'test', + 'firstName' => 'test', + 'lastName' => 'test', + 'phone' => 'test', + 'paymentType' => 'test', + 'shipmentStore' => 'test', + ]; + 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']); - + $value = serialize(['boxberry' => 'test']); + COption::SetOptionString(RetailcrmConstants::MODULE_ID, RetailcrmConstants::CRM_INTEGRATION_DELIVERY, $value); + $newParams = RetailCrmService::unsetIntegrationDeliveryFields($this->paramsExample); + $expectedArray = [ + 'delivery' => [ + 'code' => 'boxberry', + ], + ]; + $this->assertEquals($newParams, $expectedArray); } }