1
0
mirror of synced 2024-11-22 05:16:09 +03:00

fix unseting delivery fields method (#141)

This commit is contained in:
Сергей Чазов 2020-09-28 13:02:03 +03:00 committed by GitHub
parent 82d6c10c07
commit ec8f5ac661
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 90 additions and 68 deletions

View File

@ -624,6 +624,16 @@ 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(...)
*

View File

@ -1,37 +1,75 @@
<?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) {
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']);
$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']);
}
unset($order['weight']);
unset($order['phone']);
unset($order['delivery']['cost']);
unset($order['shipmentStore']);
unset($order['delivery']['address']);
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;

View File

@ -5,57 +5,31 @@
*/
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);
}