Daemon Collector settings interface, update contoller Daemon Collector

This commit is contained in:
iyzoer 2017-05-31 13:08:07 +03:00
parent a1cd3aa6b7
commit 19ceeae2b0
8 changed files with 201 additions and 35 deletions

View File

@ -195,7 +195,14 @@ class ControllerExtensionModuleRetailcrm extends Controller
'collector_tab_text',
'text_yes',
'text_no',
'collector_site_key'
'collector_site_key',
'text_collector_activity',
'text_collector_form_capture',
'text_collector_period',
'text_label_promo',
'text_label_send',
'collector_custom_text',
'text_require'
);
$this->load->model('extension/extension');
@ -245,8 +252,14 @@ class ControllerExtensionModuleRetailcrm extends Controller
}
}
if (isset($this->error['warning'])) {
$_data['error_warning'] = $this->error['warning'];
if (isset($this->_error['warning'])) {
$_data['error_warning'] = $this->_error['warning'];
} else {
$_data['error_warning'] = '';
}
if (isset($this->_error['fields'])) {
$_data['error_warning'] = $this->_error['fields'];
} else {
$_data['error_warning'] = '';
}
@ -314,6 +327,14 @@ class ControllerExtensionModuleRetailcrm extends Controller
$_data['export_file'] = true;
}
$collectorFields = array(
'name' => $this->language->get('field_name'),
'email' => $this->language->get('field_email'),
'phone' => $this->language->get('field_phone')
);
$_data['collectorFields'] = $collectorFields;
$this->response->setOutput(
$this->load->view('extension/module/retailcrm.tpl', $_data)
);
@ -486,6 +507,15 @@ class ControllerExtensionModuleRetailcrm extends Controller
$this->_error['warning'] = $this->language->get('error_permission');
}
if (isset($this->request->post['retailcrm_collector']['custom']) &&
$this->request->post['retailcrm_collector']['custom_form'] == 1) {
$customField = $this->request->post['retailcrm_collector']['custom'];
if (empty($customField['name']) && empty($customField['email']) && empty($customField['phone'])) {
$this->_error['fields'] = $this->language->get('text_error_collector_fields');
}
}
if (!$this->_error) {
return true;
} else {

View File

@ -16,6 +16,7 @@ $_['daemon_collector'] = 'Daemon Collector';
$_['general_tab_text'] = 'General';
$_['references_tab_text'] = 'References';
$_['collector_tab_text'] = 'Collector';
$_['collector_custom_text'] = 'Custom form';
$_['retailcrm_url'] = 'RetailCRM URL';
$_['retailcrm_apikey'] = 'RetailCRM API Key';
@ -29,6 +30,16 @@ $_['text_button_catalog'] = 'Unload catalog';
$_['text_success_catalog'] = 'Catalog successfully unloaded';
$_['text_error_order'] = 'Error! Order is not unloaded!';
$_['text_error_order_id'] = 'Error! Enter the correct order number!';
$_['text_collector_activity'] = 'Use Daemon Collector';
$_['text_collector_form_capture']= 'Show capture form';
$_['text_collector_period'] = 'Form show period (in minutes)';
$_['text_label_promo'] = 'Text form title';
$_['text_label_send'] = 'Text button';
$_['field_name'] = 'Name';
$_['field_email'] = 'Email';
$_['field_phone'] = 'Phone';
$_['text_require'] = 'Require';
$_['text_error_collector_fields']= 'Fill in the field names Daemon Collector';
$_['retailcrm_dict_delivery'] = 'Shipment methods';
$_['retailcrm_dict_status'] = 'Order statuses';

View File

@ -16,6 +16,7 @@ $_['daemon_collector'] = 'Демон Collector';
$_['general_tab_text'] = 'Главная';
$_['references_tab_text'] = 'Справочники';
$_['collector_tab_text'] = 'Collector';
$_['collector_custom_text'] = 'Настройка полей формы';
$_['retailcrm_url'] = 'Адрес RetailCRM';
$_['retailcrm_apikey'] = 'Api ключ RetailCRM';
@ -29,7 +30,16 @@ $_['text_button_catalog'] = 'Выгрузить каталог';
$_['text_success_catalog'] = 'Каталог успешно выгружен';
$_['text_error_order'] = 'Ошибка! Заказ не выгружен!';
$_['text_error_order_id'] = 'Ошибка! Введите корректный номер заказа!';
$_['text_collector_activity'] = 'Использовать Демон Collector';
$_['text_collector_form_capture']= 'Показывать форму захвата';
$_['text_collector_period'] = 'Периодичность всплывания формы (в минутах)';
$_['text_label_promo'] = 'Текст заголовка формы';
$_['text_label_send'] = 'Текст кнопки';
$_['field_name'] = 'Имя';
$_['field_email'] = 'Email';
$_['field_phone'] = 'Телефон';
$_['text_require'] = 'Обязательно для заполнения';
$_['text_error_collector_fields']= 'Заполните названия полей формы Демон Collector';
$_['retailcrm_dict_delivery'] = 'Способы доставки';
$_['retailcrm_dict_status'] = 'Статусы';

View File

@ -1,3 +1,4 @@
.retailcrm_unit {margin-bottom: 10px;}
.retailcrm_unit input {width: 30%;}
.checkbox input{width: auto;}
.retailcrm_unit input[type=checkbox] {width: 13px;}

View File

@ -38,7 +38,6 @@
<div class="panel panel-default">
<div class="panel-body">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-retailcrm">
<!------------------------- -->
<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'] != ''): ?>
@ -146,10 +145,9 @@
</div>
<div class="tab-pane" id="tab-collector">
<h4><?php echo $daemon_collector; ?></h4>
<h3><?php echo $daemon_collector; ?></h3>
<div class="retailcrm_unit">
<div class="checkbox">
<label for="retailcrm_collector_active" class="col-md-4"><?php echo $text_collector_activity; ?></label>
<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) :
@ -163,16 +161,73 @@
<?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; ?>">
<label for="retailcrm_collector" class="col-md-4"><?php echo $collector_site_key; ?></label>
<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>
<?php if (!empty($saved_settings['retailcrm_collector']['site_key']) &&
$saved_settings['retailcrm_collector_active'] == 1) :?>
<div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4"><?php echo $text_collector_form_capture; ?></label>
<label class="radio-inline">
<input type="radio" name="retailcrm_collector[form_capture]" value="1" <?php if (isset($saved_settings['retailcrm_collector']['form_capture']) &&
$saved_settings['retailcrm_collector']['form_capture'] == 1) :
echo 'checked'; endif; ?>>
<?php echo $text_yes; ?>
</label>
<label class="radio-inline">
<input type="radio" name="retailcrm_collector[form_capture]" value="0" <?php if (!isset($saved_settings['retailcrm_collector']['form_capture']) ||
$saved_settings['retailcrm_collector']['form_capture'] == 0) :
echo 'checked'; endif; ?>>
<?php echo $text_no; ?>
</label>
</div>
<?php if (isset($saved_settings['retailcrm_collector']['form_capture']) &&
$saved_settings['retailcrm_collector']['form_capture'] == 1) :?>
<div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4"><?php echo $text_collector_period; ?></label>
<input id="retailcrm_collector_period" type="text" name="retailcrm_collector[period]" value="<?php if (isset($saved_settings['retailcrm_collector']['period'])): echo $saved_settings['retailcrm_collector']['period']; endif; ?>">
</div>
<div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4"><?php echo $text_label_promo; ?></label>
<input id="retailcrm_collector[]" type="text" name="retailcrm_collector[label_promo]" value="<?php if (isset($saved_settings['retailcrm_collector']['label_promo'])): echo $saved_settings['retailcrm_collector']['label_promo']; endif; ?>">
</div>
<div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4"><?php echo $text_label_send; ?></label>
<input id="retailcrm_collector_label_send" type="text" name="retailcrm_collector[label_send]" value="<?php if (isset($saved_settings['retailcrm_collector']['label_send'])): echo $saved_settings['retailcrm_collector']['label_send']; endif; ?>">
</div>
<div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4"><?php echo $collector_custom_text; ?></label>
<label class="radio-inline">
<input type="radio" name="retailcrm_collector[custom_form]" value="1" <?php if (isset($saved_settings['retailcrm_collector']['custom_form']) &&
$saved_settings['retailcrm_collector']['custom_form'] == 1) :
echo 'checked'; endif; ?>>
<?php echo $text_yes; ?>
</label>
<label class="radio-inline">
<input type="radio" name="retailcrm_collector[custom_form]" value="0" <?php if (!isset($saved_settings['retailcrm_collector']['custom_form']) ||
$saved_settings['retailcrm_collector']['custom_form'] == 0) :
echo 'checked'; endif; ?>>
<?php echo $text_no; ?>
</label>
</div>
<?php if (isset($saved_settings['retailcrm_collector']['custom_form']) &&
$saved_settings['retailcrm_collector']['custom_form'] == 1) :?>
<?php foreach ($collectorFields as $field => $label) : ?>
<div class="retailcrm_unit">
<label for="retailcrm_collector" class="col-md-4"><?php echo $label; ?></label>
<div class="col-md-8">
<input id="retailcrm_collector" type="text" name="retailcrm_collector[custom][<?php echo $field; ?>]" value="<?php if (isset($saved_settings['retailcrm_collector']['custom'][$field])) : echo $saved_settings['retailcrm_collector']['custom'][$field]; endif; ?>">
<input type="checkbox" name="retailcrm_collector[require][<?php echo $field; ?>_require]" value="1" <?php if (isset($saved_settings['retailcrm_collector']['require'][$field.'_require'])) : echo 'checked'; endif;?>>
<label for="retailcrm_collector"><?php echo $text_require; ?></label>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
<!------------------------- -->
</form>
</div>
</div>

