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 integration_delivery option
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getCrmIntegrationDelivery()
|
||||
{
|
||||
return static::getUnserializedOption(RetailcrmConstants::CRM_INTEGRATION_DELIVERY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps Bitrix COption::GetOptionString(...)
|
||||
*
|
||||
|
@ -1,39 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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));
|
||||
$deliveryCode = $order['delivery']['code'];
|
||||
if ($deliveryCode) {
|
||||
$integrationDelivery = RetailcrmConfigProvider::getCrmIntegrationDelivery();
|
||||
|
||||
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]) {
|
||||
case "sdek":
|
||||
unset($order['number']);
|
||||
unset($order['height']);
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -5,58 +5,32 @@
|
||||
*/
|
||||
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',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user