fix unseting delivery fields method (#141)
This commit is contained in:
parent
82d6c10c07
commit
ec8f5ac661
@ -623,7 +623,17 @@ 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) {
|
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['firstName']);
|
||||||
|
unset($order['lastName']);
|
||||||
|
unset($order['phone']);
|
||||||
|
unset($order['delivery']['cost']);
|
||||||
|
unset($order['paymentType']);
|
||||||
|
unset($order['shipmentStore']);
|
||||||
|
unset($order['delivery']['address']);
|
||||||
|
unset($order['delivery']['data']);
|
||||||
|
}
|
||||||
|
|
||||||
switch ($integrationDelivery[$deliveryCode]) {
|
switch ($integrationDelivery[$deliveryCode]) {
|
||||||
case "sdek":
|
case "sdek":
|
||||||
unset($order['number']);
|
unset($order['weight']);
|
||||||
unset($order['height']);
|
|
||||||
unset($order['length']);
|
unset($order['length']);
|
||||||
unset($order['width']);
|
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;
|
break;
|
||||||
case "dpd":
|
case "dpd":
|
||||||
|
unset($order['weight']);
|
||||||
unset($order['manager']);
|
unset($order['manager']);
|
||||||
|
unset($order['phone']);
|
||||||
unset($order['firstName']);
|
unset($order['firstName']);
|
||||||
unset($order['lastName']);
|
unset($order['lastName']);
|
||||||
|
unset($order['delivery']['cost']);
|
||||||
|
unset($order['paymentType']);
|
||||||
|
unset($order['shipmentStore']);
|
||||||
|
unset($order['delivery']['address']);
|
||||||
|
unset($order['delivery']['data']);
|
||||||
break;
|
break;
|
||||||
case "newpost":
|
case "newpost":
|
||||||
|
unset($order['weight']);
|
||||||
unset($order['customer']);
|
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;
|
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;
|
return $order;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,58 +5,32 @@
|
|||||||
*/
|
*/
|
||||||
class RetailCrmServiceTest extends PHPUnit\Framework\TestCase
|
class RetailCrmServiceTest extends PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
private $paramsExample = array (
|
private $paramsExample = [
|
||||||
'number' => '5958C',
|
'delivery' => [
|
||||||
'externalId' => '8',
|
'code' => 'boxberry',
|
||||||
'createdAt' => '2020-06-22 16:47:49',
|
'cost' => 'test',
|
||||||
'customer' => array (
|
'address' => 'test',
|
||||||
'externalId' => '3',
|
'data' => 'test',
|
||||||
),
|
],
|
||||||
'orderType' => 'eshop-individual',
|
'weight' => 'test',
|
||||||
'status' => 'prepayed',
|
'firstName' => 'test',
|
||||||
'delivery' => array (
|
'lastName' => 'test',
|
||||||
'cost' => '0',
|
'phone' => 'test',
|
||||||
'address' => array (
|
'paymentType' => 'test',
|
||||||
'text' => 'ул. Первомайская 41',
|
'shipmentStore' => 'test',
|
||||||
),
|
];
|
||||||
'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()
|
public function testOnUnsetIntegrationDeliveryFields()
|
||||||
{
|
{
|
||||||
$newParams = RetailCrmService::unsetIntegrationDeliveryFields($this->paramsExample);
|
$value = serialize(['boxberry' => 'test']);
|
||||||
$expectedArray = $this->paramsExample;
|
COption::SetOptionString(RetailcrmConstants::MODULE_ID, RetailcrmConstants::CRM_INTEGRATION_DELIVERY, $value);
|
||||||
unset($expectedArray['firstName']);
|
$newParams = RetailCrmService::unsetIntegrationDeliveryFields($this->paramsExample);
|
||||||
unset($expectedArray['lastName']);
|
$expectedArray = [
|
||||||
unset($expectedArray['delivery']['address']);
|
'delivery' => [
|
||||||
unset($expectedArray['delivery']['cost']);
|
'code' => 'boxberry',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
$this->assertEquals($newParams, $expectedArray);
|
$this->assertEquals($newParams, $expectedArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user