Changed user interface, implemented Daemon Collector

This commit is contained in:
iyzoer 2017-05-29 15:48:56 +03:00
parent 276024a5e5
commit c51e4a35a4
5 changed files with 214 additions and 87 deletions

View File

@ -84,6 +84,7 @@ 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 $this->model_setting_setting
->editSetting('retailcrm', array('retailcrm_status' => 0)); ->editSetting('retailcrm', array('retailcrm_status' => 0));
@ -92,6 +93,32 @@ class ControllerExtensionModuleRetailcrm extends Controller
$this->model_extension_event->deleteEvent('retailcrm'); $this->model_extension_event->deleteEvent('retailcrm');
} }
/**
* Install Demon Collector method
*
* @return void
*/
public function install_collector()
{
$this->load->model('extension/extension');
$this->load->model('setting/setting');
$this->model_extension_extension->install('analytics', 'daemon_collector');
$this->model_setting_setting->editSetting('daemon_collector', array('daemon_collector_status' => 1));
}
/**
* Uninstall Demon Collector method
*
* @return void
*/
public function uninstall_collector()
{
$this->load->model('extension/extension');
$this->load->model('setting/setting');
$this->model_setting_setting->editSetting('daemon_collector', array('daemon_collector_status' => 0));
$this->model_extension_extension->uninstall('analytics', 'daemon_collector');
}
/** /**
* Setup page * Setup page
* *
@ -99,6 +126,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
*/ */
public function index() public function index()
{ {
$this->load->model('extension/extension');
$this->load->model('localisation/country'); $this->load->model('localisation/country');
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$this->load->model('extension/module'); $this->load->model('extension/module');
@ -108,6 +136,16 @@ class ControllerExtensionModuleRetailcrm extends Controller
$this->document->addStyle('/admin/view/stylesheet/retailcrm.css'); $this->document->addStyle('/admin/view/stylesheet/retailcrm.css');
if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) { if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
$analytics = $this->model_extension_extension->getInstalled('analytics');
if ($this->request->post['retailcrm_collector_active'] == 1 &&
!in_array('daemon_collector', $analytics)) {
$this->install_collector();
} elseif ($this->request->post['retailcrm_collector_active'] == 0 &&
in_array('daemon_collector', $analytics)) {
$this->uninstall_collector();
}
if (parse_url($this->request->post['retailcrm_url'])){ if (parse_url($this->request->post['retailcrm_url'])){
$crm_url = parse_url($this->request->post['retailcrm_url'], PHP_URL_HOST); $crm_url = parse_url($this->request->post['retailcrm_url'], PHP_URL_HOST);
$this->request->post['retailcrm_url'] = 'https://'.$crm_url; $this->request->post['retailcrm_url'] = 'https://'.$crm_url;
@ -150,7 +188,14 @@ class ControllerExtensionModuleRetailcrm extends Controller
'text_success_catalog', 'text_success_catalog',
'retailcrm_upload_order', 'retailcrm_upload_order',
'text_error_order', 'text_error_order',
'text_error_order_id' 'text_error_order_id',
'daemon_collector',
'general_tab_text',
'references_tab_text',
'collector_tab_text',
'text_yes',
'text_no',
'collector_site_key'
); );
$this->load->model('extension/extension'); $this->load->model('extension/extension');
@ -263,7 +308,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
$_data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; $_data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG;
$_data['token'] = $this->request->get['token']; $_data['token'] = $this->request->get['token'];
if(file_exists(DIR_SYSTEM . '/cron/export_done.txt')) { if(file_exists(DIR_SYSTEM . '/cron/export_done')) {
$_data['export_file'] = false; $_data['export_file'] = false;
} else { } else {
$_data['export_file'] = true; $_data['export_file'] = true;
@ -427,7 +472,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
$this->load->model('extension/retailcrm/order'); $this->load->model('extension/retailcrm/order');
$this->model_extension_retailcrm_order->uploadToCrm($fullOrders); $this->model_extension_retailcrm_order->uploadToCrm($fullOrders);
$file = fopen(DIR_SYSTEM . '/cron/export_done.txt', "x"); $file = fopen(DIR_SYSTEM . '/cron/export_done', "x");
} }
/** /**

View File

@ -12,8 +12,14 @@ $_['retailcrm_base_settings'] = 'Connection settings';
$_['retailcrm_dict_settings'] = 'Dictionary settings'; $_['retailcrm_dict_settings'] = 'Dictionary settings';
$_['retailcrm_countries_settings'] = 'Trading zones setting'; $_['retailcrm_countries_settings'] = 'Trading zones setting';
$_['retailcrm_upload_order'] = 'Unload single order'; $_['retailcrm_upload_order'] = 'Unload single order';
$_['daemon_collector'] = 'Daemon Collector';
$_['general_tab_text'] = 'General';
$_['references_tab_text'] = 'References';
$_['collector_tab_text'] = 'Collector';
$_['retailcrm_url'] = 'RetailCRM URL'; $_['retailcrm_url'] = 'RetailCRM URL';
$_['retailcrm_apikey'] = 'RetailCRM API Key'; $_['retailcrm_apikey'] = 'RetailCRM API Key';
$_['collector_site_key'] = 'Site key';
$_['text_success_export'] = 'Orders and customers successfully unloaded'; $_['text_success_export'] = 'Orders and customers successfully unloaded';
$_['text_success_export_order'] = 'Order successfully unloaded'; $_['text_success_export_order'] = 'Order successfully unloaded';
@ -36,6 +42,8 @@ $_['color'] = 'Color';
$_['weight'] = 'Weight'; $_['weight'] = 'Weight';
$_['size'] = 'Size'; $_['size'] = 'Size';
$_['text_yes'] = 'Yes';
$_['text_no'] = 'No';
// Errors // Errors
$_['error_permission'] = 'Warning! You do not have permission to modify module'; $_['error_permission'] = 'Warning! You do not have permission to modify module';

View File

@ -12,9 +12,14 @@ $_['retailcrm_base_settings'] = 'Настройки соединения';
$_['retailcrm_dict_settings'] = 'Настройки соответствия справочников'; $_['retailcrm_dict_settings'] = 'Настройки соответствия справочников';
$_['retailcrm_countries_settings'] = 'Настройка торговых зон'; $_['retailcrm_countries_settings'] = 'Настройка торговых зон';
$_['retailcrm_upload_order'] = 'Выгрузка одного заказа'; $_['retailcrm_upload_order'] = 'Выгрузка одного заказа';
$_['daemon_collector'] = 'Демон Collector';
$_['general_tab_text'] = 'Главная';
$_['references_tab_text'] = 'Справочники';
$_['collector_tab_text'] = 'Collector';
$_['retailcrm_url'] = 'Адрес RetailCRM'; $_['retailcrm_url'] = 'Адрес RetailCRM';
$_['retailcrm_apikey'] = 'Api ключ RetailCRM'; $_['retailcrm_apikey'] = 'Api ключ RetailCRM';
$_['collector_site_key'] = 'Ключ сайта';
$_['text_success_export'] = 'Заказы и клиенты успешно выгружены'; $_['text_success_export'] = 'Заказы и клиенты успешно выгружены';
$_['text_success_export_order'] = 'Заказ успешно выгружен'; $_['text_success_export_order'] = 'Заказ успешно выгружен';
@ -25,6 +30,7 @@ $_['text_success_catalog'] = 'Каталог успешно выгруже
$_['text_error_order'] = 'Ошибка! Заказ не выгружен!'; $_['text_error_order'] = 'Ошибка! Заказ не выгружен!';
$_['text_error_order_id'] = 'Ошибка! Введите корректный номер заказа!'; $_['text_error_order_id'] = 'Ошибка! Введите корректный номер заказа!';
$_['retailcrm_dict_delivery'] = 'Способы доставки'; $_['retailcrm_dict_delivery'] = 'Способы доставки';
$_['retailcrm_dict_status'] = 'Статусы'; $_['retailcrm_dict_status'] = 'Статусы';
$_['retailcrm_dict_payment'] = 'Способы оплаты'; $_['retailcrm_dict_payment'] = 'Способы оплаты';
@ -37,6 +43,8 @@ $_['color'] = 'Цвет';
$_['weight'] = 'Вес'; $_['weight'] = 'Вес';
$_['size'] = 'Размер'; $_['size'] = 'Размер';
$_['text_yes'] = 'Да';
$_['text_no'] = 'Нет';
// Errors // Errors
$_['error_permission'] = 'У вас недостаточно прав на изменение настроек модуля'; $_['error_permission'] = 'У вас недостаточно прав на изменение настроек модуля';

View File

@ -38,97 +38,141 @@
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-retailcrm"> <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-retailcrm">
<input type="hidden" name="retailcrm_status" value="1"> <!------------------------- -->
<ul class="nav nav-tabs">
<li class="active"><a href="#tab-general" data-toggle="tab"><?php echo $general_tab_text; ?></a></li>
<?php if (isset($saved_settings['retailcrm_apikey']) && $saved_settings['retailcrm_apikey'] != '' && isset($saved_settings['retailcrm_url']) && $saved_settings['retailcrm_url'] != ''): ?>
<li><a href="#tab-references" data-toggle="tab"><?php echo $references_tab_text; ?></a></li>
<li><a href="#tab-collector" data-toggle="tab"><?php echo $collector_tab_text; ?></a></li>
<?php endif; ?>
</ul>
<h3><?php echo $retailcrm_base_settings; ?></h3> <div class="tab-content">
<div class="retailcrm_unit"> <div class="tab-pane active" id="tab-general">
<label for="retailcrm_url"><?php echo $retailcrm_url; ?></label><br> <input type="hidden" name="retailcrm_status" value="1">
<input id="retailcrm_url" type="text" name="retailcrm_url" value="<?php if (isset($saved_settings['retailcrm_url'])): echo $saved_settings['retailcrm_url']; endif; ?>">
</div>
<div class="retailcrm_unit">
<label for="retailcrm_apikey"><?php echo $retailcrm_apikey; ?></label><br>
<input id="retailcrm_apikey" type="text" name="retailcrm_apikey" value="<?php if (isset($saved_settings['retailcrm_apikey'])): echo $saved_settings['retailcrm_apikey']; endif;?>">
</div>
<h3><?php echo $retailcrm_countries_settings; ?></h3> <h3><?php echo $retailcrm_base_settings; ?></h3>
<div class="retailcrm_unit">
<div class="well well-sm" style="height: 150px; overflow: auto; width: 30%;">
<?php foreach($countries as $country) : ?>
<div class="checkbox">
<label>
<input type="checkbox" name="<?php echo 'retailcrm_country[]'; ?>" value="<?php echo $country['country_id']; ?>" <?php if(isset($saved_settings['retailcrm_country']) && in_array($country['country_id'], $saved_settings['retailcrm_country'])): echo 'checked'; endif;?>>
<?php echo $country['name']; ?>
</label>
</div>
<?php endforeach; ?>
</div>
</div>
<?php if (isset($saved_settings['retailcrm_apikey']) && $saved_settings['retailcrm_apikey'] != '' && isset($saved_settings['retailcrm_url']) && $saved_settings['retailcrm_url'] != ''): ?>
<?php if (!empty($retailcrm_errors)) : ?>
<?php foreach($retailcrm_errors as $retailcrm_error): ?>
<div class="warning"><?php echo $retailcrm_error ?></div>
<?php endforeach; ?>
<?php else: ?>
<h3><?php echo $retailcrm_upload_order; ?></h3>
<div class="retailcrm_unit">
<label><?php echo $text_button_export_order; ?> № </label><input type="text" name="order_id">
<button type="button" id="export_order" data-toggle="tooltip" title="<?php echo $text_button_export_order; ?>" class="btn btn-success"><i class="fa fa-download"></i></button>
</div>
<h3><?php echo $retailcrm_dict_settings; ?></h3>
<h4><?php echo $retailcrm_dict_delivery; ?></h4>
<?php foreach($delivery['opencart'] as $value): ?>
<div class="pm"><?php echo $value['title'].':'; ?></div>
<?php unset($value['title']); ?>
<?php foreach ($value as $key => $val): ?>
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<select id="retailcrm_delivery_<?php echo $val['code']; ?>" name="retailcrm_delivery[<?php echo $val['code']; ?>]" > <label for="retailcrm_url"><?php echo $retailcrm_url; ?></label><br>
<?php foreach ($delivery['retailcrm'] as $k => $v): ?> <input id="retailcrm_url" type="text" name="retailcrm_url" value="<?php if (isset($saved_settings['retailcrm_url'])): echo $saved_settings['retailcrm_url']; endif; ?>">
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_delivery'][$key]) && $v['code'] == $saved_settings['retailcrm_delivery'][$key]):?>selected="selected"<?php endif;?>> </div>
<?php echo $v['name'];?> <div class="retailcrm_unit">
</option> <label for="retailcrm_apikey"><?php echo $retailcrm_apikey; ?></label><br>
<?php endforeach; ?> <input id="retailcrm_apikey" type="text" name="retailcrm_apikey" value="<?php if (isset($saved_settings['retailcrm_apikey'])): echo $saved_settings['retailcrm_apikey']; endif;?>">
</select> </div>
<label for="retailcrm_pm_<?php echo $val['code']; ?>"><?php echo $val['title']; ?></label>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
<h4><?php echo $retailcrm_dict_status; ?></h4> <h3><?php echo $retailcrm_countries_settings; ?></h3>
<?php foreach ($statuses['opencart'] as $status): ?> <div class="retailcrm_unit">
<?php $uid = $status['order_status_id']?> <div class="well well-sm" style="height: 150px; overflow: auto; width: 30%;">
<div class="retailcrm_unit"> <?php foreach($countries as $country) : ?>
<select id="retailcrm_status_<?php echo $uid; ?>" name="retailcrm_status[<?php echo $uid; ?>]" > <div class="checkbox">
<?php foreach ($statuses['retailcrm'] as $k => $v): ?> <label>
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_status'][$uid]) && $v['code'] == $saved_settings['retailcrm_status'][$uid]):?>selected="selected"<?php endif;?>> <input type="checkbox" name="<?php echo 'retailcrm_country[]'; ?>" value="<?php echo $country['country_id']; ?>" <?php if(isset($saved_settings['retailcrm_country']) && in_array($country['country_id'], $saved_settings['retailcrm_country'])): echo 'checked'; endif;?>>
<?php echo $v['name'];?> <?php echo $country['name']; ?>
</option> </label>
</div>
<?php endforeach; ?>
</div>
</div>
<?php if (isset($saved_settings['retailcrm_apikey']) && $saved_settings['retailcrm_apikey'] != '' && isset($saved_settings['retailcrm_url']) && $saved_settings['retailcrm_url'] != ''): ?>
<?php if (!empty($retailcrm_errors)) : ?>
<?php foreach($retailcrm_errors as $retailcrm_error): ?>
<div class="warning"><?php echo $retailcrm_error ?></div>
<?php endforeach; ?> <?php endforeach; ?>
</select> <?php else: ?>
<label for="retailcrm_status_<?php echo $status['order_status_id']; ?>"><?php echo $status['name']; ?></label> <h3><?php echo $retailcrm_upload_order; ?></h3>
</div> <div class="retailcrm_unit">
<?php endforeach; ?> <label><?php echo $text_button_export_order; ?> № </label><input type="text" name="order_id">
<button type="button" id="export_order" data-toggle="tooltip" title="<?php echo $text_button_export_order; ?>" class="btn btn-success"><i class="fa fa-download"></i></button>
</div>
</div>
<h4><?php echo $retailcrm_dict_payment; ?></h4> <div class="tab-pane" id="tab-references">
<?php foreach ($payments['opencart'] as $key => $value): ?> <h3><?php echo $retailcrm_dict_settings; ?></h3>
<div class="retailcrm_unit">
<select id="retailcrm_payment_<?php echo $key; ?>" name="retailcrm_payment[<?php echo $key; ?>]" > <h4><?php echo $retailcrm_dict_delivery; ?></h4>
<?php foreach ($payments['retailcrm'] as $k => $v): ?> <?php foreach($delivery['opencart'] as $value): ?>
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_payment'][$key]) && $v['code'] == $saved_settings['retailcrm_payment'][$key]):?>selected="selected"<?php endif;?>>
<?php echo $v['name'];?> <div class="pm"><?php echo $value['title'].':'; ?></div>
</option> <?php unset($value['title']); ?>
<?php foreach ($value as $key => $val): ?>
<div class="retailcrm_unit">
<select id="retailcrm_delivery_<?php echo $val['code']; ?>" name="retailcrm_delivery[<?php echo $val['code']; ?>]" >
<?php foreach ($delivery['retailcrm'] as $k => $v): ?>
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_delivery'][$key]) && $v['code'] == $saved_settings['retailcrm_delivery'][$key]):?>selected="selected"<?php endif;?>>
<?php echo $v['name'];?>
</option>
<?php endforeach; ?>
</select>
<label for="retailcrm_pm_<?php echo $val['code']; ?>"><?php echo $val['title']; ?></label>
<?php endforeach; ?>
</div>
<?php endforeach; ?> <?php endforeach; ?>
</select>
<label for="retailcrm_payment_<?php echo $key; ?>"><?php echo $value; ?></label> <h4><?php echo $retailcrm_dict_status; ?></h4>
<?php foreach ($statuses['opencart'] as $status): ?>
<?php $uid = $status['order_status_id']?>
<div class="retailcrm_unit">
<select id="retailcrm_status_<?php echo $uid; ?>" name="retailcrm_status[<?php echo $uid; ?>]" >
<?php foreach ($statuses['retailcrm'] as $k => $v): ?>
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_status'][$uid]) && $v['code'] == $saved_settings['retailcrm_status'][$uid]):?>selected="selected"<?php endif;?>>
<?php echo $v['name'];?>
</option>
<?php endforeach; ?>
</select>
<label for="retailcrm_status_<?php echo $status['order_status_id']; ?>"><?php echo $status['name']; ?></label>
</div>
<?php endforeach; ?>
<h4><?php echo $retailcrm_dict_payment; ?></h4>
<?php foreach ($payments['opencart'] as $key => $value): ?>
<div class="retailcrm_unit">
<select id="retailcrm_payment_<?php echo $key; ?>" name="retailcrm_payment[<?php echo $key; ?>]" >
<?php foreach ($payments['retailcrm'] as $k => $v): ?>
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_payment'][$key]) && $v['code'] == $saved_settings['retailcrm_payment'][$key]):?>selected="selected"<?php endif;?>>
<?php echo $v['name'];?>
</option>
<?php endforeach; ?>
</select>
<label for="retailcrm_payment_<?php echo $key; ?>"><?php echo $value; ?></label>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
</div>
<div class="tab-pane" id="tab-collector">
<h4><?php echo $daemon_collector; ?></h4>
<div class="retailcrm_unit">
<div class="checkbox">
<label class="radio-inline">
<input type="radio" name="retailcrm_collector_active" value="1" <?php if (isset($saved_settings['retailcrm_collector_active']) &&
$saved_settings['retailcrm_collector_active'] == 1) :
echo 'checked'; endif; ?>>
<?php echo $text_yes; ?>
</label>
<label class="radio-inline">
<input type="radio" name="retailcrm_collector_active" value="0" <?php if (!isset($saved_settings['retailcrm_collector_active']) ||
$saved_settings['retailcrm_collector_active'] == 0) :
echo 'checked'; endif; ?>>
<?php echo $text_no; ?>
</label>
</div>
</div>
<div class="retailcrm_unit">
<label for="retailcrm_collector_site_key"><?php echo $collector_site_key; ?></label><br>
<input id="retailcrm_collector_site_key" type="text" name="retailcrm_collector_site_key" value="<?php if (isset($saved_settings['retailcrm_collector_site_key'])): echo $saved_settings['retailcrm_collector_site_key']; endif; ?>">
</div>
</div>
</div> </div>
<?php endforeach; ?>
<?php endif; ?> <!------------------------- -->
<?php endif; ?>
</form> </form>
</div> </div>
</div> </div>

View File

@ -0,0 +1,22 @@
<?php
class ControllerExtensionAnalyticsDaemonCollector extends Controller {
public function index() {
$siteCode = $this->config->get('retailcrm_collector_site_key');
if ($this->customer->isLogged()) $customerId = $this->customer->getID();
$customer = isset($customerId) ? "'customerId': '" . $customerId . "'" : "";
$js = "<script type='text/javascript'>
(function(_,r,e,t,a,i,l){_['retailCRMObject']=a;_[a]=_[a]||function(){(_[a].q=_[a].q||[]).push(arguments)};_[a].l=1*new Date();l=r.getElementsByTagName(e)[0];i=r.createElement(e);i.async=!0;i.src=t;l.parentNode.insertBefore(i,l)})(window,document,'script','https://collector.retailcrm.pro/w.js','_rc');
_rc('create', '" . $siteCode . "', {
" . $customer . "
});
_rc('send', 'pageView');
</script>";
return html_entity_decode($js, ENT_QUOTES, 'UTF-8');
}
}