ref #90088 fix style code

edit test
Edit getting site
This commit is contained in:
Ivan Chaplygin 2023-06-07 13:01:59 +03:00
parent ef6d09c03a
commit 7d3390bc02
3 changed files with 22 additions and 23 deletions

View File

@ -334,13 +334,13 @@ class ControllerExtensionModuleRetailcrm extends Controller
: null; : null;
if (!empty($url) && !empty($key)) { if (!empty($url) && !empty($key)) {
$sites = $this->model_extension_retailcrm_references->getApiSites(); $site = $this->model_extension_retailcrm_references->getApiSite();
$_data['delivery'] = $this->getAvailableTypes( $_data['delivery'] = $this->getAvailableTypes(
$sites, $site,
$this->model_extension_retailcrm_references->getDeliveryTypes() $this->model_extension_retailcrm_references->getDeliveryTypes()
); );
$_data['payments'] = $this->getAvailableTypes( $_data['payments'] = $this->getAvailableTypes(
$sites, $site,
$this->model_extension_retailcrm_references->getPaymentTypes() $this->model_extension_retailcrm_references->getPaymentTypes()
); );
$_data['statuses'] = $this->model_extension_retailcrm_references $_data['statuses'] = $this->model_extension_retailcrm_references
@ -947,26 +947,25 @@ class ControllerExtensionModuleRetailcrm extends Controller
return $lastSinceId; 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['opencart'] = $types['opencart'];
$result['retailcrm'] = [];
if (empty($availableSite)) {
return $result;
}
foreach ($types['retailcrm'] as $codeKey => $type) { foreach ($types['retailcrm'] as $codeKey => $type) {
if ( if ($type['active'] !== true) {
$type['active'] === true && continue;
(
empty($type['sites']) ||
in_array($availableSite, $type['sites'], true)
)
) {
$result['retailcrm'][$codeKey] = $type;
} }
if (!empty($type['sites']) && !in_array($availableSite['code'], $type['sites'])) {
continue;
}
$result['retailcrm'][$codeKey] = $type;
} }
return $result; return $result;

View File

@ -161,15 +161,15 @@ class ModelExtensionRetailcrmReferences extends Model
/** /**
* Get RetailCRM available sites list * Get RetailCRM available sites list
*/ */
public function getApiSites() public function getApiSite()
{ {
$response = $this->retailcrmApiClient->sitesList(); $response = $this->retailcrmApiClient->sitesList();
if (!$response) { if (!$response) {
return array(); return [];
} }
return (!$response->isSuccessful()) ? array() : $response->sites; return (!$response->isSuccessful()) ? [] : end($response->sites);
} }
/** /**

View File

@ -45,7 +45,7 @@ class ControllerRetailcrmAdminTest extends TestCase
public function testGetAvailableTypes() public function testGetAvailableTypes()
{ {
$data = $this->getDataForTestAvailableTypes(); $data = $this->getDataForTestAvailableTypes();
$sites = $data['sites']; $sites = end($data['site']);
$types = $data['types']; $types = $data['types'];
$retailCrm = new ControllerExtensionModuleRetailcrm(self::$registry); $retailCrm = new ControllerExtensionModuleRetailcrm(self::$registry);
@ -65,7 +65,7 @@ class ControllerRetailcrmAdminTest extends TestCase
private function getDataForTestAvailableTypes(): array private function getDataForTestAvailableTypes(): array
{ {
return [ return [
'sites' => [ 'site' => [
'opencart' => [ 'opencart' => [
'code' => 'opencart', 'code' => 'opencart',
'name' => 'OpenCart' 'name' => 'OpenCart'