mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-22 13:16:07 +03:00
Send to crm marketplace activate/deactivate information
This commit is contained in:
parent
30a2600b7b
commit
0854d36155
@ -50,13 +50,32 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
$this->uninstall_collector();
|
||||
$this->load->model('setting/setting');
|
||||
$settings = $this->model_setting_setting->getSetting('retailcrm_setting');
|
||||
|
||||
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_setting');
|
||||
$this->deleteEvents();
|
||||
}
|
||||
|
||||
@ -184,6 +203,36 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$retailcrm_setting = $this->model_setting_setting->getSetting('retailcrm_setting');
|
||||
|
||||
if (!$retailcrm_setting) {
|
||||
$clientId = hash('md5', date('Y-m-d H:i:s'));
|
||||
$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');
|
||||
$redirect = $this->url->link(
|
||||
'extension/module/retailcrm', $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle],
|
||||
@ -839,4 +888,57 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
$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';
|
||||
$code = 'opencart';
|
||||
$name = 'Opencart';
|
||||
$accountUrl = $scheme . $this->request->server['HTTP_HOST'] . '/admin/index.php?route=extension/module/retailcrm';
|
||||
|
||||
if ($api_version == 'v4') {
|
||||
$configuration = array(
|
||||
'name' => $name,
|
||||
'code' => $code,
|
||||
'logo' => $logo,
|
||||
'configurationUrl' => $accountUrl,
|
||||
'active' => $active
|
||||
);
|
||||
|
||||
$response = $apiClient->marketplaceSettingsEdit($configuration);
|
||||
} else {
|
||||
$configuration = array(
|
||||
'clientId' => $clientId,
|
||||
'code' => $code,
|
||||
'integrationCode' => $code,
|
||||
'active' => $active,
|
||||
'name' => $name,
|
||||
'logo' => $logo,
|
||||
'accountUrl' => $accountUrl
|
||||
);
|
||||
|
||||
$response = $apiClient->integrationModulesEdit($configuration);
|
||||
}
|
||||
|
||||
if (!$response) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user