diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 086f7c35..97cdf874 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -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 \ diff --git a/CHANGELOG.md b/CHANGELOG.md index 88c6c8c2..1437e5c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/VERSION b/VERSION index 18837e70..5d30083e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.9 +4.1.10 diff --git a/src/upload/admin/controller/extension/module/retailcrm.php b/src/upload/admin/controller/extension/module/retailcrm.php index 63bb76da..956d5690 100644 --- a/src/upload/admin/controller/extension/module/retailcrm.php +++ b/src/upload/admin/controller/extension/module/retailcrm.php @@ -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(); @@ -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; + } } diff --git a/src/upload/admin/model/extension/retailcrm/references.php b/src/upload/admin/model/extension/retailcrm/references.php index aea9f0e8..fe76a77e 100644 --- a/src/upload/admin/model/extension/retailcrm/references.php +++ b/src/upload/admin/model/extension/retailcrm/references.php @@ -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 * diff --git a/tests/admin/ControllerRetailcrmAdminTest.php b/tests/admin/ControllerRetailcrmAdminTest.php index cfdec6b9..b46d6841 100644 --- a/tests/admin/ControllerRetailcrmAdminTest.php +++ b/tests/admin/ControllerRetailcrmAdminTest.php @@ -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' + ] + ] + ] + ]; + } }