Merge pull request #118 from iyzoer/master

3.1.3
This commit is contained in:
Alex Lushpai 2018-10-25 12:03:30 +03:00 committed by GitHub
commit bca86cc51c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 192 additions and 31 deletions

View File

@ -1,3 +1,6 @@
## v.3.1.3
* Добавлена активация модуля в маркетплейсе retailCRM
## v.3.1.2 ## v.3.1.2
* Добавлен перевод на испанский язык * Добавлен перевод на испанский язык
* Переделан перевод на английский язык * Переделан перевод на английский язык

View File

@ -1 +1 @@
3.1.2 3.1.3

View File

@ -50,13 +50,32 @@ class ControllerExtensionModuleRetailcrm extends Controller
*/ */
public function uninstall() public function uninstall()
{ {
$this->uninstall_collector();
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$this->model_setting_setting->editSetting( $settings = $this->model_setting_setting->getSetting('retailcrm_setting');
$this->moduleTitle,
array($this->moduleTitle . '_status' => 0) if (!empty($settings)) {
); $clientId = $settings['retailcrm_setting_client_id'];
$this->integrationModule(
$this->retailcrm->getApiClient(
$settings['retailcrm_setting_url'],
$settings['retailcrm_setting_key'],
$settings['retailcrm_setting_version']
),
$clientId,
$settings['retailcrm_setting_version'],
false
);
$this->uninstall_collector();
$this->model_setting_setting->editSetting(
$this->moduleTitle,
array($this->moduleTitle . '_status' => 0)
);
}
$this->model_setting_setting->deleteSetting('retailcrm_history'); $this->model_setting_setting->deleteSetting('retailcrm_history');
$this->model_setting_setting->deleteSetting('retailcrm_setting');
$this->deleteEvents(); $this->deleteEvents();
} }
@ -66,7 +85,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
* @return void * @return void
*/ */
public function install_collector() public function install_collector()
{ {
$collector = $this->getCollectorTitle(); $collector = $this->getCollectorTitle();
$this->loadModels(); $this->loadModels();
$this->load->model('setting/setting'); $this->load->model('setting/setting');
@ -80,7 +99,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
* @return void * @return void
*/ */
public function uninstall_collector() public function uninstall_collector()
{ {
$collector = $this->getCollectorTitle(); $collector = $this->getCollectorTitle();
$this->loadModels(); $this->loadModels();
$this->load->model('setting/setting'); $this->load->model('setting/setting');
@ -174,7 +193,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
} }
$this->model_setting_setting->editSetting( $this->model_setting_setting->editSetting(
'retailcrm_history', 'retailcrm_history',
array( array(
'retailcrm_history_orders' => isset($sinceIdOrders) ? $sinceIdOrders : 1, 'retailcrm_history_orders' => isset($sinceIdOrders) ? $sinceIdOrders : 1,
'retailcrm_history_customers' => isset($sinceIdCustomers) ? $sinceIdCustomers : 1, 'retailcrm_history_customers' => isset($sinceIdCustomers) ? $sinceIdCustomers : 1,
@ -184,6 +203,36 @@ class ControllerExtensionModuleRetailcrm extends Controller
} }
} }
$retailcrm_setting = $this->model_setting_setting->getSetting('retailcrm_setting');
if (!$retailcrm_setting) {
$clientId = uniqid();
$api = $this->retailcrm->getApiClient(
$this->request->post[$this->moduleTitle . '_url'],
$this->request->post[$this->moduleTitle . '_apikey'],
$this->request->post[$this->moduleTitle . '_apiversion']
);
$result = $this->integrationModule(
$api,
$clientId,
$this->request->post[$this->moduleTitle . '_apiversion']
);
if ($result === true) {
$this->model_setting_setting->editSetting(
'retailcrm_setting',
array(
'retailcrm_setting_active_in_crm' => true,
'retailcrm_setting_client_id' => $clientId,
'retailcrm_setting_url' => $this->request->post[$this->moduleTitle . '_url'],
'retailcrm_setting_key' => $this->request->post[$this->moduleTitle . '_apikey'],
'retailcrm_setting_version' => $this->request->post[$this->moduleTitle . '_apiversion']
)
);
}
}
$this->session->data['success'] = $this->language->get('text_success'); $this->session->data['success'] = $this->language->get('text_success');
$redirect = $this->url->link( $redirect = $this->url->link(
'extension/module/retailcrm', $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], 'extension/module/retailcrm', $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle],
@ -282,7 +331,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
->getOrderStatuses(); ->getOrderStatuses();
$_data['payments'] = $this->model_extension_retailcrm_references $_data['payments'] = $this->model_extension_retailcrm_references
->getPaymentTypes(); ->getPaymentTypes();
if ($apiVersion == 'v5') { if ($apiVersion == 'v5') {
$_data['customFields'] = $this->model_extension_retailcrm_references $_data['customFields'] = $this->model_extension_retailcrm_references
->getCustomFields(); ->getCustomFields();
@ -464,7 +513,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
* @return void * @return void
*/ */
public function customer_edit($route, $customer) public function customer_edit($route, $customer)
{ {
$this->load->model('localisation/country'); $this->load->model('localisation/country');
$this->load->model('localisation/zone'); $this->load->model('localisation/zone');
$this->load->model('customer/customer'); $this->load->model('customer/customer');
@ -487,7 +536,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
'postcode' => $address['postcode'], 'postcode' => $address['postcode'],
'iso_code_2' => $country['iso_code_2'], 'iso_code_2' => $country['iso_code_2'],
'zone' => $zone['name'] 'zone' => $zone['name']
); );
} }
$this->load->model('extension/retailcrm/customer'); $this->load->model('extension/retailcrm/customer');
@ -654,7 +703,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
/** /**
* Clear retailcrm log file * Clear retailcrm log file
* *
* @return void * @return void
*/ */
public function clear_retailcrm() public function clear_retailcrm()
@ -672,7 +721,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
/** /**
* Clear opencart API log file * Clear opencart API log file
* *
* @return void * @return void
*/ */
public function clear_opencart() public function clear_opencart()
@ -690,7 +739,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
/** /**
* Method for load models * Method for load models
* *
* @return void * @return void
*/ */
private function loadModels() private function loadModels()
@ -716,7 +765,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
/** /**
* Get collector module name * Get collector module name
* *
* @return string * @return string
*/ */
private function getCollectorTitle() private function getCollectorTitle()
@ -732,7 +781,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
/** /**
* Check file size * Check file size
* *
* @return string * @return string
*/ */
private function checkLogFile($file) private function checkLogFile($file)
@ -754,7 +803,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
/** /**
* Add events to db * Add events to db
* *
* @return void * @return void
*/ */
private function addEvents() private function addEvents()
@ -806,7 +855,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
/** /**
* Check events in db * Check events in db
* *
* @return boolean * @return boolean
*/ */
private function checkEvents() private function checkEvents()
@ -826,7 +875,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
/** /**
* Delete events from db * Delete events from db
* *
* @return void * @return void
*/ */
private function deleteEvents() private function deleteEvents()
@ -839,4 +888,57 @@ class ControllerExtensionModuleRetailcrm extends Controller
$this->{'model_' . $this->modelEvent}->deleteEventByCode($this->moduleTitle); $this->{'model_' . $this->modelEvent}->deleteEventByCode($this->moduleTitle);
} }
} }
/**
* Activate/deactivate module in marketplace retailCRM
*
* @param \RetailcrmProxy $apiClient
* @param string $clientId
* @param string $api_version
* @param boolean $active
*
* @return boolean
*/
private function integrationModule($apiClient, $clientId, $api_version, $active = true)
{
$scheme = isset($this->request->server['HTTPS']) ? 'https://' : 'http://';
$logo = 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5af48736c6a0c-opencart-seeklogo.com.svg';
$integrationCode = 'opencart';
$name = 'Opencart';
$accountUrl = $scheme . $this->request->server['HTTP_HOST'] . '/admin';
if ($api_version == 'v4') {
$configuration = array(
'name' => $name,
'code' => $integrationCode . '-' . $clientId,
'logo' => $logo,
'configurationUrl' => $accountUrl,
'active' => $active
);
$response = $apiClient->marketplaceSettingsEdit($configuration);
} else {
$configuration = array(
'clientId' => $clientId,
'code' => $integrationCode . '-' . $clientId,
'integrationCode' => $integrationCode,
'active' => $active,
'name' => $name,
'logo' => $logo,
'accountUrl' => $accountUrl
);
$response = $apiClient->integrationModulesEdit($configuration);
}
if (!$response) {
return false;
}
if ($response->isSuccessful()) {
return true;
}
return false;
}
} }

