Skip to content

Commit

Permalink
ref #90088 fix style code
Browse files Browse the repository at this point in the history
edit test
Edit getting site
  • Loading branch information
Ivan Chaplygin committed Jun 7, 2023
1 parent ef6d09c commit 7d3390b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
35 changes: 17 additions & 18 deletions src/upload/admin/controller/extension/module/retailcrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,13 @@ public function index()
: 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
Expand Down Expand Up @@ -947,26 +947,25 @@ private function getHistorySinceId($api, $method)
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;
}

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;
Expand Down
6 changes: 3 additions & 3 deletions src/upload/admin/model/extension/retailcrm/references.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ public function getApiDeliveryTypes()
/**
* 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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/admin/ControllerRetailcrmAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testController()
public function testGetAvailableTypes()
{
$data = $this->getDataForTestAvailableTypes();
$sites = $data['sites'];
$sites = end($data['site']);
$types = $data['types'];

$retailCrm = new ControllerExtensionModuleRetailcrm(self::$registry);
Expand All @@ -65,7 +65,7 @@ public function testGetAvailableTypes()
private function getDataForTestAvailableTypes(): array
{
return [
'sites' => [
'site' => [
'opencart' => [
'code' => 'opencart',
'name' => 'OpenCart'
Expand Down

0 comments on commit 7d3390b

Please sign in to comment.