From 7d3390bc02c5210c9191fc3da2270d8ddf2def8b Mon Sep 17 00:00:00 2001 From: Ivan Chaplygin Date: Wed, 7 Jun 2023 13:01:59 +0300 Subject: [PATCH] ref #90088 fix style code edit test Edit getting site --- .../controller/extension/module/retailcrm.php | 35 +++++++++---------- .../model/extension/retailcrm/references.php | 6 ++-- tests/admin/ControllerRetailcrmAdminTest.php | 4 +-- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/upload/admin/controller/extension/module/retailcrm.php b/src/upload/admin/controller/extension/module/retailcrm.php index 9be4d70..956d569 100644 --- a/src/upload/admin/controller/extension/module/retailcrm.php +++ b/src/upload/admin/controller/extension/module/retailcrm.php @@ -334,13 +334,13 @@ class ControllerExtensionModuleRetailcrm extends Controller : null; if (!empty($url) && !empty($key)) { - $sites = $this->model_extension_retailcrm_references->getApiSites(); + $site = $this->model_extension_retailcrm_references->getApiSite(); $_data['delivery'] = $this->getAvailableTypes( - $sites, + $site, $this->model_extension_retailcrm_references->getDeliveryTypes() ); $_data['payments'] = $this->getAvailableTypes( - $sites, + $site, $this->model_extension_retailcrm_references->getPaymentTypes() ); $_data['statuses'] = $this->model_extension_retailcrm_references @@ -947,26 +947,25 @@ class ControllerExtensionModuleRetailcrm extends Controller return $lastSinceId; } - private function getAvailableTypes($availableSites, $types) + private function getAvailableTypes($availableSite, $types) { - if (!empty($availableSites)) { - $availableSite = end($availableSites)['code']; - } else { - return $types; + $result['opencart'] = $types['opencart']; + $result['retailcrm'] = []; + + if (empty($availableSite)) { + return $result; } - $result['opencart'] = $types['opencart']; - foreach ($types['retailcrm'] as $codeKey => $type) { - if ( - $type['active'] === true && - ( - empty($type['sites']) || - in_array($availableSite, $type['sites'], true) - ) - ) { - $result['retailcrm'][$codeKey] = $type; + if ($type['active'] !== true) { + continue; } + + if (!empty($type['sites']) && !in_array($availableSite['code'], $type['sites'])) { + continue; + } + + $result['retailcrm'][$codeKey] = $type; } return $result; diff --git a/src/upload/admin/model/extension/retailcrm/references.php b/src/upload/admin/model/extension/retailcrm/references.php index dd7d3b7..0ad36df 100644 --- a/src/upload/admin/model/extension/retailcrm/references.php +++ b/src/upload/admin/model/extension/retailcrm/references.php @@ -161,15 +161,15 @@ class ModelExtensionRetailcrmReferences extends Model /** * Get RetailCRM available sites list */ - public function getApiSites() + public function getApiSite() { $response = $this->retailcrmApiClient->sitesList(); if (!$response) { - return array(); + return []; } - return (!$response->isSuccessful()) ? array() : $response->sites; + return (!$response->isSuccessful()) ? [] : end($response->sites); } /** diff --git a/tests/admin/ControllerRetailcrmAdminTest.php b/tests/admin/ControllerRetailcrmAdminTest.php index fbd3d0e..b46d684 100644 --- a/tests/admin/ControllerRetailcrmAdminTest.php +++ b/tests/admin/ControllerRetailcrmAdminTest.php @@ -45,7 +45,7 @@ class ControllerRetailcrmAdminTest extends TestCase public function testGetAvailableTypes() { $data = $this->getDataForTestAvailableTypes(); - $sites = $data['sites']; + $sites = end($data['site']); $types = $data['types']; $retailCrm = new ControllerExtensionModuleRetailcrm(self::$registry); @@ -65,7 +65,7 @@ class ControllerRetailcrmAdminTest extends TestCase private function getDataForTestAvailableTypes(): array { return [ - 'sites' => [ + 'site' => [ 'opencart' => [ 'code' => 'opencart', 'name' => 'OpenCart'