View File

@ -35,20 +35,20 @@ class RetailcrmApiClient4
if ('/' !== $url[strlen($url) - 1]) { if ('/' !== $url[strlen($url) - 1]) {
$url .= '/'; $url .= '/';
} }
$url = $version == null ? $url . 'api' : $url . 'api/' . $version; $url = $version == null ? $url . 'api' : $url . 'api/' . $version;
$this->client = new RetailcrmHttpClient($url, array('apiKey' => $apiKey)); $this->client = new RetailcrmHttpClient($url, array('apiKey' => $apiKey));
$this->siteCode = $site; $this->siteCode = $site;
} }
/** /**
* Returns api versions list * Returns api versions list
* *
* @throws \RetailCrm\Exception\InvalidJsonException * @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException * @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* *
* @return ApiResponse * @return ApiResponse
*/ */
public function apiVersions() public function apiVersions()
@ -1699,6 +1699,34 @@ class RetailcrmApiClient4
); );
} }
/**
* Edit marketplace configuration
*
* @param array $configuration
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return ApiResponse
*/
public function marketplaceSettingsEdit(array $configuration)
{
if (!count($configuration) || empty($configuration['code'])) {
throw new \InvalidArgumentException(
'Parameter `configuration` must contains a data & configuration `code` must be set'
);
}
$code = $configuration['code'];
return $this->client->makeRequest(
"/marketplace/external/setting/$code/edit",
RetailcrmHttpClient::METHOD_POST,
array('configuration' => json_encode($configuration))
);
}
/** /**
* Return current site * Return current site
* *

View File

@ -41,21 +41,21 @@ class RetailcrmApiClient5
$this->client = new RetailcrmHttpClient($url, array('apiKey' => $apiKey)); $this->client = new RetailcrmHttpClient($url, array('apiKey' => $apiKey));
$this->siteCode = $site; $this->siteCode = $site;
} }
/** /**
* Returns api versions list * Returns api versions list
* *
* @throws \RetailCrm\Exception\InvalidJsonException * @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException * @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* *
* @return ApiResponse * @return ApiResponse
*/ */
public function apiVersions() public function apiVersions()
{ {
return $this->client->makeRequest('/api-versions', RetailcrmHttpClient::METHOD_GET); return $this->client->makeRequest('/api-versions', RetailcrmHttpClient::METHOD_GET);
} }
/** /**
* Returns users list * Returns users list
* *
@ -190,7 +190,7 @@ class RetailcrmApiClient5
$parameters $parameters
); );
} }
/** /**
* Create custom field * Create custom field
* *
@ -223,7 +223,7 @@ class RetailcrmApiClient5
array('customField' => json_encode($customField)) array('customField' => json_encode($customField))
); );
} }
/** /**
* Edit custom field * Edit custom field
* *
@ -730,7 +730,7 @@ class RetailcrmApiClient5
'Parameter `id` must be set' 'Parameter `id` must be set'
); );
} }
return $this->client->makeRequest( return $this->client->makeRequest(
sprintf('/orders/payments/%s/delete', $id), sprintf('/orders/payments/%s/delete', $id),
RetailcrmHttpClient::METHOD_POST RetailcrmHttpClient::METHOD_POST
@ -2324,6 +2324,34 @@ class RetailcrmApiClient5
); );
} }
/**
* Edit module configuration
*
* @param array $configuration
*
* @throws \RetailCrm\Exception\InvalidJsonException
* @throws \RetailCrm\Exception\CurlException
* @throws \InvalidArgumentException
*
* @return ApiResponse
*/
public function integrationModulesEdit(array $configuration)
{
if (!count($configuration) || empty($configuration['code'])) {
throw new \InvalidArgumentException(
'Parameter `configuration` must contains a data & configuration `code` must be set'
);
}
$code = $configuration['code'];
return $this->client->makeRequest(
"/integration-modules/$code/edit",
RetailcrmHttpClient::METHOD_POST,
array('integrationModule' => json_encode($configuration))
);
}
/** /**
* Update CRM basic statistic * Update CRM basic statistic
* *