opencart-module/admin/controller/module/retailcrm.php

227 lines
7.7 KiB
PHP
Raw Normal View History

2014-08-15 13:35:22 +04:00
<?php
require_once DIR_SYSTEM . 'library/retailcrm.php';
2014-08-15 13:35:22 +04:00
2015-06-26 18:07:36 +03:00
class ControllerModuleRetailcrm extends Controller {
2014-08-15 13:35:22 +04:00
private $error = array();
protected $log, $statuses, $payments, $deliveryTypes, $retailcrm;
public $children, $template;
2014-08-15 13:35:22 +04:00
public function install() {
$this->load->model('setting/setting');
2015-06-26 18:07:36 +03:00
$this->model_setting_setting->editSetting(
'retailcrm',
array('retailcrm_status' => 1)
);
2014-08-15 13:35:22 +04:00
}
public function uninstall() {
$this->load->model('setting/setting');
2015-06-26 18:07:36 +03:00
$this->model_setting_setting->editSetting(
'retailcrm',
array('retailcrm_status' => 0)
);
2014-08-15 13:35:22 +04:00
}
public function index() {
$this->load->model('setting/setting');
$this->load->model('setting/extension');
2015-06-26 18:07:36 +03:00
$this->load->model('retailcrm/references');
$this->load->language('module/retailcrm');
2014-08-15 13:35:22 +04:00
$this->document->setTitle($this->language->get('heading_title'));
2015-06-26 18:07:36 +03:00
$this->document->addStyle('/admin/view/stylesheet/retailcrm.css');
2014-08-15 13:35:22 +04:00
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
2015-06-26 18:07:36 +03:00
$this->model_setting_setting->editSetting('retailcrm', $this->request->post);
2014-08-15 13:35:22 +04:00
$this->session->data['success'] = $this->language->get('text_success');
$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
}
$text_strings = array(
'heading_title',
'text_enabled',
'text_disabled',
'button_save',
'button_cancel',
'text_notice',
2015-06-26 18:07:36 +03:00
'retailcrm_url',
'retailcrm_apikey',
'retailcrm_base_settings',
'retailcrm_dict_settings',
'retailcrm_dict_delivery',
'retailcrm_dict_status',
'retailcrm_dict_payment',
2014-08-15 13:35:22 +04:00
);
foreach ($text_strings as $text) {
$this->data[$text] = $this->language->get($text);
}
2015-06-26 18:07:36 +03:00
$this->data['retailcrm_errors'] = array();
$this->data['saved_settings'] = $this->model_setting_setting->getSetting('retailcrm');
2014-08-15 13:35:22 +04:00
2015-06-26 18:07:36 +03:00
if (
!empty($this->data['saved_settings']['retailcrm_url'])
&&
!empty($this->data['saved_settings']['retailcrm_apikey'])
) {
2014-08-15 13:35:22 +04:00
2015-06-26 18:07:36 +03:00
$this->retailcrm = new ApiHelper(
$this->data['saved_settings']['retailcrm_url'],
$this->data['saved_settings']['retailcrm_apikey']
2014-08-15 13:35:22 +04:00
);
/*
* Delivery
*/
$this->deliveryTypes = array();
2014-08-15 13:35:22 +04:00
try {
2015-06-26 18:07:36 +03:00
$this->deliveryTypes = $this->retailcrm->deliveryTypesList();
} catch (CurlException $e) {
2015-06-26 18:07:36 +03:00
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::deliveryTypesList::Curl:' . $e->getMessage());
} catch (InvalidJsonException $e) {
2015-06-26 18:07:36 +03:00
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::deliveryTypesList::JSON:' . $e->getMessage());
2014-08-15 13:35:22 +04:00
}
$this->data['delivery'] = array(
2015-06-26 18:07:36 +03:00
'opencart' => $this->model_retailcrm_tools->getOpercartDeliveryMethods(),
'retailcrm' => $this->deliveryTypes
2014-08-15 13:35:22 +04:00
);
/*
* Statuses
*/
$this->statuses = array();
2014-08-15 13:35:22 +04:00
try {
2015-06-26 18:07:36 +03:00
$this->statuses = $this->retailcrm->orderStatusesList();
} catch (CurlException $e) {
2015-06-26 18:07:36 +03:00
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::orderStatusesList::Curl:' . $e->getMessage());
} catch (InvalidJsonException $e) {
2015-06-26 18:07:36 +03:00
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::orderStatusesList::JSON:' . $e->getMessage());
2014-08-15 13:35:22 +04:00
}
$this->data['statuses'] = array(
2015-06-26 18:07:36 +03:00
'opencart' => $this->model_retailcrm_tools->getOpercartOrderStatuses(),
'retailcrm' => $this->statuses
2014-08-15 13:35:22 +04:00
);
/*
* Payment
*/
$this->payments = array();
2014-08-15 13:35:22 +04:00
try {
2015-06-26 18:07:36 +03:00
$this->payments = $this->retailcrm->paymentTypesList();
} catch (CurlException $e) {
2015-06-26 18:07:36 +03:00
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::paymentTypesList::Curl:' . $e->getMessage());
} catch (InvalidJsonException $e) {
2015-06-26 18:07:36 +03:00
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::paymentTypesList::JSON:' . $e->getMessage());
2014-08-15 13:35:22 +04:00
}
$this->data['payments'] = array(
2015-06-26 18:07:36 +03:00
'opencart' => $this->model_retailcrm_tools->getOpercartPaymentTypes(),
'retailcrm' => $this->payments
2014-08-15 13:35:22 +04:00
);
}
$config_data = array(
2015-06-26 18:07:36 +03:00
'retailcrm_status'
2014-08-15 13:35:22 +04:00
);
foreach ($config_data as $conf) {
if (isset($this->request->post[$conf])) {
$this->data[$conf] = $this->request->post[$conf];
} else {
$this->data[$conf] = $this->config->get($conf);
}
}
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
2015-06-26 18:07:36 +03:00
'href' => $this->url->link('module/retailcrm', 'token=' . $this->session->data['token'], 'SSL'),
2014-08-15 13:35:22 +04:00
'separator' => ' :: '
);
2015-06-26 18:07:36 +03:00
$this->data['action'] = $this->url->link('module/retailcrm', 'token=' . $this->session->data['token'], 'SSL');
2014-08-15 13:35:22 +04:00
$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
$this->data['modules'] = array();
2015-06-26 18:07:36 +03:00
if (isset($this->request->post['retailcrm_module'])) {
$this->data['modules'] = $this->request->post['retailcrm_module'];
} elseif ($this->config->get('retailcrm_module')) {
$this->data['modules'] = $this->config->get('retailcrm_module');
2014-08-15 13:35:22 +04:00
}
$this->load->model('design/layout');
$this->data['layouts'] = $this->model_design_layout->getLayouts();
2015-06-26 18:07:36 +03:00
$this->template = 'module/retailcrm.tpl';
2014-08-15 13:35:22 +04:00
$this->children = array(
'common/header',
'common/footer',
);
$this->response->setOutput($this->render());
}
2015-06-26 18:07:36 +03:00
public function history()
{
$this->load->model('retailcrm/history');
$this->model_retailcrm_history->request();
}
2015-06-26 18:07:36 +03:00
public function icml()
2014-08-27 18:06:19 +04:00
{
2015-06-26 18:07:36 +03:00
$this->load->model('retailcrm/icml');
$this->model_retailcrm_icml->generateICML();
}
2014-08-15 13:35:22 +04:00
private function validate() {
2015-06-26 18:07:36 +03:00
if (!$this->user->hasPermission('modify', 'module/retailcrm')) {
2014-08-15 13:35:22 +04:00
$this->error['warning'] = $this->language->get('error_permission');
}
if (!$this->error) {
return TRUE;
} else {
return FALSE;
}
}
}