diff --git a/admin/controller/extension/module/retailcrm.php b/admin/controller/extension/module/retailcrm.php index 591eea1..b5a2855 100644 --- a/admin/controller/extension/module/retailcrm.php +++ b/admin/controller/extension/module/retailcrm.php @@ -54,13 +54,6 @@ class ControllerExtensionModuleRetailcrm extends Controller 'catalog/model/account/customer/addCustomer/after', 'extension/module/retailcrm/customer_create' ); - - $this->model_extension_event - ->addEvent( - 'retailcrm', - 'catalog/model/checkout/order/editOrder/after', - 'extension/module/retailcrm/order_edit' - ); } /** @@ -237,6 +230,8 @@ class ControllerExtensionModuleRetailcrm extends Controller $_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']; $this->response->setOutput( $this->load->view('extension/module/retailcrm.tpl', $_data) @@ -300,6 +295,31 @@ class ControllerExtensionModuleRetailcrm extends Controller } } + /** + * 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'); + $this->model_extension_retailcrm_order->uploadOrder($data); + } + + } + /** * Export orders * diff --git a/admin/language/en-gb/extension/module/retailcrm.php b/admin/language/en-gb/extension/module/retailcrm.php index b3e8e7e..266b1bc 100644 --- a/admin/language/en-gb/extension/module/retailcrm.php +++ b/admin/language/en-gb/extension/module/retailcrm.php @@ -11,10 +11,18 @@ $_['text_notice'] = 'Warning! Timezone in CRM & your shop must be $_['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'; + $_['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 892924d..85bbdd0 100644 --- a/admin/language/ru-ru/extension/module/retailcrm.php +++ b/admin/language/ru-ru/extension/module/retailcrm.php @@ -11,10 +11,18 @@ $_['text_notice'] = 'Внимание! Часовой пояс в $_['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'] = 'Каталог успешно выгружен'; + $_['retailcrm_dict_delivery'] = 'Способы доставки'; $_['retailcrm_dict_status'] = 'Статусы'; $_['retailcrm_dict_payment'] = 'Способы оплаты'; diff --git a/admin/model/extension/retailcrm/icml.php b/admin/model/extension/retailcrm/icml.php index f2f3d47..d1dea3e 100644 --- a/admin/model/extension/retailcrm/icml.php +++ b/admin/model/extension/retailcrm/icml.php @@ -220,7 +220,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($productPrice + $optionsTotalCost)); /** * Vendor */ diff --git a/admin/model/extension/retailcrm/order.php b/admin/model/extension/retailcrm/order.php index 77fa54d..253d31c 100644 --- a/admin/model/extension/retailcrm/order.php +++ b/admin/model/extension/retailcrm/order.php @@ -1,6 +1,7 @@ load->model('catalog/product'); @@ -20,6 +21,47 @@ class ModelExtensionRetailcrmOrder extends Model { } } + 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); + + $this->retailcrm->ordersCreate($order); + } + } + private function process($order_data) { $order = array(); diff --git a/admin/view/template/extension/module/retailcrm.tpl b/admin/view/template/extension/module/retailcrm.tpl index a77bb21..b9c84bc 100644 --- a/admin/view/template/extension/module/retailcrm.tpl +++ b/admin/view/template/extension/module/retailcrm.tpl @@ -5,6 +5,8 @@