View File

@ -1,19 +1,78 @@
<?php
class ControllerExtensionAnalyticsDaemonCollector extends Controller {
public function index() {
$siteCode = $this->config->get('retailcrm_collector_site_key');
$this->load->model('setting/setting');
$settings = $this->model_setting_setting->getSetting('retailcrm');
$setting = $settings['retailcrm_collector'];
$siteCode = isset($setting['site_key']) ? $setting['site_key'] : '';
if ($this->customer->isLogged()) $customerId = $this->customer->getID();
$customer = isset($customerId) ? "'customerId': '" . $customerId . "'" : "";
$labelPromo = !empty($setting['label_promo']) ? $setting['label_promo'] : null;
$labelSend = !empty($setting['label_send']) ? $setting['label_send'] : null;
$customForm = '';
$js = "<script type='text/javascript'>
if (isset($setting['custom']) && $setting['custom_form'] == 1) {
$customForm = "'fields': {";
$cntEmpty = 0;
foreach ($setting['custom'] as $field => $label) {
if (empty($label)) { $cntEmpty += 1; continue; }
if (isset($setting['require'][$field . '_require'])) {
$customForm .= "\n\t'$field': { required: true, label: '$label' },";
} else {
$customForm .= "\n\t'$field': { label: '$label' },";
}
}
$customForm .= "\n\t},";
if ($cntEmpty == count($setting['custom'])) $customForm = '';
}
if (isset($setting['form_capture']) && $setting['form_capture'] == 1) {
if (!empty($setting['period']) && is_numeric($setting['period'])) {
if ($labelPromo != null || $labelSend != null){
$captureForm = "_rc('require', 'capture-form', {
'period': " . $setting['period'] . ",
" . $customForm . "
labelPromo: '" . $labelPromo . "',
labelSend: '" . $labelSend . "'
});";
} else {
$captureForm = "_rc('require', 'capture-form', {
'period': " . $settings['retailcrm_collector']['period'] . ",
" . $customForm . "
});";
}
} elseif ($labelPromo != null || $labelSend != null) {
$captureForm = "_rc('require', 'capture-form', {
" . $customForm . "
labelPromo: '" . $labelPromo . "',
labelSend: '" . $labelSend . "'
});";
} elseif (isset($setting['custom'])){
$captureForm = "_rc('require', 'capture-form', {
" . $customForm . "
});";
} else {
$captureForm = "_rc('require', 'capture-form');";
}
} else {
$captureForm = "";
}
$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 . "
});
" . $captureForm . "
_rc('send', 'pageView');
</script>";

View File

@ -43,11 +43,6 @@ class ControllerExtensionModuleRetailcrm extends Controller
$data['order_status'] = $status['retailcrm_status'][$data['order_status_id']];
}
$data['totals'][] = array(
'code' => 'shipping',
'value' => $this->session->data['shipping_method']['cost']
);
$this->load->model('extension/retailcrm/order');
$this->model_extension_retailcrm_order->sendToCrm($data, $data['order_id']);
}

View File

@ -204,8 +204,13 @@ class ModelExtensionRetailcrmOrder extends Model {
if ($totals['code'] == 'shipping') {
$deliveryCost = $totals['value'];
}
if ($totals['code'] == 'coupon') {
$couponTotal = abs($totals['value']);
}
}
$order['discount'] = $couponTotal;
$order['createdAt'] = $order_data['date_added'];
$order['paymentType'] = $settings['retailcrm_payment'][$payment_code];