Skip to content

Commit

Permalink
ref #90088 Types of deliveries and payments are displayed only active…
Browse files Browse the repository at this point in the history
… status and available stores
  • Loading branch information
uryvskiy-dima authored Jun 7, 2023
2 parents 090a578 + 792546d commit 6a7f395
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM php:7.1-apache

RUN apt-get update

RUN apt-get install -y netcat zlib1g-dev libpq-dev git libicu-dev libxml2-dev libpng-dev libjpeg-dev libmcrypt-dev libxslt-dev libfreetype6-dev \
RUN apt-get install -y netcat zlib1g-dev libpq-dev git libicu-dev libxml2-dev libpng-dev libjpeg-dev libmcrypt-dev libxslt-dev libfreetype6-dev unzip \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v4.1.10
* Types of deliveries and payments are displayed only active status and available stores

## v4.1.9
* Optimization of the history processing algorithm

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.9
4.1.10
38 changes: 33 additions & 5 deletions src/upload/admin/controller/extension/module/retailcrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,17 @@ public function index()
: null;

if (!empty($url) && !empty($key)) {

$_data['delivery'] = $this->model_extension_retailcrm_references
->getDeliveryTypes();
$site = $this->model_extension_retailcrm_references->getApiSite();
$_data['delivery'] = $this->getAvailableTypes(
$site,
$this->model_extension_retailcrm_references->getDeliveryTypes()
);
$_data['payments'] = $this->getAvailableTypes(
$site,
$this->model_extension_retailcrm_references->getPaymentTypes()
);
$_data['statuses'] = $this->model_extension_retailcrm_references
->getOrderStatuses();
$_data['payments'] = $this->model_extension_retailcrm_references
->getPaymentTypes();
$_data['customFields'] = $this->model_extension_retailcrm_references
->getCustomFields();

Expand Down Expand Up @@ -942,4 +946,28 @@ private function getHistorySinceId($api, $method)

return $lastSinceId;
}

private function getAvailableTypes($availableSite, $types)
{
$result['opencart'] = $types['opencart'];
$result['retailcrm'] = [];

if (empty($availableSite)) {
return $result;
}

foreach ($types['retailcrm'] as $codeKey => $type) {
if ($type['active'] !== true) {
continue;
}

if (!empty($type['sites']) && !in_array($availableSite['code'], $type['sites'])) {
continue;
}

$result['retailcrm'][$codeKey] = $type;
}

return $result;
}
}
16 changes: 16 additions & 0 deletions src/upload/admin/model/extension/retailcrm/references.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ public function getApiDeliveryTypes()
return (!$response->isSuccessful()) ? array() : $response->deliveryTypes;
}

/**
* Get RetailCRM available sites list
*/
public function getApiSite()
{
$response = $this->retailcrmApiClient->sitesList();

if (!$response || !$response->isSuccessful()) {
return [];
}

$sites = $response->sites;

return end($sites);
}

/**
* Get RetailCRM order statuses
*
Expand Down
59 changes: 59 additions & 0 deletions tests/admin/ControllerRetailcrmAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,63 @@ public function testController()
$response = $this->dispatchAction('extension/module/retailcrm/uninstall_collector');
$this->assertRegExp('/Connection settings/', $response->getOutput());
}

public function testGetAvailableTypes()
{
$data = $this->getDataForTestAvailableTypes();
$sites = end($data['site']);
$types = $data['types'];

$retailCrm = new ControllerExtensionModuleRetailcrm(self::$registry);
$class = new ReflectionClass($retailCrm);
$method = $class->getMethod('getAvailableTypes');
$method->setAccessible(true);

$result = $method->invokeArgs($retailCrm, [$sites, $types]);

$this->assertNotEmpty($result['opencart']);
$this->assertNotEmpty($result['retailcrm']);
$this->assertCount(2, $result['retailcrm']);
$this->assertNotEmpty($result['retailcrm']['test1']['code']);
$this->assertNotEmpty($result['retailcrm']['test4']['code']);
}

private function getDataForTestAvailableTypes(): array
{
return [
'site' => [
'opencart' => [
'code' => 'opencart',
'name' => 'OpenCart'
]
],
'types' => [
'opencart' => [
'test'
],
'retailcrm' => [
'test1' => [
'active' => true,
'sites' => [],
'code' => 'test1'
],
'test2' => [
'active' => false,
'sites' => [],
'code' => 'test2'
],
'test3' => [
'active' => true,
'sites' => ['otherSite'],
'code' => 'test3'
],
'test4' => [
'active' => true,
'sites' => ['cms1', 'cms2', 'opencart'],
'code' => 'test4'
]
]
]
];
}
}

0 comments on commit 6a7f395

Please sign in to comment.