From 579150ea08c7cd26bd885af8cb08f62aa8483bbf Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Fri, 25 Sep 2020 10:39:00 +0300 Subject: [PATCH] cleared api version detecting (#198) * cleared api version detecting * phpcs stage --- .travis.yml | 5 ++ Makefile | 6 ++ VERSION | 2 +- composer.json | 3 +- .../controller/extension/module/retailcrm.php | 11 +--- .../en-gb/extension/module/retailcrm.php | 1 - .../es-es/extension/module/retailcrm.php | 1 - .../ru-ru/extension/module/retailcrm.php | 1 - .../model/extension/retailcrm/prices.php | 4 -- .../model/extension/retailcrm/order.php | 55 +++++++------------ .../retailcrm/lib/api/CurlException.php | 2 +- .../lib/api/InvalidJsonException.php | 2 +- .../lib/api/RetailcrmApiResponse.php | 2 +- .../retailcrm/lib/api/RetailcrmHttpClient.php | 2 +- .../library/retailcrm/lib/history/Order.php | 2 +- .../retailcrm/lib/service/SettingsManager.php | 6 +- .../system/library/retailcrm/retailcrm.php | 3 +- 17 files changed, 44 insertions(+), 64 deletions(-) diff --git a/.travis.yml b/.travis.yml index f828c00..f48df70 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ env: stages: - test + - phpcs - deploy before_install: @@ -119,6 +120,10 @@ jobs: env: TEST_SUITE=3.0 OPENCART=3.0.3.1 - php: 7.3 env: TEST_SUITE=3.0 OPENCART=3.0.3.2 + - stage: phpcs + before_script: composer install + script: make phpcomp + after_success: skip - stage: deploy before_script: skip script: make build_archive diff --git a/Makefile b/Makefile index 4bf3481..d0eb813 100644 --- a/Makefile +++ b/Makefile @@ -45,3 +45,9 @@ run_test: run test: robo_deploy composer test + +phpcs-config: + bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility + +phpcomp: phpcs-config + @bin/phpcs -s -p ./src --standard=PHPCompatibility --runtime-set testVersion 5.4-7.3 diff --git a/VERSION b/VERSION index 4d0dcda..de197cc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.2 +4.1.3 diff --git a/composer.json b/composer.json index 581e825..a85205b 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,6 @@ }, "require-dev": { "consolidation/robo": "~1.0", - "beyondit/opencart-test-suite": "~3.0", - "opencart/opencart": "3.0.2.0" + "phpcompatibility/php-compatibility": "^9.3" } } diff --git a/src/upload/admin/controller/extension/module/retailcrm.php b/src/upload/admin/controller/extension/module/retailcrm.php index 5b2e177..5511cb7 100644 --- a/src/upload/admin/controller/extension/module/retailcrm.php +++ b/src/upload/admin/controller/extension/module/retailcrm.php @@ -278,7 +278,6 @@ class ControllerExtensionModuleRetailcrm extends Controller 'button_cancel', 'text_notice', 'retailcrm_title', - 'retailcrm_apiversion', 'retailcrm_url', 'retailcrm_apikey', 'retailcrm_base_settings', @@ -358,9 +357,6 @@ class ControllerExtensionModuleRetailcrm extends Controller $key = isset($_data['saved_settings'][$this->moduleTitle . '_apikey']) ? $_data['saved_settings'][$this->moduleTitle . '_apikey'] : null; - $apiVersion = isset($_data['saved_settings'][$this->moduleTitle . '_apiversion']) - ? $_data['saved_settings'][$this->moduleTitle . '_apiversion'] - : null; if (!empty($url) && !empty($key)) { @@ -370,11 +366,8 @@ class ControllerExtensionModuleRetailcrm extends Controller ->getOrderStatuses(); $_data['payments'] = $this->model_extension_retailcrm_references ->getPaymentTypes(); - - if ($apiVersion == 'v5') { - $_data['customFields'] = $this->model_extension_retailcrm_references - ->getCustomFields(); - } + $_data['customFields'] = $this->model_extension_retailcrm_references + ->getCustomFields(); $_data['lenghts'] = $this->model_localisation_length_class->getLengthClasses(); $_data['priceTypes'] = $this->model_extension_retailcrm_references diff --git a/src/upload/admin/language/en-gb/extension/module/retailcrm.php b/src/upload/admin/language/en-gb/extension/module/retailcrm.php index c7036d2..81d7ded 100644 --- a/src/upload/admin/language/en-gb/extension/module/retailcrm.php +++ b/src/upload/admin/language/en-gb/extension/module/retailcrm.php @@ -20,7 +20,6 @@ $_['collector_tab_text'] = 'Daemon Collector'; $_['logs_tab_text'] = 'Logs'; $_['collector_custom_text'] = 'Configuration of form fields'; $_['custom_fields_tab_text'] = 'Custom fields'; -$_['retailcrm_apiversion'] = 'API Version'; $_['retailcrm_url'] = 'URL of retailCRM'; $_['retailcrm_apikey'] = 'API key of retailCRM'; $_['corporate_enabled_label'] = 'Corporate customers support'; diff --git a/src/upload/admin/language/es-es/extension/module/retailcrm.php b/src/upload/admin/language/es-es/extension/module/retailcrm.php index a13bfd3..af4f9ce 100644 --- a/src/upload/admin/language/es-es/extension/module/retailcrm.php +++ b/src/upload/admin/language/es-es/extension/module/retailcrm.php @@ -20,7 +20,6 @@ $_['collector_tab_text'] = 'Daemon Collector'; $_['logs_tab_text'] = 'Registro'; $_['collector_custom_text'] = 'Configurar campos de formulario'; $_['custom_fields_tab_text'] = 'Campos personalizados'; -$_['retailcrm_apiversion'] = 'Versión de la API'; $_['retailcrm_url'] = 'Dirección del retailCRM'; $_['retailcrm_apikey'] = 'Clave de la API del retailCRM'; $_['corporate_enabled_label'] = 'Corporate customers support'; diff --git a/src/upload/admin/language/ru-ru/extension/module/retailcrm.php b/src/upload/admin/language/ru-ru/extension/module/retailcrm.php index 446afda..24ada07 100644 --- a/src/upload/admin/language/ru-ru/extension/module/retailcrm.php +++ b/src/upload/admin/language/ru-ru/extension/module/retailcrm.php @@ -20,7 +20,6 @@ $_['consultant_tab_text'] = 'Online Consultant'; $_['logs_tab_text'] = 'Логи'; $_['collector_custom_text'] = 'Настройка полей формы'; $_['custom_fields_tab_text'] = 'Пользовательские поля'; -$_['retailcrm_apiversion'] = 'Версия API'; $_['retailcrm_url'] = 'Адрес RetailCRM'; $_['retailcrm_apikey'] = 'Api ключ RetailCRM'; $_['corporate_enabled_label'] = 'Поддержка корпоративных клиентов'; diff --git a/src/upload/admin/model/extension/retailcrm/prices.php b/src/upload/admin/model/extension/retailcrm/prices.php index 1f19995..6a929f1 100644 --- a/src/upload/admin/model/extension/retailcrm/prices.php +++ b/src/upload/admin/model/extension/retailcrm/prices.php @@ -60,10 +60,6 @@ class ModelExtensionRetailcrmPrices extends Model $prices = array(); $site = $this->getSite($retailcrmApiClient); - if ($this->settings[$this->moduleTitle . '_apiversion'] == 'v3') { - return false; - } - foreach ($products as $product) { $specials = $this->model_catalog_product->getProductSpecials($product['product_id']); diff --git a/src/upload/catalog/model/extension/retailcrm/order.php b/src/upload/catalog/model/extension/retailcrm/order.php index c208388..790a203 100644 --- a/src/upload/catalog/model/extension/retailcrm/order.php +++ b/src/upload/catalog/model/extension/retailcrm/order.php @@ -68,7 +68,7 @@ class ModelExtensionRetailcrmOrder extends Model { $response = $retailcrmApiClient->ordersEdit($order); } - if ($this->settings[$this->moduleTitle . '_apiversion'] == 'v5' && $response->isSuccessful()) { + if ($response->isSuccessful()) { $this->updatePayment($order_payment, $order['externalId'], $retailcrmApiClient); } } @@ -169,16 +169,8 @@ class ModelExtensionRetailcrmOrder extends Model { } $order['createdAt'] = $order_data['date_added']; - - if ($this->settings[$this->moduleTitle . '_apiversion'] != 'v5') { - $order['paymentType'] = $payment_code; - if ($couponTotal > 0) { - $order['discount'] = $couponTotal; - } - } else { - if ($couponTotal > 0) { - $order['discountManualAmount'] = $couponTotal; - } + if ($couponTotal > 0) { + $order['discountManualAmount'] = $couponTotal; } $country = isset($order_data['shipping_country']) ? $order_data['shipping_country'] : '' ; @@ -245,38 +237,29 @@ class ModelExtensionRetailcrmOrder extends Model { $offerId = implode('_', $offerId); } - if ($this->settings[$this->moduleTitle . '_apiversion'] != 'v3') { - $item = array( - 'offer' => array( - 'externalId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id'] - ), - 'productName' => $product['name'], - 'initialPrice' => $product['price'], - 'quantity' => $product['quantity'] - ); + $item = array( + 'offer' => array( + 'externalId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id'] + ), + 'productName' => $product['name'], + 'initialPrice' => $product['price'], + 'quantity' => $product['quantity'] + ); - $specials = $this->model_extension_retailcrm_product->getProductSpecials($product['product_id']); + $specials = $this->model_extension_retailcrm_product->getProductSpecials($product['product_id']); - if (!empty($specials)) { - $customer = $this->model_account_customer->getCustomer($order_data['customer_id']); + if (!empty($specials)) { + $customer = $this->model_account_customer->getCustomer($order_data['customer_id']); - foreach ($specials as $special) { - if (isset($customer['customer_group_id'])) { - if ($special['customer_group_id'] == $customer['customer_group_id']) { - if ($this->settings[$this->moduleTitle . '_special_' . $customer['customer_group_id']]) { - $item['priceType']['code'] = $this->settings[$this->moduleTitle . '_special_' . $customer['customer_group_id']]; - } + foreach ($specials as $special) { + if (isset($customer['customer_group_id'])) { + if ($special['customer_group_id'] == $customer['customer_group_id']) { + if ($this->settings[$this->moduleTitle . '_special_' . $customer['customer_group_id']]) { + $item['priceType']['code'] = $this->settings[$this->moduleTitle . '_special_' . $customer['customer_group_id']]; } } } } - } else { - $item = array( - 'productName' => $product['name'], - 'initialPrice' => $product['price'], - 'quantity' => $product['quantity'], - 'productId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id'] - ); } if (isset($properties)) $item['properties'] = $properties; diff --git a/src/upload/system/library/retailcrm/lib/api/CurlException.php b/src/upload/system/library/retailcrm/lib/api/CurlException.php index dbc5868..8eab88c 100644 --- a/src/upload/system/library/retailcrm/lib/api/CurlException.php +++ b/src/upload/system/library/retailcrm/lib/api/CurlException.php @@ -8,7 +8,7 @@ * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ class CurlException extends RuntimeException { diff --git a/src/upload/system/library/retailcrm/lib/api/InvalidJsonException.php b/src/upload/system/library/retailcrm/lib/api/InvalidJsonException.php index 1e631c2..c35e419 100644 --- a/src/upload/system/library/retailcrm/lib/api/InvalidJsonException.php +++ b/src/upload/system/library/retailcrm/lib/api/InvalidJsonException.php @@ -8,7 +8,7 @@ * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ class InvalidJsonException extends DomainException { diff --git a/src/upload/system/library/retailcrm/lib/api/RetailcrmApiResponse.php b/src/upload/system/library/retailcrm/lib/api/RetailcrmApiResponse.php index b63599f..24f3080 100644 --- a/src/upload/system/library/retailcrm/lib/api/RetailcrmApiResponse.php +++ b/src/upload/system/library/retailcrm/lib/api/RetailcrmApiResponse.php @@ -8,7 +8,7 @@ * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ class RetailcrmApiResponse implements ArrayAccess { diff --git a/src/upload/system/library/retailcrm/lib/api/RetailcrmHttpClient.php b/src/upload/system/library/retailcrm/lib/api/RetailcrmHttpClient.php index 7f4d4e0..4294d97 100644 --- a/src/upload/system/library/retailcrm/lib/api/RetailcrmHttpClient.php +++ b/src/upload/system/library/retailcrm/lib/api/RetailcrmHttpClient.php @@ -8,7 +8,7 @@ * @package RetailCrm * @author RetailCrm * @license https://opensource.org/licenses/MIT MIT License - * @link http://www.retailcrm.ru/docs/Developers/ApiVersion4 + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ class RetailcrmHttpClient { diff --git a/src/upload/system/library/retailcrm/lib/history/Order.php b/src/upload/system/library/retailcrm/lib/history/Order.php index b7d3f4b..5cc44be 100644 --- a/src/upload/system/library/retailcrm/lib/history/Order.php +++ b/src/upload/system/library/retailcrm/lib/history/Order.php @@ -229,7 +229,7 @@ class Order { $product_id = $item['offer']['externalId']; $options = array(); - if (mb_strpos($item['offer']['externalId'], '#') > 1) { + if (mb_strpos($item['offer']['externalId'], '#', 0, mb_internal_encoding()) > 1) { $offer = explode('#', $item['offer']['externalId']); $product_id = $offer[0]; $options_from_crm = explode('_', $offer[1]); diff --git a/src/upload/system/library/retailcrm/lib/service/SettingsManager.php b/src/upload/system/library/retailcrm/lib/service/SettingsManager.php index 962d975..e3b8243 100644 --- a/src/upload/system/library/retailcrm/lib/service/SettingsManager.php +++ b/src/upload/system/library/retailcrm/lib/service/SettingsManager.php @@ -18,8 +18,10 @@ class SettingsManager extends \retailcrm\Base { } public function getSetting($key) { - if (!empty($this->getSettings()[$this->retailcrm->getModuleTitle() . '_' . $key])) { - return $this->getSettings()[$this->retailcrm->getModuleTitle() . '_' . $key]; + $settings = $this->getSettings(); + + if (!empty($settings[$this->retailcrm->getModuleTitle() . '_' . $key])) { + return $settings[$this->retailcrm->getModuleTitle() . '_' . $key]; } return null; diff --git a/src/upload/system/library/retailcrm/retailcrm.php b/src/upload/system/library/retailcrm/retailcrm.php index f9930e2..c6e4ab8 100644 --- a/src/upload/system/library/retailcrm/retailcrm.php +++ b/src/upload/system/library/retailcrm/retailcrm.php @@ -52,11 +52,10 @@ class Retailcrm { * * @param string $apiUrl (default = null) * @param string $apiKey (default = null) - * @param string $apiVersion (default = null) * * @return mixed object | boolean */ - public function getApiClient($apiUrl = null, $apiKey = null, $apiVersion = null) { + public function getApiClient($apiUrl = null, $apiKey = null) { if (!$this->registry->has('RetailcrmProxy')) { $setting = $this->model_setting_setting->getSetting($this->getModuleTitle());