fix unseting delivery fields method (#141)
This commit is contained in:
parent
82d6c10c07
commit
ec8f5ac661
@ -624,6 +624,16 @@ class RetailcrmConfigProvider
|
|||||||
return COption::GetOptionString("main", "new_user_phone_required") === 'Y';
|
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(...)
|
* Wraps Bitrix COption::GetOptionString(...)
|
||||||
*
|
*
|
||||||
|
@ -1,39 +1,77 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class RetailCrmService
|
||||||
|
*/
|
||||||
class RetailCrmService
|
class RetailCrmService
|
||||||
{
|
{
|
||||||
public static function unsetIntegrationDeliveryFields($order)
|
/**
|
||||||
|
* @param $order
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function unsetIntegrationDeliveryFields(array $order): array
|
||||||
{
|
{
|
||||||
$integrationDelivery = unserialize(COption::GetOptionString(RetailcrmConstants::MODULE_ID, RetailcrmConstants::CRM_INTEGRATION_DELIVERY, 0));
|
$integrationDelivery = RetailcrmConfigProvider::getCrmIntegrationDelivery();
|
||||||
$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']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (isset($order['delivery']['code'])) {
|
||||||
|
$deliveryCode = $order['delivery']['code'];
|
||||||
|
|
||||||
|
if (!empty($integrationDelivery[$deliveryCode])
|
||||||
|
&& $integrationDelivery[$deliveryCode] !== 'sdek'
|
||||||
|
&& $integrationDelivery[$deliveryCode] !== 'dpd'
|
||||||
|
&& $integrationDelivery[$deliveryCode] !== 'newpost'
|
||||||
|
) {
|
||||||
unset($order['weight']);
|
unset($order['weight']);
|
||||||
|
unset($order['firstName']);
|
||||||
|
unset($order['lastName']);
|
||||||
unset($order['phone']);
|
unset($order['phone']);
|
||||||
unset($order['delivery']['cost']);
|
unset($order['delivery']['cost']);
|
||||||
|
unset($order['paymentType']);
|
||||||
unset($order['shipmentStore']);
|
unset($order['shipmentStore']);
|
||||||
unset($order['delivery']['address']);
|
unset($order['delivery']['address']);
|
||||||
unset($order['delivery']['data']);
|
unset($order['delivery']['data']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch ($integrationDelivery[$deliveryCode]) {
|
||||||
|
case "sdek":
|
||||||
|
unset($order['weight']);
|
||||||
|
unset($order['length']);
|
||||||
|
unset($order['width']);
|
||||||
|
unset($order['height']);
|
||||||
|
unset($order['phone']);
|
||||||
|
unset($order['delivery']['cost']);
|
||||||
|
unset($order['paymentType']);
|
||||||
|
unset($order['shipmentStore']);
|
||||||
|
unset($order['number']);
|
||||||
|
unset($order['delivery']['address']);
|
||||||
|
unset($order['delivery']['data']);
|
||||||
|
break;
|
||||||
|
case "dpd":
|
||||||
|
unset($order['weight']);
|
||||||
|
unset($order['manager']);
|
||||||
|
unset($order['phone']);
|
||||||
|
unset($order['firstName']);
|
||||||
|
unset($order['lastName']);
|
||||||
|
unset($order['delivery']['cost']);
|
||||||
|
unset($order['paymentType']);
|
||||||
|
unset($order['shipmentStore']);
|
||||||
|
unset($order['delivery']['address']);
|
||||||
|
unset($order['delivery']['data']);
|
||||||
|
break;
|
||||||
|
case "newpost":
|
||||||
|
unset($order['weight']);
|
||||||
|
unset($order['customer']);
|
||||||
|
unset($order['phone']);
|
||||||
|
unset($order['shipmentStore']);
|
||||||
|
unset($order['paymentType']);
|
||||||
|
unset($order['delivery']['cost']);
|
||||||
|
unset($order['delivery']['address']);
|
||||||
|
unset($order['delivery']['data']);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $order;
|
return $order;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,57 +5,31 @@
|
|||||||
*/
|
*/
|
||||||
class RetailCrmServiceTest extends PHPUnit\Framework\TestCase
|
class RetailCrmServiceTest extends PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
private $paramsExample = array (
|
private $paramsExample = [
|
||||||
'number' => '5958C',
|
'delivery' => [
|
||||||
'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',
|
'code' => 'boxberry',
|
||||||
),
|
'cost' => 'test',
|
||||||
'contragent' => array (
|
'address' => 'test',
|
||||||
'contragentType' => 'individual',
|
'data' => 'test',
|
||||||
),
|
],
|
||||||
'discountManualAmount' => '0',
|
'weight' => 'test',
|
||||||
'discountManualPercent' => '0',
|
'firstName' => 'test',
|
||||||
'items' => array (
|
'lastName' => 'test',
|
||||||
array (
|
'phone' => 'test',
|
||||||
'externalIds' => array (
|
'paymentType' => 'test',
|
||||||
array (
|
'shipmentStore' => 'test',
|
||||||
'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()
|
public function testOnUnsetIntegrationDeliveryFields()
|
||||||
{
|
{
|
||||||
|
$value = serialize(['boxberry' => 'test']);
|
||||||
|
COption::SetOptionString(RetailcrmConstants::MODULE_ID, RetailcrmConstants::CRM_INTEGRATION_DELIVERY, $value);
|
||||||
$newParams = RetailCrmService::unsetIntegrationDeliveryFields($this->paramsExample);
|
$newParams = RetailCrmService::unsetIntegrationDeliveryFields($this->paramsExample);
|
||||||
$expectedArray = $this->paramsExample;
|
$expectedArray = [
|
||||||
unset($expectedArray['firstName']);
|
'delivery' => [
|
||||||
unset($expectedArray['lastName']);
|
'code' => 'boxberry',
|
||||||
unset($expectedArray['delivery']['address']);
|
],
|
||||||
unset($expectedArray['delivery']['cost']);
|
];
|
||||||
|
|
||||||
$this->assertEquals($newParams, $expectedArray);
|
$this->assertEquals($newParams, $expectedArray);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user