mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-22 05:06:07 +03:00
update: admin/controller/extension/module/retailcrm.php
update: admin/language/en-gb/extension/module/retailcrm.php update: admin/language/ru-ru/extension/module/retailcrm.php update: admin/model/extension/retailcrm/icml.php update: admin/model/extension/retailcrm/order.php update: admin/view/template/extension/module/retailcrm.tpl
This commit is contained in:
parent
83fb02bf09
commit
be14df7c7a
@ -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
|
||||
*
|
||||
|
@ -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';
|
||||
|
@ -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'] = 'Способы оплаты';
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
class ModelExtensionRetailcrmOrder extends Model {
|
||||
|
||||
public function uploadToCrm($orders) {
|
||||
$this->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();
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
<div class="page-header">
|
||||
<div class="container-fluid">
|
||||
<div class="pull-right">
|
||||
<button type="button" id="icml" data-toggle="tooltip" title="<?php echo $text_button_catalog; ?>" class="btn btn-success"><i class="fa fa-file-text-o"></i></button>
|
||||
<button type="button" id="export" data-toggle="tooltip" title="<?php echo $text_button_export; ?>" class="btn btn-success"><i class="fa fa-download"></i></button>
|
||||
<button type="submit" form="form-retailcrm" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
|
||||
<a href="<?php echo $cancel; ?>" data-toggle="tooltip" title="<?php echo $button_cancel; ?>" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
|
||||
<h1><?php echo $heading_title; ?></h1>
|
||||
@ -47,7 +49,7 @@
|
||||
</div>
|
||||
<h3><?php echo $retailcrm_countries_settings; ?></h3>
|
||||
<div class="retailcrm_unit">
|
||||
<div class="well well-sm" style="height: 150px; overflow: auto;">
|
||||
<div class="well well-sm" style="height: 150px; overflow: auto; width: 30%;">
|
||||
<?php foreach($countries as $country) : ?>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
@ -58,6 +60,11 @@
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<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>
|
||||
|
||||
<?php if (isset($saved_settings['retailcrm_apikey']) && $saved_settings['retailcrm_apikey'] != '' && isset($saved_settings['retailcrm_url']) && $saved_settings['retailcrm_url'] != ''): ?>
|
||||
|
||||
@ -125,4 +132,59 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php echo $footer; ?>
|
||||
<?php echo $footer; ?>
|
||||
|
||||
<script type="text/javascript">
|
||||
var token = '<?php echo $token; ?>';
|
||||
$('#icml').on('click', function() {
|
||||
$.ajax({
|
||||
url: '<?php echo $catalog; ?>'+'system/cron/icml.php',
|
||||
beforeSend: function() {
|
||||
$('#icml').button('loading');
|
||||
},
|
||||
complete: function() {
|
||||
$('.alert-success').remove();
|
||||
$('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-exclamation-circle"></i> <?php echo $text_success_catalog; ?></div>');
|
||||
$('#icml').button('reset');
|
||||
},
|
||||
error: function(){
|
||||
alert('error');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#export').on('click', function() {
|
||||
$.ajax({
|
||||
url: '<?php echo $catalog; ?>'+'system/cron/export.php',
|
||||
beforeSend: function() {
|
||||
$('#export').button('loading');
|
||||
},
|
||||
complete: function() {
|
||||
$('.alert-success').remove();
|
||||
$('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-exclamation-circle"></i> <?php echo $text_success_export; ?></div>');
|
||||
$('#export').button('reset');
|
||||
},
|
||||
error: function(){
|
||||
alert('error');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#export_order').on('click', function() {
|
||||
$.ajax({
|
||||
url: '<?php echo $catalog; ?>'+'admin/index.php?route=extension/module/retailcrm/exportOrder&token=' + token + '&order_id=' + $('input[name=\'order_id\']').val(),
|
||||
beforeSend: function() {
|
||||
$('#export_order').button('loading');
|
||||
},
|
||||
complete: function(json) {
|
||||
$('.alert-success').remove();
|
||||
$('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-exclamation-circle"></i> <?php echo $text_success_export_order; ?></div>');
|
||||
$('#export_order').button('reset');
|
||||
},
|
||||
error: function(xhr, ajaxOptions, thrownError) {
|
||||
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user