Unset integration delivery fields on orders edit method
This commit is contained in:
parent
09f82bcfdf
commit
a43881166b
@ -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');
|
||||
}
|
||||
|
||||
|
@ -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';
|
||||
}
|
||||
|
@ -380,7 +380,8 @@ class RetailCrmICML
|
||||
|
||||
// Set filter
|
||||
$filter = array(
|
||||
"IBLOCK_ID" => $id
|
||||
"IBLOCK_ID" => $id,
|
||||
"ACTIVE" => 'Y',
|
||||
);
|
||||
$order = array("id");
|
||||
$arNavStatParams = array(
|
||||
|
@ -297,6 +297,10 @@ class RetailCrmOrder
|
||||
}
|
||||
}
|
||||
|
||||
if ('ordersEdit' === $methodApi) {
|
||||
$order = RetailCrmService::unsetIntegrationDeliveryFields($order);
|
||||
}
|
||||
|
||||
$normalizer = new RestNormalizer();
|
||||
$order = $normalizer->normalize($order, 'orders');
|
||||
|
||||
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
class RetailCrmService
|
||||
{
|
||||
public static function unsetIntegrationDeliveryFields($order)
|
||||
{
|
||||
$integrationDelivery = unserialize(COption::GetOptionString(RetailcrmConstants::MODULE_ID, RetailcrmConstants::CRM_INTEGRATION_DELIVERY, 0));
|
||||
$deliveryCode = $order['delivery']['code'];
|
||||
if ($deliveryCode) {
|
||||
switch ($integrationDelivery[$deliveryCode]) {
|
||||
case "sdek":
|
||||
unset($order['number']);
|
||||
unset($order['height']);
|
||||
unset($order['length']);
|
||||
unset($order['width']);
|
||||
break;
|
||||
case "dpd":
|
||||
unset($order['manager']);
|
||||
unset($order['firstName']);
|
||||
unset($order['lastName']);
|
||||
break;
|
||||
case "newpost":
|
||||
unset($order['customer']);
|
||||
break;
|
||||
default:
|
||||
unset($order['firstName']);
|
||||
unset($order['lastName']);
|
||||
}
|
||||
|
||||
unset($order['weight']);
|
||||
unset($order['phone']);
|
||||
unset($order['delivery']['cost']);
|
||||
unset($order['shipmentStore']);
|
||||
unset($order['delivery']['address']);
|
||||
unset($order['delivery']['data']);
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
}
|
@ -37,6 +37,7 @@ CModule::AddAutoloadClasses(
|
||||
'BuilderBase' => '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',
|
||||
)
|
||||
);
|
||||
|
@ -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']);
|
||||
|
62
tests/classes/general/services/RetailCrmServiceTest.php
Normal file
62
tests/classes/general/services/RetailCrmServiceTest.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class RetailCrmServiceTest
|
||||
*/
|
||||
class RetailCrmServiceTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $paramsExample = array (
|
||||
'number' => '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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user