From 3e1c19fd8d97604231bd52eaeca9c7ff0631688a Mon Sep 17 00:00:00 2001 From: Ivan Chaplygin Date: Fri, 2 Jun 2023 13:55:00 +0300 Subject: [PATCH] ref #90088 Types of deliveries and payments are displayed only active status and available stores --- .../controller/extension/module/retailcrm.php | 39 ++++++++++++++++--- .../model/extension/retailcrm/references.php | 14 +++++++ .../retailcrm/lib/api/OpencartApiClient.php | 2 +- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/upload/admin/controller/extension/module/retailcrm.php b/src/upload/admin/controller/extension/module/retailcrm.php index 63bb76d..3678dff 100644 --- a/src/upload/admin/controller/extension/module/retailcrm.php +++ b/src/upload/admin/controller/extension/module/retailcrm.php @@ -334,13 +334,17 @@ class ControllerExtensionModuleRetailcrm extends Controller : null; if (!empty($url) && !empty($key)) { - - $_data['delivery'] = $this->model_extension_retailcrm_references - ->getDeliveryTypes(); + $sites = $this->model_extension_retailcrm_references->getApiSites(); + $_data['delivery'] = $this->getAvailableTypes( + $sites, + $this->model_extension_retailcrm_references->getDeliveryTypes() + ); + $_data['payments'] = $this->getAvailableTypes( + $sites, + $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,29 @@ class ControllerExtensionModuleRetailcrm extends Controller return $lastSinceId; } + + private function getAvailableTypes($availableSites, $types) + { + if (!empty($availableSites)) { + $availableSite = end($availableSites)['code']; + } else { + return $types; + } + + $result = []; + + foreach ($types as $type) { + if ( + $type['active'] === true && + ( + empty($type['sites']) || + in_array($availableSite, $type['sites'], true) + ) + ) { + $result[] = $type; + } + } + + return $result; + } } diff --git a/src/upload/admin/model/extension/retailcrm/references.php b/src/upload/admin/model/extension/retailcrm/references.php index aea9f0e..dd7d3b7 100644 --- a/src/upload/admin/model/extension/retailcrm/references.php +++ b/src/upload/admin/model/extension/retailcrm/references.php @@ -158,6 +158,20 @@ class ModelExtensionRetailcrmReferences extends Model return (!$response->isSuccessful()) ? array() : $response->deliveryTypes; } + /** + * Get RetailCRM available sites list + */ + public function getApiSites() + { + $response = $this->retailcrmApiClient->sitesList(); + + if (!$response) { + return array(); + } + + return (!$response->isSuccessful()) ? array() : $response->sites; + } + /** * Get RetailCRM order statuses * diff --git a/src/upload/system/library/retailcrm/lib/api/OpencartApiClient.php b/src/upload/system/library/retailcrm/lib/api/OpencartApiClient.php index adec79a..72fa92a 100644 --- a/src/upload/system/library/retailcrm/lib/api/OpencartApiClient.php +++ b/src/upload/system/library/retailcrm/lib/api/OpencartApiClient.php @@ -87,7 +87,7 @@ class OpencartApiClient { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_FORBID_REUSE, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_URL, $url . 'index.php?route=api/' . $method . (!empty($getParams) ? '&' . http_build_query($getParams) : '')); + curl_setopt($curl, CURLOPT_URL, 'https://chaplygin-is.proxy.retailcrm.tech/' . 'index.php?route=api/' . $method . (!empty($getParams) ? '&' . http_build_query($getParams) : '')); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postParams));