Skip to content

Commit

Permalink
Update to v2.3 (#22)
Browse files Browse the repository at this point in the history
* restruct for 2.3
* new files for 2.3
  • Loading branch information
iyzoer authored and gwinn committed Mar 22, 2017
1 parent 1045928 commit 3be4ac7
Show file tree
Hide file tree
Showing 22 changed files with 165 additions and 233 deletions.
39 changes: 0 additions & 39 deletions Changelog.md

This file was deleted.

8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
Opencart module
===============

Module allows integrate CMS Opencart 2.x with [retailCRM](http://retailcrm.pro)
Module allows integrate CMS Opencart >= 2.3 with [retailCRM](http://retailcrm.pro)

### Previous versions:

[v1.x](https://github.com/retailcrm/opencart-module/tree/v1.x)

[v2.x (2.0, 2.1, 2.2)](https://github.com/retailcrm/opencart-module/tree/v2.2)

#### Features:

Expand Down
8 changes: 7 additions & 1 deletion README.ru.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
Opencart module
===============

Модуль интеграции CMS Openacart 2.x c [RetailCRM](http://retailcrm.ru)
Модуль интеграции CMS Opencart >= 2.3 c [RetailCRM](http://retailcrm.ru)

### Предыдущие версии:

[v1.x](https://github.com/retailcrm/opencart-module/tree/v1.x)

[v2.x (2.0, 2.1, 2.2)](https://github.com/retailcrm/opencart-module/tree/v2.2)

#### Модуль позволяет:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3
*/
class ControllerModuleRetailcrm extends Controller
class ControllerExtensionModuleRetailcrm extends Controller
{
private $_error = array();
protected $log, $statuses, $payments, $deliveryTypes, $retailcrm;
Expand All @@ -33,22 +33,29 @@ public function install()
$this->model_extension_event
->addEvent(
'retailcrm',
version_compare(VERSION, '2.2', '>=') ? 'catalog/model/checkout/order/addOrder/after' : 'post.order.add',
'module/retailcrm/order_create'
'catalog/model/checkout/order/addOrder/after',
'extension/module/retailcrm/order_create'
);

$this->model_extension_event
->addEvent(
'retailcrm',
version_compare(VERSION, '2.2', '>=') ? 'catalog/model/checkout/order/addOrderHistory/after' : 'post.order.history.add',
'module/retailcrm/order_edit'
'catalog/model/checkout/order/addOrderHistory/after',
'extension/module/retailcrm/order_edit'
);

$this->model_extension_event
->addEvent(
'retailcrm',
version_compare(VERSION, '2.2', '>=') ? 'catalog/model/account/customer/addCustomer/after' : 'post.customer.add',
'module/retailcrm/customer_create'
'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'
);
}

Expand Down Expand Up @@ -77,20 +84,24 @@ public function index()

$this->load->model('setting/setting');
$this->load->model('extension/module');
$this->load->model('retailcrm/references');
$this->load->language('module/retailcrm');
$this->load->model('extension/retailcrm/references');
$this->load->language('extension/module/retailcrm');
$this->document->setTitle($this->language->get('heading_title'));
$this->document->addStyle('/admin/view/stylesheet/retailcrm.css');

if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
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;
}
$this->model_setting_setting->editSetting(
'retailcrm',
$this->request->post
);

$this->session->data['success'] = $this->language->get('text_success');
$redirect = $this->url->link(
'module/retailcrm', 'token=' . $this->session->data['token'],
'extension/module/retailcrm', 'token=' . $this->session->data['token'],
'SSL'
);

Expand Down Expand Up @@ -137,14 +148,14 @@ public function index()
$this->retailcrm = new RetailcrmProxy(
$url,
$key,
DIR_SYSTEM . 'logs/retailcrm.log'
DIR_SYSTEM . 'storage/logs/retailcrm.log'
);

$_data['delivery'] = $this->model_retailcrm_references
$_data['delivery'] = $this->model_extension_retailcrm_references
->getDeliveryTypes();
$_data['statuses'] = $this->model_retailcrm_references
$_data['statuses'] = $this->model_extension_retailcrm_references
->getOrderStatuses();
$_data['payments'] = $this->model_retailcrm_references
$_data['payments'] = $this->model_extension_retailcrm_references
->getPaymentTypes();

}
Expand Down Expand Up @@ -181,7 +192,7 @@ public function index()
$_data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link(
'extension/module',
'extension/extension/module',
'token=' . $this->session->data['token'], 'SSL'
),
'separator' => ' :: '
Expand All @@ -190,19 +201,19 @@ public function index()
$_data['breadcrumbs'][] = array(
'text' => $this->language->get('retailcrm_title'),
'href' => $this->url->link(
'module/retailcrm',
'extension/module/retailcrm',
'token=' . $this->session->data['token'], 'SSL'
),
'separator' => ' :: '
);

$_data['action'] = $this->url->link(
'module/retailcrm',
'extension/module/retailcrm',
'token=' . $this->session->data['token'], 'SSL'
);

$_data['cancel'] = $this->url->link(
'extension/module',
'extension/extension',
'token=' . $this->session->data['token'], 'SSL'
);

Expand All @@ -222,7 +233,7 @@ public function index()
$_data['footer'] = $this->load->controller('common/footer');

$this->response->setOutput(
$this->load->view('module/retailcrm.tpl', $_data)
$this->load->view('extension/module/retailcrm.tpl', $_data)
);
}

Expand All @@ -233,12 +244,12 @@ public function index()
*/
public function history()
{
if (file_exists(DIR_APPLICATION . 'model/retailcrm/custom/history.php')) {
$this->load->model('retailcrm/custom/history');
$this->model_retailcrm_custom_history->request();
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/history.php')) {
$this->load->model('extension/retailcrm/custom/history');
$this->model_extension_retailcrm_custom_history->request();
} else {
$this->load->model('retailcrm/history');
$this->model_retailcrm_history->request();
$this->load->model('extension/retailcrm/history');
$this->model_extension_retailcrm_history->request();
}
}

Expand All @@ -249,12 +260,12 @@ public function history()
*/
public function icml()
{
if (file_exists(DIR_APPLICATION . 'model/retailcrm/custom/icml.php')) {
$this->load->model('retailcrm/custom/icml');
$this->model_retailcrm_custom_icml->generateICML();
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/icml.php')) {
$this->load->model('extension/retailcrm/custom/icml');
$this->model_extension_retailcrm_custom_icml->generateICML();
} else {
$this->load->model('retailcrm/icml');
$this->model_retailcrm_icml->generateICML();
$this->load->model('extension/retailcrm/icml');
$this->model_extension_retailcrm_icml->generateICML();
}
}

Expand All @@ -278,8 +289,8 @@ public function order_create($order_id)
$status = $this->model_setting_setting->getSetting('retailcrm');
$data['order_status'] = $status['retailcrm_status'][$data['order_status_id']];

$this->load->model('retailcrm/order');
$this->model_retailcrm_order->sendToCrm($data, $data['order_id']);
$this->load->model('extension/retailcrm/order');
$this->model_extension_retailcrm_order->sendToCrm($data, $data['order_id']);
}
}

Expand All @@ -289,16 +300,12 @@ public function order_create($order_id)
*
*/
public function export() {
if(version_compare(VERSION, '2.1', '<')) {
$this->load->model('sale/customer');
$customers = $this->model_sale_customer->getCustomers();
} else {
$this->load->model('customer/customer');
$customers = $this->model_customer_customer->getCustomers();
}

$this->load->model('customer/customer');
$customers = $this->model_customer_customer->getCustomers();

$this->load->model('retailcrm/customer');
$this->model_retailcrm_customer->uploadToCrm($customers);
$this->load->model('extension/retailcrm/customer');
$this->model_extension_retailcrm_customer->uploadToCrm($customers);

$this->load->model('sale/order');
$orders = $this->model_sale_order->getOrders();
Expand All @@ -317,8 +324,8 @@ public function export() {
$fullOrders[] = $fullOrder;
}

$this->load->model('retailcrm/order');
$this->model_retailcrm_order->uploadToCrm($fullOrders);
$this->load->model('extension/retailcrm/order');
$this->model_extension_retailcrm_order->uploadToCrm($fullOrders);
}

/**
Expand All @@ -328,7 +335,7 @@ public function export() {
*/
private function validate()
{
if (!$this->user->hasPermission('modify', 'module/retailcrm')) {
if (!$this->user->hasPermission('modify', 'extension/module/retailcrm')) {
$this->_error['warning'] = $this->language->get('error_permission');
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class ModelRetailcrmCustomer extends Model {
class ModelExtensionRetailcrmCustomer extends Model {

public function uploadToCrm($customers) {
$this->load->model('setting/setting');
Expand All @@ -16,7 +16,7 @@ public function uploadToCrm($customers) {
$this->retailcrmApi = new RetailcrmProxy(
$settings['retailcrm_url'],
$settings['retailcrm_apikey'],
DIR_SYSTEM . 'logs/retailcrm.log'
DIR_SYSTEM . 'storage/logs/retailcrm.log'
);

$customersToCrm = array();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class ModelRetailcrmHistory extends Model
class ModelExtensionRetailcrmHistory extends Model
{
protected $createResult;

Expand All @@ -12,17 +12,13 @@ public function request()
$this->load->model('setting/store');
$this->load->model('user/api');
$this->load->model('sale/order');
if (version_compare(VERSION, '2.1.0.0', '>=')) {
$this->load->model('customer/customer');
} else {
$this->load->model('sale/customer');
}
$this->load->model('retailcrm/references');
$this->load->model('customer/customer');
$this->load->model('extension/retailcrm/references');
$this->load->model('catalog/product');
$this->load->model('catalog/option');
$this->load->model('localisation/zone');

$this->load->language('module/retailcrm');
$this->load->language('extension/module/retailcrm');

$settings = $this->model_setting_setting->getSetting('retailcrm');
$history = $this->model_setting_setting->getSetting('retailcrm_history');
Expand All @@ -41,7 +37,7 @@ public function request()
$crm = new RetailcrmProxy(
$settings['retailcrm_url'],
$settings['retailcrm_apikey'],
DIR_SYSTEM . 'logs/retailcrm.log'
DIR_SYSTEM . 'storage/logs/retailcrm.log'
);

$lastRun = !empty($history['retailcrm_history'])
Expand All @@ -65,10 +61,10 @@ public function request()
$this->payment = array_flip($settings['retailcrm_payment']);
$this->status = array_flip($settings['retailcrm_status']);

$this->ocPayment = $this->model_retailcrm_references
$this->ocPayment = $this->model_extension_retailcrm_references
->getOpercartPaymentTypes();

$this->ocDelivery = $this->model_retailcrm_references
$this->ocDelivery = $this->model_extension_retailcrm_references
->getOpercartDeliveryTypes();

$this->zones = $this->model_localisation_zone->getZones();
Expand Down Expand Up @@ -314,25 +310,14 @@ protected function createOrders($orders)
),
);

if (version_compare(VERSION, '2.1.0.0', '>=')) {
$this->model_customer_customer->addCustomer($cData);
} else {
$this->model_sale_customer->addCustomer($cData);
}


$this->model_customer_customer->addCustomer($cData);

if (!empty($order['email'])) {
if (version_compare(VERSION, '2.1.0.0', '>=')) {
$tryToFind = $this->model_customer_customer->getCustomerByEmail($order['email']);
} else {
$tryToFind = $this->model_sale_customer->getCustomerByEmail($order['email']);
}
$tryToFind = $this->model_customer_customer->getCustomerByEmail($order['email']);
$customer_id = $tryToFind['customer_id'];
} else {
if (version_compare(VERSION, '2.1.0.0', '>=')) {
$last = $this->model_customer_customer->getCustomers($data = array('order' => 'DESC', 'limit' => 1));
} else {
$last = $this->model_sale_customer->getCustomers($data = array('order' => 'DESC', 'limit' => 1));
}
$last = $this->model_customer_customer->getCustomers($data = array('order' => 'DESC', 'limit' => 1));
$customer_id = $last[0]['customer_id'];
}

Expand Down
Loading

0 comments on commit 3be4ac7

Please sign in to comment.