Skip to content

Commit

Permalink
Advanced search for delivery methods (#25)
Browse files Browse the repository at this point in the history
Plugin's deliveries
ICML export
Order export
  • Loading branch information
iyzoer authored and gwinn committed Apr 7, 2017
1 parent 3be4ac7 commit c724392
Show file tree
Hide file tree
Showing 16 changed files with 334 additions and 43 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ 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

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
Expand Down
4 changes: 2 additions & 2 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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
```

#### Настройка экспорта каталога

Для периодической выгрузки каталога добавьте в 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 установите путь к файлу выгрузки
Expand Down
52 changes: 51 additions & 1 deletion admin/controller/extension/module/retailcrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -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
*
Expand Down
12 changes: 11 additions & 1 deletion admin/language/en-gb/extension/module/retailcrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
11 changes: 11 additions & 0 deletions admin/language/ru-ru/extension/module/retailcrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = 'Способы оплаты';
Expand Down
9 changes: 9 additions & 0 deletions admin/model/extension/retailcrm/history.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '',
Expand Down
1 change: 1 addition & 0 deletions admin/model/extension/retailcrm/icml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions admin/model/extension/retailcrm/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
33 changes: 11 additions & 22 deletions admin/model/extension/retailcrm/references.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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');
Expand Down
1 change: 1 addition & 0 deletions admin/view/stylesheet/retailcrm.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.retailcrm_unit {margin-bottom: 10px;}
.retailcrm_unit input {width: 30%;}
.checkbox input{width: auto;}
Loading

0 comments on commit c724392

Please sign in to comment.