mirror of
https://github.com/retailcrm/opencart-module.git
synced 2025-01-23 11:11:41 +03:00
custom dir, minor fixes
This commit is contained in:
parent
c29ed65dfa
commit
df9523f5b3
@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
require_once DIR_SYSTEM . 'library/retailcrm.php';
|
require_once DIR_SYSTEM . 'library/retailcrm.php';
|
||||||
|
|
||||||
class ControllerModuleRetailcrm extends Controller {
|
class ControllerModuleRetailcrm extends Controller
|
||||||
|
{
|
||||||
private $error = array();
|
private $error = array();
|
||||||
protected $log, $statuses, $payments, $deliveryTypes, $retailcrm;
|
protected $log, $statuses, $payments, $deliveryTypes, $retailcrm;
|
||||||
public $children, $template;
|
public $children, $template;
|
||||||
|
|
||||||
public function install() {
|
public function install()
|
||||||
|
{
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$this->model_setting_setting->editSetting(
|
$this->model_setting_setting->editSetting(
|
||||||
'retailcrm',
|
'retailcrm',
|
||||||
@ -15,7 +17,8 @@ class ControllerModuleRetailcrm extends Controller {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function uninstall() {
|
public function uninstall()
|
||||||
|
{
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$this->model_setting_setting->editSetting(
|
$this->model_setting_setting->editSetting(
|
||||||
'retailcrm',
|
'retailcrm',
|
||||||
@ -23,7 +26,8 @@ class ControllerModuleRetailcrm extends Controller {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index() {
|
public function index()
|
||||||
|
{
|
||||||
|
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$this->load->model('setting/extension');
|
$this->load->model('setting/extension');
|
||||||
@ -32,10 +36,22 @@ class ControllerModuleRetailcrm extends Controller {
|
|||||||
$this->document->setTitle($this->language->get('heading_title'));
|
$this->document->setTitle($this->language->get('heading_title'));
|
||||||
$this->document->addStyle('/admin/view/stylesheet/retailcrm.css');
|
$this->document->addStyle('/admin/view/stylesheet/retailcrm.css');
|
||||||
|
|
||||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
|
if (
|
||||||
$this->model_setting_setting->editSetting('retailcrm', $this->request->post);
|
$this->request->server['REQUEST_METHOD'] == 'POST'
|
||||||
|
&&
|
||||||
|
$this->validate()
|
||||||
|
) {
|
||||||
|
$this->model_setting_setting
|
||||||
|
->editSetting('retailcrm', $this->request->post);
|
||||||
|
|
||||||
$this->session->data['success'] = $this->language->get('text_success');
|
$this->session->data['success'] = $this->language->get('text_success');
|
||||||
$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
|
|
||||||
|
$this->redirect(
|
||||||
|
$this->url->link(
|
||||||
|
'extension/module',
|
||||||
|
'token=' . $this->session->data['token'], 'SSL'
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$text_strings = array(
|
$text_strings = array(
|
||||||
@ -59,7 +75,8 @@ class ControllerModuleRetailcrm extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->data['retailcrm_errors'] = array();
|
$this->data['retailcrm_errors'] = array();
|
||||||
$this->data['saved_settings'] = $this->model_setting_setting->getSetting('retailcrm');
|
$this->data['saved_settings'] = $this->model_setting_setting
|
||||||
|
->getSetting('retailcrm');
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!empty($this->data['saved_settings']['retailcrm_url'])
|
!empty($this->data['saved_settings']['retailcrm_url'])
|
||||||
@ -72,65 +89,12 @@ class ControllerModuleRetailcrm extends Controller {
|
|||||||
$this->data['saved_settings']['retailcrm_apikey']
|
$this->data['saved_settings']['retailcrm_apikey']
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
$this->data['delivery'] = $this->model_retailcrm_references
|
||||||
* Delivery
|
->getDeliveryTypes();
|
||||||
*/
|
$this->data['statuses'] = $this->model_retailcrm_references
|
||||||
$this->deliveryTypes = array();
|
->getOrderStatuses();
|
||||||
|
$this->data['payments'] = $this->model_retailcrm_references
|
||||||
try {
|
->getPaymentTypes();
|
||||||
$this->deliveryTypes = $this->retailcrm->deliveryTypesList();
|
|
||||||
} catch (CurlException $e) {
|
|
||||||
$this->data['retailcrm_error'][] = $e->getMessage();
|
|
||||||
$this->log->addError('RestApi::deliveryTypesList::Curl:' . $e->getMessage());
|
|
||||||
} catch (InvalidJsonException $e) {
|
|
||||||
$this->data['retailcrm_error'][] = $e->getMessage();
|
|
||||||
$this->log->addError('RestApi::deliveryTypesList::JSON:' . $e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->data['delivery'] = array(
|
|
||||||
'opencart' => $this->model_retailcrm_tools->getOpercartDeliveryMethods(),
|
|
||||||
'retailcrm' => $this->deliveryTypes
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Statuses
|
|
||||||
*/
|
|
||||||
$this->statuses = array();
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->statuses = $this->retailcrm->orderStatusesList();
|
|
||||||
} catch (CurlException $e) {
|
|
||||||
$this->data['retailcrm_error'][] = $e->getMessage();
|
|
||||||
$this->log->addError('RestApi::orderStatusesList::Curl:' . $e->getMessage());
|
|
||||||
} catch (InvalidJsonException $e) {
|
|
||||||
$this->data['retailcrm_error'][] = $e->getMessage();
|
|
||||||
$this->log->addError('RestApi::orderStatusesList::JSON:' . $e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->data['statuses'] = array(
|
|
||||||
'opencart' => $this->model_retailcrm_tools->getOpercartOrderStatuses(),
|
|
||||||
'retailcrm' => $this->statuses
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Payment
|
|
||||||
*/
|
|
||||||
$this->payments = array();
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->payments = $this->retailcrm->paymentTypesList();
|
|
||||||
} catch (CurlException $e) {
|
|
||||||
$this->data['retailcrm_error'][] = $e->getMessage();
|
|
||||||
$this->log->addError('RestApi::paymentTypesList::Curl:' . $e->getMessage());
|
|
||||||
} catch (InvalidJsonException $e) {
|
|
||||||
$this->data['retailcrm_error'][] = $e->getMessage();
|
|
||||||
$this->log->addError('RestApi::paymentTypesList::JSON:' . $e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->data['payments'] = array(
|
|
||||||
'opencart' => $this->model_retailcrm_tools->getOpercartPaymentTypes(),
|
|
||||||
'retailcrm' => $this->payments
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,25 +120,40 @@ class ControllerModuleRetailcrm extends Controller {
|
|||||||
|
|
||||||
$this->data['breadcrumbs'][] = array(
|
$this->data['breadcrumbs'][] = array(
|
||||||
'text' => $this->language->get('text_home'),
|
'text' => $this->language->get('text_home'),
|
||||||
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
|
'href' => $this->url->link(
|
||||||
|
'common/home',
|
||||||
|
'token=' . $this->session->data['token'], 'SSL'
|
||||||
|
),
|
||||||
'separator' => false
|
'separator' => false
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->data['breadcrumbs'][] = array(
|
$this->data['breadcrumbs'][] = array(
|
||||||
'text' => $this->language->get('text_module'),
|
'text' => $this->language->get('text_module'),
|
||||||
'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
|
'href' => $this->url->link(
|
||||||
|
'extension/module',
|
||||||
|
'token=' . $this->session->data['token'], 'SSL'
|
||||||
|
),
|
||||||
'separator' => ' :: '
|
'separator' => ' :: '
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->data['breadcrumbs'][] = array(
|
$this->data['breadcrumbs'][] = array(
|
||||||
'text' => $this->language->get('heading_title'),
|
'text' => $this->language->get('heading_title'),
|
||||||
'href' => $this->url->link('module/retailcrm', 'token=' . $this->session->data['token'], 'SSL'),
|
'href' => $this->url->link(
|
||||||
|
'module/retailcrm',
|
||||||
|
'token=' . $this->session->data['token'], 'SSL'
|
||||||
|
),
|
||||||
'separator' => ' :: '
|
'separator' => ' :: '
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->data['action'] = $this->url->link('module/retailcrm', 'token=' . $this->session->data['token'], 'SSL');
|
$this->data['action'] = $this->url->link(
|
||||||
|
'module/retailcrm',
|
||||||
|
'token=' . $this->session->data['token'], 'SSL'
|
||||||
|
);
|
||||||
|
|
||||||
$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
|
$this->data['cancel'] = $this->url->link(
|
||||||
|
'extension/module',
|
||||||
|
'token=' . $this->session->data['token'], 'SSL'
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
$this->data['modules'] = array();
|
$this->data['modules'] = array();
|
||||||
@ -200,17 +179,28 @@ class ControllerModuleRetailcrm extends Controller {
|
|||||||
|
|
||||||
public function history()
|
public function history()
|
||||||
{
|
{
|
||||||
$this->load->model('retailcrm/history');
|
if (file_exists(DIR_APPLICATION . 'model/retailcrm/custom/history')) {
|
||||||
$this->model_retailcrm_history->request();
|
$this->load->model('retailcrm/custom/history');
|
||||||
|
$this->model_retailcrm_custom_history->request();
|
||||||
|
} else {
|
||||||
|
$this->load->model('retailcrm/history');
|
||||||
|
$this->model_retailcrm_history->request();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function icml()
|
public function icml()
|
||||||
{
|
{
|
||||||
$this->load->model('retailcrm/icml');
|
if (file_exists(DIR_APPLICATION . 'model/retailcrm/custom/icml')) {
|
||||||
$this->model_retailcrm_icml->generateICML();
|
$this->load->model('retailcrm/custom/icml');
|
||||||
|
$this->model_retailcrm_custom_icml->generateICML();
|
||||||
|
} else {
|
||||||
|
$this->load->model('retailcrm/icml');
|
||||||
|
$this->model_retailcrm_icml->generateICML();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validate() {
|
private function validate()
|
||||||
|
{
|
||||||
if (!$this->user->hasPermission('modify', 'module/retailcrm')) {
|
if (!$this->user->hasPermission('modify', 'module/retailcrm')) {
|
||||||
$this->error['warning'] = $this->language->get('error_permission');
|
$this->error['warning'] = $this->language->get('error_permission');
|
||||||
}
|
}
|
||||||
@ -221,6 +211,4 @@ class ControllerModuleRetailcrm extends Controller {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
0
admin/model/retailcrm/custom/.gitkeep
Normal file
0
admin/model/retailcrm/custom/.gitkeep
Normal file
@ -37,11 +37,11 @@ class ModelRetailcrmHistory extends Model
|
|||||||
|
|
||||||
foreach ($orders as $order) {
|
foreach ($orders as $order) {
|
||||||
|
|
||||||
if (!isset($order['deleted']) || !$order['deleted']) {
|
if (empty($order['deleted'])) {
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
|
|
||||||
$customer_id = (isset($order['customer']['externalId']) && $order['customer']['externalId'] != 0)
|
$customer_id = (!empty($order['customer']['externalId']))
|
||||||
? $order['customer']['externalId']
|
? $order['customer']['externalId']
|
||||||
: ''
|
: ''
|
||||||
;
|
;
|
||||||
|
@ -3,7 +3,31 @@
|
|||||||
class ModelRetailcrmReferences extends Model
|
class ModelRetailcrmReferences extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
public function getOpercartDeliveryMethods()
|
public function getDeliveryTypes()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'opencart' => $this->getOpercartDeliveryTypes(),
|
||||||
|
'retailcrm' => $this->getApiDeliveryTypes()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOrderStatuses()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'opencart' => $this->getOpercartOrderStatuses(),
|
||||||
|
'retailcrm' => $this->getApiOrderStatuses()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPaymentTypes()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'opencart' => $this->getOpercartPaymentTypes(),
|
||||||
|
'retailcrm' => $this->getApiPaymentTypes()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getOpercartDeliveryTypes()
|
||||||
{
|
{
|
||||||
$deliveryMethods = array();
|
$deliveryMethods = array();
|
||||||
$files = glob(DIR_APPLICATION . 'controller/shipping/*.php');
|
$files = glob(DIR_APPLICATION . 'controller/shipping/*.php');
|
||||||
@ -25,7 +49,7 @@ class ModelRetailcrmReferences extends Model
|
|||||||
return $deliveryMethods;
|
return $deliveryMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOpercartOrderStatuses()
|
protected function getOpercartOrderStatuses()
|
||||||
{
|
{
|
||||||
$this->load->model('localisation/order_status');
|
$this->load->model('localisation/order_status');
|
||||||
|
|
||||||
@ -33,7 +57,7 @@ class ModelRetailcrmReferences extends Model
|
|||||||
->getOrderStatuses(array());
|
->getOrderStatuses(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOpercartPaymentTypes()
|
protected function getOpercartPaymentTypes()
|
||||||
{
|
{
|
||||||
$paymentTypes = array();
|
$paymentTypes = array();
|
||||||
$files = glob(DIR_APPLICATION . 'controller/payment/*.php');
|
$files = glob(DIR_APPLICATION . 'controller/payment/*.php');
|
||||||
@ -54,4 +78,43 @@ class ModelRetailcrmReferences extends Model
|
|||||||
|
|
||||||
return $paymentTypes;
|
return $paymentTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getApiDeliveryTypes()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->retailcrm->deliveryTypesList();
|
||||||
|
} catch (CurlException $e) {
|
||||||
|
$this->data['retailcrm_error'][] = $e->getMessage();
|
||||||
|
$this->log->addError('RestApi::deliveryTypesList::Curl:' . $e->getMessage());
|
||||||
|
} catch (InvalidJsonException $e) {
|
||||||
|
$this->data['retailcrm_error'][] = $e->getMessage();
|
||||||
|
$this->log->addError('RestApi::deliveryTypesList::JSON:' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getApiOrderStatuses()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->retailcrm->orderStatusesList();
|
||||||
|
} catch (CurlException $e) {
|
||||||
|
$this->data['retailcrm_error'][] = $e->getMessage();
|
||||||
|
$this->log->addError('RestApi::orderStatusesList::Curl:' . $e->getMessage());
|
||||||
|
} catch (InvalidJsonException $e) {
|
||||||
|
$this->data['retailcrm_error'][] = $e->getMessage();
|
||||||
|
$this->log->addError('RestApi::orderStatusesList::JSON:' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getApiPaymentTypes()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->retailcrm->paymentTypesList();
|
||||||
|
} catch (CurlException $e) {
|
||||||
|
$this->data['retailcrm_error'][] = $e->getMessage();
|
||||||
|
$this->log->addError('RestApi::paymentTypesList::Curl:' . $e->getMessage());
|
||||||
|
} catch (InvalidJsonException $e) {
|
||||||
|
$this->data['retailcrm_error'][] = $e->getMessage();
|
||||||
|
$this->log->addError('RestApi::paymentTypesList::JSON:' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class ApiHelper
|
class ApiHelper
|
||||||
{
|
{
|
||||||
private $dir, $fileDate;
|
private $fileDate;
|
||||||
protected $api, $log, $settings;
|
protected $api, $log, $settings;
|
||||||
|
|
||||||
public function __construct($settings) {
|
public function __construct($settings) {
|
||||||
@ -59,7 +59,7 @@ class ApiHelper
|
|||||||
));
|
));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->customer = $this->api->customerEdit($customer);
|
$this->customer = $this->api->customersEdit($customer);
|
||||||
} catch (CurlException $e) {
|
} catch (CurlException $e) {
|
||||||
$this->customer = $e->getMessage();
|
$this->customer = $e->getMessage();
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . $e->getMessage());
|
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . $e->getMessage());
|
||||||
@ -128,7 +128,7 @@ class ApiHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->api->orderEdit($order);
|
$this->api->ordersEdit($order);
|
||||||
} catch (CurlException $e) {
|
} catch (CurlException $e) {
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . $e->getMessage());
|
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . $e->getMessage());
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . json_encode($order));
|
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . json_encode($order));
|
||||||
@ -196,8 +196,6 @@ class ApiHelper
|
|||||||
return $this->api->orderGet($order_id);
|
return $this->api->orderGet($order_id);
|
||||||
} catch (CurlException $e) {
|
} catch (CurlException $e) {
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds:' . $e->getMessage());
|
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds:' . $e->getMessage());
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds:' . json_encode($order));
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} catch (InvalidJsonException $e) {
|
} catch (InvalidJsonException $e) {
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds::Curl:' . $e->getMessage());
|
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds::Curl:' . $e->getMessage());
|
||||||
@ -390,6 +388,7 @@ class ApiResponse implements ArrayAccess
|
|||||||
* Allow to access for the property throw class method
|
* Allow to access for the property throw class method
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
* @param array $arguments
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function __call($name, $arguments)
|
public function __call($name, $arguments)
|
||||||
@ -479,7 +478,7 @@ class ApiClient
|
|||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param string $apiKey
|
* @param string $apiKey
|
||||||
* @param string $siteCode
|
* @param string $site
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function __construct($url, $apiKey, $site = null)
|
public function __construct($url, $apiKey, $site = null)
|
||||||
@ -515,8 +514,9 @@ class ApiClient
|
|||||||
/**
|
/**
|
||||||
* Edit a order
|
* Edit a order
|
||||||
*
|
*
|
||||||
* @param array $order
|
* @param array $order
|
||||||
* @param string $site (default: null)
|
* @param string $by
|
||||||
|
* @param string $site (default: null)
|
||||||
* @return ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function ordersEdit(array $order, $by = 'externalId', $site = null)
|
public function ordersEdit(array $order, $by = 'externalId', $site = null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user