diff --git a/README.md b/README.md index 417fc0e..216764c 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ cp -r opencart-module/* /path/to/site/root Add to cron: ``` -*/5 * * * * /usr/bin/php /path/to/opencart/system/cron/history.php >> /path/to/opencart/system/logs/cronjob_history.log 2>&1 +*/5 * * * * /usr/bin/php /path/to/opencart/system/cron/history.php >> /path/to/opencart/system/storage/logs/cronjob_history.log 2>&1 ``` #### Setting product catalog export @@ -42,7 +42,7 @@ Add to cron: Add to cron: ``` -* */4 * * * /usr/bin/php /path/to/opencart/system/cron/icml.php >> /path/to/opencart/system/logs/cronjob_icml.log 2>&1 +* */4 * * * /usr/bin/php /path/to/opencart/system/cron/icml.php >> /path/to/opencart/system/storage/logs/cronjob_icml.log 2>&1 ``` Your export file will be available by following url diff --git a/README.ru.md b/README.ru.md index 0e5d119..b3b4f46 100644 --- a/README.ru.md +++ b/README.ru.md @@ -37,7 +37,7 @@ cp -r opencart-module/* /path/to/site/root Для получения изменений и новых данных добавьте в cron следующую запись: ``` -*/5 * * * * /usr/bin/php /path/to/opencart/system/cron/history.php >> /path/to/opencart/system/logs/cronjob_history.log 2>&1 +*/5 * * * * /usr/bin/php /path/to/opencart/system/cron/history.php >> /path/to/opencart/system/storage/logs/cronjob_history.log 2>&1 ``` #### Настройка экспорта каталога @@ -45,7 +45,7 @@ cp -r opencart-module/* /path/to/site/root Для периодической выгрузки каталога добавьте в cron следующую запись: ``` -* */4 * * * /usr/bin/php /path/to/opencart/system/cron/icml.php >> /path/to/opencart/system/logs/cronjob_icml.log 2>&1 +* */4 * * * /usr/bin/php /path/to/opencart/system/cron/icml.php >> /path/to/opencart/system/storage/logs/cronjob_icml.log 2>&1 ``` В настройках CRM установите путь к файлу выгрузки diff --git a/admin/controller/extension/module/retailcrm.php b/admin/controller/extension/module/retailcrm.php index fc5500f..d8d056a 100644 --- a/admin/controller/extension/module/retailcrm.php +++ b/admin/controller/extension/module/retailcrm.php @@ -26,7 +26,11 @@ public function install() { $this->load->model('setting/setting'); $this->model_setting_setting - ->editSetting('retailcrm', array('retailcrm_status' => 1)); + ->editSetting('retailcrm', array( + 'retailcrm_status' => 1, + 'retailcrm_country' => array($this->config->get('config_country_id')) + ) + ); $this->load->model('extension/event'); @@ -82,6 +86,7 @@ public function uninstall() public function index() { + $this->load->model('localisation/country'); $this->load->model('setting/setting'); $this->load->model('extension/module'); $this->load->model('extension/retailcrm/references'); @@ -123,6 +128,16 @@ public function index() 'retailcrm_dict_delivery', 'retailcrm_dict_status', 'retailcrm_dict_payment', + 'retailcrm_countries_settings', + 'text_success_export', + 'text_success_export_order', + 'text_button_export', + 'text_button_export_order', + 'text_button_catalog', + 'text_success_catalog', + 'retailcrm_upload_order', + 'text_error_order', + 'text_error_order_id' ); $this->load->model('extension/extension'); @@ -231,7 +246,16 @@ public function index() $_data['header'] = $this->load->controller('common/header'); $_data['column_left'] = $this->load->controller('common/column_left'); $_data['footer'] = $this->load->controller('common/footer'); + $_data['countries'] = $this->model_localisation_country->getCountries(); + $_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')) { + $_data['export_file'] = false; + } else { + $_data['export_file'] = true; + } + $this->response->setOutput( $this->load->view('extension/module/retailcrm.tpl', $_data) ); @@ -294,6 +318,32 @@ public function order_create($order_id) } } + /** + * Export single order + * + * + */ + public function exportOrder() + { + $order_id = isset($this->request->get['order_id']) ? $this->request->get['order_id'] : ''; + $this->load->model('sale/order'); + + $data = $this->model_sale_order->getOrder($order_id); + $data['products'] = $this->model_sale_order->getOrderProducts($order_id); + $data['totals'] = $this->model_sale_order->getOrderTotals($order_id); + + if (!isset($data['fromApi'])) { + $this->load->model('setting/setting'); + $status = $this->model_setting_setting->getSetting('retailcrm'); + $data['order_status'] = $status['retailcrm_status'][$data['order_status_id']]; + + $this->load->model('extension/retailcrm/order'); + $result = $this->model_extension_retailcrm_order->uploadOrder($data); + } + + echo json_encode($result); + } + /** * Export orders * diff --git a/admin/language/en-gb/extension/module/retailcrm.php b/admin/language/en-gb/extension/module/retailcrm.php index f1baabb..0ca1927 100644 --- a/admin/language/en-gb/extension/module/retailcrm.php +++ b/admin/language/en-gb/extension/module/retailcrm.php @@ -10,10 +10,20 @@ $_['text_notice'] = 'Warning! Timezone in CRM & your shop must be equal, you must setup it here:'; $_['retailcrm_base_settings'] = 'Connection settings'; $_['retailcrm_dict_settings'] = 'Dictionary settings'; - +$_['retailcrm_countries_settings'] = 'Trading zones setting'; +$_['retailcrm_upload_order'] = 'Unload single order'; $_['retailcrm_url'] = 'RetailCRM URL'; $_['retailcrm_apikey'] = 'RetailCRM API Key'; +$_['text_success_export'] = 'Orders and customers successfully unloaded'; +$_['text_success_export_order'] = 'Order successfully unloaded'; +$_['text_button_export'] = 'Unload all orders and customers'; +$_['text_button_export_order'] = 'Unload order'; +$_['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!'; + $_['retailcrm_dict_delivery'] = 'Shipment methods'; $_['retailcrm_dict_status'] = 'Order statuses'; $_['retailcrm_dict_payment'] = 'Payment methods'; diff --git a/admin/language/ru-ru/extension/module/retailcrm.php b/admin/language/ru-ru/extension/module/retailcrm.php index b2062ff..9672dd5 100644 --- a/admin/language/ru-ru/extension/module/retailcrm.php +++ b/admin/language/ru-ru/extension/module/retailcrm.php @@ -10,10 +10,21 @@ $_['text_notice'] = 'Внимание! Часовой пояс в CRM должен совпадать с часовым поясом в магазине, настроки часового пояса CRM можно задать по адресу:'; $_['retailcrm_base_settings'] = 'Настройки соединения'; $_['retailcrm_dict_settings'] = 'Настройки соответствия справочников'; +$_['retailcrm_countries_settings'] = 'Настройка торговых зон'; +$_['retailcrm_upload_order'] = 'Выгрузка одного заказа'; $_['retailcrm_url'] = 'Адрес RetailCRM'; $_['retailcrm_apikey'] = 'Api ключ RetailCRM'; +$_['text_success_export'] = 'Заказы и клиенты успешно выгружены'; +$_['text_success_export_order'] = 'Заказ успешно выгружен'; +$_['text_button_export'] = 'Выгрузить все заказы и клиентов'; +$_['text_button_export_order'] = 'Выгрузить заказ'; +$_['text_button_catalog'] = 'Выгрузить каталог'; +$_['text_success_catalog'] = 'Каталог успешно выгружен'; +$_['text_error_order'] = 'Ошибка! Заказ не выгружен!'; +$_['text_error_order_id'] = 'Ошибка! Введите корректный номер заказа!'; + $_['retailcrm_dict_delivery'] = 'Способы доставки'; $_['retailcrm_dict_status'] = 'Статусы'; $_['retailcrm_dict_payment'] = 'Способы оплаты'; diff --git a/admin/model/extension/retailcrm/history.php b/admin/model/extension/retailcrm/history.php index eb19ffb..5e61bad 100644 --- a/admin/model/extension/retailcrm/history.php +++ b/admin/model/extension/retailcrm/history.php @@ -227,6 +227,15 @@ protected function updateOrders($orders) $deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0; + if(isset($order['discount']) && $order['discount'] > 0) { + $orderTotals = $this->model_sale_order->getOrderTotals($order['externalId']); + foreach($orderTotals as $orderTotal) { + if($orderTotal['code'] == 'coupon') { + $data['order_total'][] = $orderTotal; + } + } + } + $data['order_total'] = array( array( 'order_total_id' => '', diff --git a/admin/model/extension/retailcrm/icml.php b/admin/model/extension/retailcrm/icml.php index f2f3d47..7a28c1f 100644 --- a/admin/model/extension/retailcrm/icml.php +++ b/admin/model/extension/retailcrm/icml.php @@ -220,6 +220,7 @@ private function addOffers() ->appendChild($this->dd->createTextNode($product['name'])); } $e->appendChild($this->dd->createElement('price')) + ->appendChild($this->dd->createTextNode($productPrice + $optionsTotalCost)); ->appendChild($this->dd->createTextNode($product['price'] + $optionsTotalCost)); /** * Vendor diff --git a/admin/model/extension/retailcrm/order.php b/admin/model/extension/retailcrm/order.php index 77fa54d..2c27169 100644 --- a/admin/model/extension/retailcrm/order.php +++ b/admin/model/extension/retailcrm/order.php @@ -20,6 +20,49 @@ public function uploadToCrm($orders) { } } + public function uploadOrder($order) + { + if(isset($this->request->post['fromApi'])) return; + + $this->load->model('setting/setting'); + $settings = $this->model_setting_setting->getSetting('retailcrm'); + + if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) { + $this->load->model('catalog/product'); + + require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php'; + + $this->retailcrm = new RetailcrmProxy( + $settings['retailcrm_url'], + $settings['retailcrm_apikey'], + DIR_SYSTEM . 'storage/logs/retailcrm.log' + ); + + $customers = $this->retailcrm->customersList( + array( + 'name' => $order['telephone'], + 'email' => $order['email'] + ), + 1, + 100 + ); + + $order = $this->process($order); + + if($customers) { + foreach ($customers['customers'] as $customer) { + $order['customer']['id'] = $customer['id']; + } + } + + unset($customers); + + $result = $this->retailcrm->ordersCreate($order); + } + + return $result; + } + private function process($order_data) { $order = array(); diff --git a/admin/model/extension/retailcrm/references.php b/admin/model/extension/retailcrm/references.php index b764c55..79d7564 100644 --- a/admin/model/extension/retailcrm/references.php +++ b/admin/model/extension/retailcrm/references.php @@ -5,9 +5,20 @@ class ModelExtensionRetailcrmReferences extends Model { protected $retailcrm; + private $opencartApiClient; + + public function getOpercartDeliveryTypes() + { + $this->load->model('user/api'); + $this->opencartApiClient = new OpencartApiClient($this->registry); + + return $this->opencartApiClient->request('retailcrm/getDeliveryTypes', array(), array()); + } public function getDeliveryTypes() { + $this->load->model('setting/store'); + return array( 'opencart' => $this->getOpercartDeliveryTypes(), 'retailcrm' => $this->getApiDeliveryTypes() @@ -30,28 +41,6 @@ public function getPaymentTypes() ); } - public function getOpercartDeliveryTypes() - { - $deliveryMethods = array(); - $files = glob(DIR_APPLICATION . 'controller/extension/shipping/*.php'); - - if ($files) { - foreach ($files as $file) { - $extension = basename($file, '.php'); - - $this->load->language('extension/shipping/' . $extension); - - if ($this->config->get($extension . '_status')) { - $deliveryMethods[$extension.'.'.$extension] = strip_tags( - $this->language->get('heading_title') - ); - } - } - } - - return $deliveryMethods; - } - public function getOpercartOrderStatuses() { $this->load->model('localisation/order_status'); diff --git a/admin/view/stylesheet/retailcrm.css b/admin/view/stylesheet/retailcrm.css index 43cbeb6..5c3b88f 100644 --- a/admin/view/stylesheet/retailcrm.css +++ b/admin/view/stylesheet/retailcrm.css @@ -1,2 +1,3 @@ .retailcrm_unit {margin-bottom: 10px;} .retailcrm_unit input {width: 30%;} +.checkbox input{width: auto;} diff --git a/admin/view/template/extension/module/retailcrm.tpl b/admin/view/template/extension/module/retailcrm.tpl index 144f68b..9afdbdd 100644 --- a/admin/view/template/extension/module/retailcrm.tpl +++ b/admin/view/template/extension/module/retailcrm.tpl @@ -5,6 +5,10 @@