diff --git a/admin/controller/extension/module/retailcrm.php b/admin/controller/extension/module/retailcrm.php index f36fc49..2af82fb 100644 --- a/admin/controller/extension/module/retailcrm.php +++ b/admin/controller/extension/module/retailcrm.php @@ -83,7 +83,8 @@ class ControllerExtensionModuleRetailcrm extends Controller * @return void */ public function uninstall() - { + { + $this->uninstall_collector(); $this->load->model('setting/setting'); $this->model_setting_setting ->editSetting('retailcrm', array('retailcrm_status' => 0)); @@ -92,13 +93,40 @@ class ControllerExtensionModuleRetailcrm extends Controller $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 * * @return void */ public function index() - { + { + $this->load->model('extension/extension'); $this->load->model('localisation/country'); $this->load->model('setting/setting'); $this->load->model('extension/module'); @@ -108,6 +136,16 @@ class ControllerExtensionModuleRetailcrm extends Controller $this->document->addStyle('/admin/view/stylesheet/retailcrm.css'); 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'])){ $crm_url = parse_url($this->request->post['retailcrm_url'], PHP_URL_HOST); $this->request->post['retailcrm_url'] = 'https://'.$crm_url; @@ -150,7 +188,21 @@ class ControllerExtensionModuleRetailcrm extends Controller 'text_success_catalog', 'retailcrm_upload_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', + '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'); @@ -200,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'] = ''; } @@ -263,12 +321,20 @@ class ControllerExtensionModuleRetailcrm extends Controller $_data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; $_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; } else { $_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) ); @@ -427,7 +493,7 @@ class ControllerExtensionModuleRetailcrm extends Controller $this->load->model('extension/retailcrm/order'); $this->model_extension_retailcrm_order->uploadToCrm($fullOrders); - $file = fopen(DIR_SYSTEM . '/cron/export_done.txt', "x"); + $file = fopen(DIR_SYSTEM . '/cron/export_done', "x"); } /** @@ -441,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 { diff --git a/admin/language/en-gb/extension/module/retailcrm.php b/admin/language/en-gb/extension/module/retailcrm.php index 0ca1927..3e55368 100644 --- a/admin/language/en-gb/extension/module/retailcrm.php +++ b/admin/language/en-gb/extension/module/retailcrm.php @@ -12,8 +12,15 @@ $_['retailcrm_base_settings'] = 'Connection settings'; $_['retailcrm_dict_settings'] = 'Dictionary settings'; $_['retailcrm_countries_settings'] = 'Trading zones setting'; $_['retailcrm_upload_order'] = 'Unload single order'; +$_['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'; +$_['collector_site_key'] = 'Site key'; $_['text_success_export'] = 'Orders and customers successfully unloaded'; $_['text_success_export_order'] = 'Order successfully unloaded'; @@ -23,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'; @@ -36,6 +53,8 @@ $_['color'] = 'Color'; $_['weight'] = 'Weight'; $_['size'] = 'Size'; +$_['text_yes'] = 'Yes'; +$_['text_no'] = 'No'; // Errors $_['error_permission'] = 'Warning! You do not have permission to modify module'; diff --git a/admin/language/ru-ru/extension/module/retailcrm.php b/admin/language/ru-ru/extension/module/retailcrm.php index 9672dd5..0c99f25 100644 --- a/admin/language/ru-ru/extension/module/retailcrm.php +++ b/admin/language/ru-ru/extension/module/retailcrm.php @@ -12,9 +12,15 @@ $_['retailcrm_base_settings'] = 'Настройки соединения'; $_['retailcrm_dict_settings'] = 'Настройки соответствия справочников'; $_['retailcrm_countries_settings'] = 'Настройка торговых зон'; $_['retailcrm_upload_order'] = 'Выгрузка одного заказа'; +$_['daemon_collector'] = 'Демон Collector'; +$_['general_tab_text'] = 'Главная'; +$_['references_tab_text'] = 'Справочники'; +$_['collector_tab_text'] = 'Collector'; +$_['collector_custom_text'] = 'Настройка полей формы'; $_['retailcrm_url'] = 'Адрес RetailCRM'; $_['retailcrm_apikey'] = 'Api ключ RetailCRM'; +$_['collector_site_key'] = 'Ключ сайта'; $_['text_success_export'] = 'Заказы и клиенты успешно выгружены'; $_['text_success_export_order'] = 'Заказ успешно выгружен'; @@ -24,6 +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'] = 'Статусы'; @@ -37,6 +53,8 @@ $_['color'] = 'Цвет'; $_['weight'] = 'Вес'; $_['size'] = 'Размер'; +$_['text_yes'] = 'Да'; +$_['text_no'] = 'Нет'; // Errors $_['error_permission'] = 'У вас недостаточно прав на изменение настроек модуля'; diff --git a/admin/model/extension/retailcrm/icml.php b/admin/model/extension/retailcrm/icml.php index f2f3d47..5535e3a 100644 --- a/admin/model/extension/retailcrm/icml.php +++ b/admin/model/extension/retailcrm/icml.php @@ -121,13 +121,20 @@ class ModelExtensionRetailcrmIcml extends Model // Если первая итерация if(empty($offers)) { foreach($requiredOption['product_option_value'] as $optionValue) { - $offers[$requiredOption['product_option_id'].':'.$requiredOption['option_id'].'-'.$optionValue['option_value_id']] = (float)$optionValue['price']; + $offers[$requiredOption['product_option_id'].':'.$requiredOption['option_id'].'-'.$optionValue['option_value_id']] = array( + 'price' => (float)$optionValue['price'], + 'qty' => $optionValue['quantity'] + ); } } else { - foreach($offers as $optionKey => $optionCost) { + foreach($offers as $optionKey => $optionAttr) { unset($offers[$optionKey]); // Работая в контексте обязательных опций не забываем удалять прошлые обязательные опции, т.к. они должны быть скомбинированы с другими обязательными опциями foreach($requiredOption['product_option_value'] as $optionValue) { - $offers[$optionKey.'_'.$requiredOption['product_option_id'].':'.$requiredOption['option_id'].'-'.$optionValue['option_value_id']] = $optionCost + (float)$optionValue['price']; + $offers[$optionKey.'_'.$requiredOption['product_option_id'].':'.$requiredOption['option_id'].'-'.$optionValue['option_value_id']] = array( + 'price' => $optionAttr['price'] + (float)$optionValue['price'], + 'qty' => ($optionAttr['qty'] > $optionValue['quantity']) ? + $optionValue['quantity'] : $optionAttr['qty'] + ); } } } @@ -138,21 +145,28 @@ class ModelExtensionRetailcrmIcml extends Model if(empty($offers)) { $offers['0:0-0'] = 0; // В случае работы с необязательными опциями мы должны учитывать товарное предложение без опций, поэтому создадим "пустую" опцию foreach($notRequiredOption['product_option_value'] as $optionValue) { - $offers[$notRequiredOption['product_option_id'].':'.$notRequiredOption['option_id'].'-'.$optionValue['option_value_id']] = (float)$optionValue['price']; + $offers[$notRequiredOption['product_option_id'].':'.$notRequiredOption['option_id'].'-'.$optionValue['option_value_id']] = array( + 'price' => (float)$optionValue['price'], + 'qty' => $optionValue['quantity'] + ); } } else { - foreach($offers as $optionKey => $optionCost) { + foreach($offers as $optionKey => $optionAttr) { foreach($notRequiredOption['product_option_value'] as $optionValue) { - $offers[$optionKey.'_'.$notRequiredOption['product_option_id'].':'.$notRequiredOption['option_id'].'-'.$optionValue['option_value_id']] = $optionCost + (float)$optionValue['price']; + $offers[$optionKey.'_'.$notRequiredOption['product_option_id'].':'.$notRequiredOption['option_id'].'-'.$optionValue['option_value_id']] = array( + 'price' => $optionAttr['price'] + (float)$optionValue['price'], + 'qty' => ($optionAttr['qty'] > $optionValue['quantity']) ? + $optionValue['quantity'] : $optionAttr['qty'] + ); } } } } if(empty($offers)) { - $offers = array('0:0-0' => '0'); + $offers = array('0:0-0' => array('price' => '0', 'qty' => '0')); } - foreach($offers as $optionsString => $optionsTotalCost) { + foreach($offers as $optionsString => $optionsValues) { $optionsString = explode('_', $optionsString); $options = array(); foreach($optionsString as $optionString) { @@ -174,12 +188,16 @@ class ModelExtensionRetailcrmIcml extends Model } $offerId = implode('_', $offerId); $e = $this->eOffers->appendChild($this->dd->createElement('offer')); - if(!empty($offerId)) + if(!empty($offerId)) { $e->setAttribute('id', $product['product_id'].'#'.$offerId); - else + $e->setAttribute('productId', $product['product_id']); + $e->setAttribute('quantity', $optionsValues['qty']); + } + else { $e->setAttribute('id', $product['product_id']); - $e->setAttribute('productId', $product['product_id']); - $e->setAttribute('quantity', $product['quantity']); + $e->setAttribute('productId', $product['product_id']); + $e->setAttribute('quantity', $product['quantity']); + } /** * Offer activity */ @@ -220,7 +238,7 @@ class ModelExtensionRetailcrmIcml extends Model ->appendChild($this->dd->createTextNode($product['name'])); } $e->appendChild($this->dd->createElement('price')) - ->appendChild($this->dd->createTextNode($product['price'] + $optionsTotalCost)); + ->appendChild($this->dd->createTextNode($product['price'] + $optionsValues['price'])); /** * Vendor */ diff --git a/admin/view/stylesheet/retailcrm.css b/admin/view/stylesheet/retailcrm.css index 5c3b88f..2efb7ae 100644 --- a/admin/view/stylesheet/retailcrm.css +++ b/admin/view/stylesheet/retailcrm.css @@ -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;} \ No newline at end of file diff --git a/admin/view/template/extension/module/retailcrm.tpl b/admin/view/template/extension/module/retailcrm.tpl index 8703791..6ee4124 100644 --- a/admin/view/template/extension/module/retailcrm.tpl +++ b/admin/view/template/extension/module/retailcrm.tpl @@ -38,97 +38,196 @@