mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-21 20:56:07 +03:00
update v1.x structure, bug fixes
This commit is contained in:
parent
74993334c5
commit
2053b45b88
@ -1,7 +1,7 @@
|
||||
Opencart module
|
||||
===============
|
||||
|
||||
Module allows integrate CMS Opencart with [retailCRM](http://retailcrm.pro)
|
||||
Module allows integrate CMS Opencart 1.5.x.x with [retailCRM](http://retailcrm.pro)
|
||||
|
||||
#### Features:
|
||||
|
||||
@ -24,7 +24,7 @@ cp -r opencart-module/* /path/to/site/root
|
||||
* Specify directories matching
|
||||
|
||||
|
||||
#### Export orders to retailCRM (for opencart 1.5.x, for version 2.x this step is unnecessary)
|
||||
#### Export orders to retailCRM
|
||||
|
||||
##### VQmod
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
Opencart module
|
||||
===============
|
||||
|
||||
Модуль интеграции CMS Openacart c [RetailCRM](http://retailcrm.ru)
|
||||
Модуль интеграции CMS Openacart 1.5.x.x c [RetailCRM](http://retailcrm.ru)
|
||||
|
||||
#### Модуль позволяет:
|
||||
|
||||
@ -27,7 +27,7 @@ cp -r opencart-module/* /path/to/site/root
|
||||
На странице настроек модуля укажите URL Вашей CRM и ключ авторизации, после сохранения этих данных укажите соответствия справочников типов доставок, оплат и статусов заказа.
|
||||
|
||||
|
||||
#### Выгрузка новых заказов в CRM (для версии opencart 1.5.x.x, для версии 2.0 и старше не требуется)
|
||||
#### Выгрузка новых заказов в CRM
|
||||
|
||||
##### VQmod
|
||||
|
||||
|
@ -27,22 +27,6 @@ class ControllerModuleRetailcrm extends Controller
|
||||
$this->load->model('setting/setting');
|
||||
$this->model_setting_setting
|
||||
->editSetting('retailcrm', array('retailcrm_status' => 1));
|
||||
|
||||
$this->load->model('extension/event');
|
||||
|
||||
$this->model_extension_event
|
||||
->addEvent(
|
||||
'retailcrm',
|
||||
version_compare(VERSION, '2.2', '>=') ? 'catalog/model/checkout/order/addOrder/after' : 'post.order.add',
|
||||
'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'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,9 +39,6 @@ class ControllerModuleRetailcrm extends Controller
|
||||
$this->load->model('setting/setting');
|
||||
$this->model_setting_setting
|
||||
->editSetting('retailcrm', array('retailcrm_status' => 0));
|
||||
|
||||
$this->load->model('extension/event');
|
||||
$this->model_extension_event->deleteEvent('retailcrm');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,7 +50,6 @@ class ControllerModuleRetailcrm extends Controller
|
||||
{
|
||||
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->model('extension/module');
|
||||
$this->load->model('retailcrm/references');
|
||||
$this->load->language('module/retailcrm');
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
@ -87,7 +67,7 @@ class ControllerModuleRetailcrm extends Controller
|
||||
'SSL'
|
||||
);
|
||||
|
||||
$this->response->redirect($redirect);
|
||||
$this->redirect($redirect);
|
||||
}
|
||||
|
||||
$text_strings = array(
|
||||
@ -107,8 +87,9 @@ class ControllerModuleRetailcrm extends Controller
|
||||
'retailcrm_dict_payment',
|
||||
);
|
||||
|
||||
$this->load->model('extension/extension');
|
||||
$_data = &$data;
|
||||
|
||||
$_data = &$this->data;
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
foreach ($text_strings as $text) {
|
||||
$_data[$text] = $this->language->get($text);
|
||||
@ -210,13 +191,13 @@ class ControllerModuleRetailcrm extends Controller
|
||||
$this->load->model('design/layout');
|
||||
$_data['layouts'] = $this->model_design_layout->getLayouts();
|
||||
|
||||
$_data['header'] = $this->load->controller('common/header');
|
||||
$_data['column_left'] = $this->load->controller('common/column_left');
|
||||
$_data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput(
|
||||
$this->load->view('module/retailcrm.tpl', $_data)
|
||||
$this->template = 'module/retailcrm.1.x.tpl';
|
||||
$this->children = array(
|
||||
'common/header',
|
||||
'common/footer',
|
||||
);
|
||||
|
||||
$this->response->setOutput($this->render());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,19 +4,12 @@ class ModelRetailcrmHistory extends Model
|
||||
{
|
||||
protected $createResult;
|
||||
|
||||
private $opencartApiClient;
|
||||
|
||||
public function request()
|
||||
{
|
||||
$this->load->model('setting/setting');
|
||||
$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('sale/customer');
|
||||
$this->load->model('retailcrm/references');
|
||||
$this->load->model('catalog/product');
|
||||
$this->load->model('catalog/option');
|
||||
@ -36,8 +29,6 @@ class ModelRetailcrmHistory extends Model
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->opencartApiClient = new OpencartApiClient($this->registry);
|
||||
|
||||
$crm = new RetailcrmProxy(
|
||||
$settings['retailcrm_url'],
|
||||
$settings['retailcrm_apikey'],
|
||||
@ -190,7 +181,8 @@ class ModelRetailcrmHistory extends Model
|
||||
$data['order_product'] = array();
|
||||
|
||||
foreach ($order['items'] as $item) {
|
||||
//$product = $this->model_catalog_product->getProduct($item['offer']['externalId']);
|
||||
$product = $this->model_catalog_product->getProduct($item['offer']['externalId']);
|
||||
|
||||
$productId = $item['offer']['externalId'];
|
||||
$options = array();
|
||||
if(mb_strpos($item['offer']['externalId'], '#') > 1) {
|
||||
@ -201,25 +193,44 @@ class ModelRetailcrmHistory extends Model
|
||||
foreach($optionsFromCRM as $optionFromCRM) {
|
||||
$optionData = explode('-', $optionFromCRM);
|
||||
$productOptionId = $optionData[0];
|
||||
$optionValueId = $optionData[1];
|
||||
$productOptionValueId = $optionData[1];
|
||||
|
||||
$productOptions = $this->model_catalog_product->getProductOptions($productId);
|
||||
|
||||
foreach($productOptions as $productOption) {
|
||||
if($productOptionId == $productOption['product_option_id']) {
|
||||
if($productOption['product_option_id'] == $productOptionId) {
|
||||
foreach($productOption['product_option_value'] as $productOptionValue) {
|
||||
if($productOptionValue['option_value_id'] == $optionValueId) {
|
||||
$options[$productOptionId] = $productOptionValue['product_option_value_id'];
|
||||
if($productOptionValue['option_value_id'] == $productOptionValueId) {
|
||||
$productOptionValue = $this->model_catalog_option->getOptionValue($productOptionValueId);
|
||||
|
||||
$options[] = array(
|
||||
'order_option_id' => 'default', // default или NULL для автоинкремента http://stackoverflow.com/questions/8753371/how-to-insert-data-to-mysql-having-auto-incremented-primary-key
|
||||
'product_option_id' => $productOptionId,
|
||||
'product_option_value_id' => $productOptionValueId,
|
||||
'name' => $productOption['name'],
|
||||
'value' => $productOptionValue['name'],
|
||||
'type' => $productOption['type']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['order_product'][] = array(
|
||||
'product_id' => $productId,
|
||||
'name' => $item['offer']['name'],
|
||||
'quantity' => $item['quantity'],
|
||||
'option' => $options
|
||||
'price' => $item['initialPrice'],
|
||||
'total' => $item['initialPrice'] * $item['quantity'],
|
||||
'model' => $product['model'],
|
||||
'order_option' => $options,
|
||||
|
||||
// this data will not retrive from crm
|
||||
'order_product_id' => '',
|
||||
'tax' => 0,
|
||||
'reward' => 0
|
||||
);
|
||||
}
|
||||
|
||||
@ -261,7 +272,7 @@ class ModelRetailcrmHistory extends Model
|
||||
$data['order_status_id'] = $tmpOrder['order_status_id'];
|
||||
}
|
||||
|
||||
$this->opencartApiClient->editOrder($order['externalId'], $data);
|
||||
$this->model_sale_order->editOrder($order['externalId'], $data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,25 +319,13 @@ class ModelRetailcrmHistory extends Model
|
||||
),
|
||||
);
|
||||
|
||||
if (version_compare(VERSION, '2.1.0.0', '>=')) {
|
||||
$this->model_customer_customer->addCustomer($cData);
|
||||
} else {
|
||||
$this->model_sale_customer->addCustomer($cData);
|
||||
}
|
||||
$this->model_sale_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_sale_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_sale_customer->getCustomers($data = array('order' => 'DESC', 'limit' => 1));
|
||||
$customer_id = $last[0]['customer_id'];
|
||||
}
|
||||
|
||||
@ -452,7 +451,7 @@ class ModelRetailcrmHistory extends Model
|
||||
$data['fromApi'] = true;
|
||||
$data['order_status_id'] = 1;
|
||||
|
||||
$this->opencartApiClient->addOrder($data);
|
||||
$this->model_sale_order->addOrder($data);
|
||||
|
||||
$last = $this->model_sale_order->getOrders($data = array('order' => 'DESC', 'limit' => 1, 'start' => 0));
|
||||
|
||||
|
@ -18,8 +18,8 @@ class ModelRetailcrmIcml extends Model
|
||||
$this->load->language('module/retailcrm');
|
||||
$this->load->model('catalog/category');
|
||||
$this->load->model('catalog/product');
|
||||
$this->load->model('catalog/option');
|
||||
$this->load->model('catalog/manufacturer');
|
||||
$this->load->model('catalog/option');
|
||||
|
||||
$string = '<?xml version="1.0" encoding="UTF-8"?>
|
||||
<yml_catalog date="'.date('Y-m-d H:i:s').'">
|
||||
@ -102,9 +102,12 @@ class ModelRetailcrmIcml extends Model
|
||||
foreach ($products as $product) {
|
||||
// Формируем офферы отнсительно доступных опций
|
||||
$options = $this->model_catalog_product->getProductOptions($product['product_id']);
|
||||
|
||||
$offerOptions = array('select', 'radio');
|
||||
|
||||
$requiredOptions = array();
|
||||
$notRequiredOptions = array();
|
||||
|
||||
// Оставляем опции связанные с вариациями товаров, сортируем по параметру обязательный или нет
|
||||
foreach($options as $option) {
|
||||
if(in_array($option['type'], $offerOptions)) {
|
||||
@ -115,7 +118,9 @@ class ModelRetailcrmIcml extends Model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$offers = array();
|
||||
|
||||
// Сначала совмещаем все обязательные опции
|
||||
foreach($requiredOptions as $requiredOption) {
|
||||
// Если первая итерация
|
||||
@ -132,6 +137,7 @@ class ModelRetailcrmIcml extends Model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Совмещаем или добавляем необязательные опции, учитывая тот факт что обязательных опций может и не быть.
|
||||
foreach($notRequiredOptions as $notRequiredOption) {
|
||||
// Если обязательных опцией не оказалось и первая итерация
|
||||
@ -148,6 +154,7 @@ class ModelRetailcrmIcml extends Model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($offers)) {
|
||||
$offers = array('0:0-0' => '0');
|
||||
}
|
||||
@ -158,21 +165,26 @@ class ModelRetailcrmIcml extends Model
|
||||
foreach($optionsString as $optionString) {
|
||||
$option = explode('-', $optionString);
|
||||
$optionIds = explode(':', $option[0]);
|
||||
|
||||
if($optionString != '0:0-0') {
|
||||
$optionData = $this->getOptionData($optionIds[1], $option[1]);
|
||||
|
||||
$options[$optionIds[0]] = array(
|
||||
'name' => $optionData['optionName'],
|
||||
'value' => $optionData['optionValue'],
|
||||
'value_id' => $option[1]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
ksort($options);
|
||||
|
||||
$offerId = array();
|
||||
foreach($options as $optionKey => $optionData) {
|
||||
$offerId[] = $optionKey.'-'.$optionData['value_id'];
|
||||
}
|
||||
$offerId = implode('_', $offerId);
|
||||
|
||||
$e = $this->eOffers->appendChild($this->dd->createElement('offer'));
|
||||
if(!empty($offerId))
|
||||
$e->setAttribute('id', $product['product_id'].'#'.$offerId);
|
||||
@ -180,6 +192,7 @@ class ModelRetailcrmIcml extends Model
|
||||
$e->setAttribute('id', $product['product_id']);
|
||||
$e->setAttribute('productId', $product['product_id']);
|
||||
$e->setAttribute('quantity', $product['quantity']);
|
||||
|
||||
/**
|
||||
* Offer activity
|
||||
*/
|
||||
@ -189,11 +202,13 @@ class ModelRetailcrmIcml extends Model
|
||||
)->appendChild(
|
||||
$this->dd->createTextNode($activity)
|
||||
);
|
||||
|
||||
/**
|
||||
* Offer categories
|
||||
*/
|
||||
$categories = $this->model_catalog_product
|
||||
->getProductCategories($product['product_id']);
|
||||
|
||||
if (!empty($categories)) {
|
||||
foreach ($categories as $category) {
|
||||
$e->appendChild($this->dd->createElement('categoryId'))
|
||||
@ -202,6 +217,7 @@ class ModelRetailcrmIcml extends Model
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Name & price
|
||||
*/
|
||||
@ -213,14 +229,17 @@ class ModelRetailcrmIcml extends Model
|
||||
$optionsString[] = $option['name'].': '.$option['value'];
|
||||
}
|
||||
$optionsString = ' ('.implode(', ', $optionsString).')';
|
||||
|
||||
$e->appendChild($this->dd->createElement('name'))
|
||||
->appendChild($this->dd->createTextNode($product['name'].$optionsString));
|
||||
} else {
|
||||
$e->appendChild($this->dd->createElement('name'))
|
||||
->appendChild($this->dd->createTextNode($product['name']));
|
||||
}
|
||||
|
||||
$e->appendChild($this->dd->createElement('price'))
|
||||
->appendChild($this->dd->createTextNode($product['price'] + $optionsTotalCost));
|
||||
|
||||
/**
|
||||
* Vendor
|
||||
*/
|
||||
@ -232,6 +251,7 @@ class ModelRetailcrmIcml extends Model
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Image
|
||||
*/
|
||||
@ -240,6 +260,7 @@ class ModelRetailcrmIcml extends Model
|
||||
$e->appendChild($this->dd->createElement('picture'))
|
||||
->appendChild($this->dd->createTextNode($image));
|
||||
}
|
||||
|
||||
/**
|
||||
* Url
|
||||
*/
|
||||
@ -249,6 +270,7 @@ class ModelRetailcrmIcml extends Model
|
||||
? HTTP_CATALOG
|
||||
: HTTPS_CATALOG
|
||||
);
|
||||
|
||||
$e->appendChild($this->dd->createElement('url'))
|
||||
->appendChild(
|
||||
$this->dd->createTextNode(
|
||||
@ -257,6 +279,7 @@ class ModelRetailcrmIcml extends Model
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Options
|
||||
if(!empty($options)) {
|
||||
foreach($options as $optionKey => $optionData) {
|
||||
@ -267,6 +290,8 @@ class ModelRetailcrmIcml extends Model
|
||||
$e->appendChild($param);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($product['sku']) {
|
||||
$sku = $this->dd->createElement('param');
|
||||
$sku->setAttribute('code', 'article');
|
||||
@ -274,6 +299,7 @@ class ModelRetailcrmIcml extends Model
|
||||
$sku->appendChild($this->dd->createTextNode($product['sku']));
|
||||
$e->appendChild($sku);
|
||||
}
|
||||
|
||||
if ($product['weight'] != '') {
|
||||
$weight = $this->dd->createElement('param');
|
||||
$weight->setAttribute('code', 'weight');
|
||||
@ -297,18 +323,6 @@ class ModelRetailcrmIcml extends Model
|
||||
{
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (version_compare(VERSION, '2.2', '>=')) {
|
||||
$currentTheme = $this->config->get('config_theme');
|
||||
$width = $this->config->get($currentTheme . '_image_related_width') ? $this->config->get($currentTheme . '_image_related_width') : 200;
|
||||
$height = $this->config->get($currentTheme . '_image_related_height') ? $this->config->get($currentTheme . '_image_related_height') : 200;
|
||||
|
||||
return $this->model_tool_image->resize(
|
||||
$image,
|
||||
$width,
|
||||
$height
|
||||
);
|
||||
}
|
||||
|
||||
return $this->model_tool_image->resize(
|
||||
$image,
|
||||
$this->config->get('config_image_product_width'),
|
||||
@ -323,12 +337,14 @@ class ModelRetailcrmIcml extends Model
|
||||
$option = $this->model_catalog_option->getOption($optionId);
|
||||
$this->options[$optionId] = $option;
|
||||
}
|
||||
|
||||
if(!empty($this->optionValues[$optionValueId])) {
|
||||
$optionValue = $this->optionValues[$optionValueId];
|
||||
} else {
|
||||
$optionValue = $this->model_catalog_option->getOptionValue($optionValueId);
|
||||
$this->optionValues[$optionValueId] = $optionValue;
|
||||
}
|
||||
|
||||
return array(
|
||||
'optionName' => $option['name'],
|
||||
'optionValue' => $optionValue['name']
|
||||
|
@ -77,10 +77,30 @@ class ModelRetailcrmOrder extends Model {
|
||||
);
|
||||
|
||||
$orderProducts = isset($order_data['products']) ? $order_data['products'] : $order_data['order_product'];
|
||||
$offerOptions = array('select', 'radio');
|
||||
|
||||
foreach ($orderProducts as $product) {
|
||||
$offerId = '';
|
||||
if(!empty($product['option'])) {
|
||||
$options = array();
|
||||
|
||||
foreach($product['option'] as $option) {
|
||||
if(!in_array($option['type'], $offerOptions)) continue;
|
||||
$options[$option['product_option_id']] = $option['option_value_id'];
|
||||
}
|
||||
|
||||
ksort($options);
|
||||
|
||||
$offerId = array();
|
||||
foreach($options as $optionKey => $optionValue) {
|
||||
$offerId[] = $optionKey.'-'.$optionValue;
|
||||
}
|
||||
$offerId = implode('_', $offerId);
|
||||
}
|
||||
|
||||
|
||||
$order['items'][] = array(
|
||||
'productId' => $product['product_id'],
|
||||
'productId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id'],
|
||||
'productName' => $product['name'],
|
||||
'initialPrice' => $product['price'],
|
||||
'quantity' => $product['quantity'],
|
||||
@ -95,6 +115,10 @@ class ModelRetailcrmOrder extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $order_data
|
||||
* @param $order_id
|
||||
*/
|
||||
public function changeInCrm($order_data, $order_id)
|
||||
{
|
||||
$this->load->model('setting/setting');
|
||||
@ -136,9 +160,7 @@ class ModelRetailcrmOrder extends Model {
|
||||
$country = (isset($order_data['shipping_country'])) ? $order_data['shipping_country'] : '' ;
|
||||
|
||||
$order['delivery'] = array(
|
||||
'code' => !empty($settings['retailcrm_delivery'][$delivery_code])
|
||||
? $settings['retailcrm_delivery'][$delivery_code]
|
||||
: null,
|
||||
'code' => $settings['retailcrm_delivery'][$delivery_code],
|
||||
'cost' => $deliveryCost,
|
||||
'address' => array(
|
||||
'index' => $order_data['shipping_postcode'],
|
||||
@ -156,16 +178,46 @@ class ModelRetailcrmOrder extends Model {
|
||||
);
|
||||
|
||||
$orderProducts = isset($order_data['products']) ? $order_data['products'] : $order_data['order_product'];
|
||||
$offerOptions = array('select', 'radio');
|
||||
|
||||
foreach ($orderProducts as $product) {
|
||||
if(!empty($product['order_option'])) {
|
||||
$options = array();
|
||||
|
||||
$productOptions = $this->model_catalog_product->getProductOptions($product['product_id']);
|
||||
foreach($productOptions as $key=>$productOption) {
|
||||
$productOptionValues[$productOption['product_option_id']] = array();
|
||||
|
||||
foreach($productOption['product_option_value'] as $productOptionValue) {
|
||||
$productOptionValues[$productOption['product_option_id']][$productOptionValue['product_option_value_id']] = $productOptionValue['option_value_id'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach($product['order_option'] as $option) {
|
||||
if(!in_array($option['type'], $offerOptions)) continue;
|
||||
$options[$option['product_option_id']] = $productOptionValues[$option['product_option_id']][$option['product_option_value_id']];
|
||||
}
|
||||
|
||||
ksort($options);
|
||||
|
||||
$offerId = array();
|
||||
foreach($options as $optionKey => $optionValue) {
|
||||
$offerId[] = $optionKey.'-'.$optionValue;
|
||||
}
|
||||
$offerId = implode('_', $offerId);
|
||||
}
|
||||
|
||||
$order['items'][] = array(
|
||||
'productId' => $product['product_id'],
|
||||
'productId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id'],
|
||||
'productName' => $product['name'],
|
||||
'initialPrice' => $product['price'],
|
||||
'quantity' => $product['quantity'],
|
||||
);
|
||||
}
|
||||
|
||||
// Сделаем порядок товраных позиций в срм как и в магазине
|
||||
$order['items'] = array_reverse($order['items']);
|
||||
|
||||
if (isset($order_data['order_status_id']) && $order_data['order_status_id'] > 0) {
|
||||
$order['status'] = $settings['retailcrm_status'][$order_data['order_status_id']];
|
||||
}
|
||||
|
99
admin/view/template/module/retailcrm.1.x.tpl
Normal file
99
admin/view/template/module/retailcrm.1.x.tpl
Normal file
@ -0,0 +1,99 @@
|
||||
<?php echo $header; ?>
|
||||
|
||||
<div id="content">
|
||||
<div class="breadcrumb">
|
||||
<?php foreach ($breadcrumbs as $breadcrumb): ?>
|
||||
<?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php if ($error_warning) : ?>
|
||||
<div class="warning"><?php echo $error_warning; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($saved_settings['retailcrm_url'])): ?>
|
||||
<div class="success">
|
||||
<?php echo $text_notice; ?>
|
||||
<a href="<?php echo $saved_settings['retailcrm_url']; ?>/admin/settings#t-main"><?php echo $saved_settings['retailcrm_url']; ?>/admin/settings#t-main</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="box">
|
||||
<div class="heading">
|
||||
<h1><img src="view/image/module.png" alt="" /> <?php echo $heading_title; ?></h1>
|
||||
<div class="buttons"><a onclick="$('#form').submit();" class="button"><span><?php echo $button_save; ?></span></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><span><?php echo $button_cancel; ?></span></a></div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
|
||||
<input type="hidden" name="retailcrm_status" value="1">
|
||||
|
||||
<h3><?php echo $retailcrm_base_settings; ?></h3>
|
||||
<div class="retailcrm_unit">
|
||||
<label for="retailcrm_url"><?php echo $retailcrm_url; ?></label><br>
|
||||
<input id="retailcrm_url" type="text" name="retailcrm_url" value="<?php if (isset($saved_settings['retailcrm_url'])): echo $saved_settings['retailcrm_url']; endif; ?>">
|
||||
</div>
|
||||
<div class="retailcrm_unit">
|
||||
<label for="retailcrm_apikey"><?php echo $retailcrm_apikey; ?></label><br>
|
||||
<input id="retailcrm_apikey" type="text" name="retailcrm_apikey" value="<?php if (isset($saved_settings['retailcrm_apikey'])): echo $saved_settings['retailcrm_apikey']; endif;?>">
|
||||
</div>
|
||||
|
||||
<?php if (isset($saved_settings['retailcrm_apikey']) && $saved_settings['retailcrm_apikey'] != '' && isset($saved_settings['retailcrm_url']) && $saved_settings['retailcrm_url'] != ''): ?>
|
||||
|
||||
<?php if (!empty($retailcrm_errors)) : ?>
|
||||
<?php foreach($retailcrm_errors as $retailcrm_error): ?>
|
||||
<div class="warning"><?php echo $retailcrm_error ?></div>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<h3><?php echo $retailcrm_dict_settings; ?></h3>
|
||||
|
||||
<h4><?php echo $retailcrm_dict_delivery; ?></h4>
|
||||
<?php foreach ($delivery['opencart'] as $key => $value): ?>
|
||||
<div class="retailcrm_unit">
|
||||
<select id="retailcrm_delivery_<?php echo $key; ?>" name="retailcrm_delivery[<?php echo $key; ?>]" >
|
||||
<?php foreach ($delivery['retailcrm'] as $k => $v): ?>
|
||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_delivery'][$key]) && $v['code'] == $saved_settings['retailcrm_delivery'][$key]):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v['name'];?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<label for="retailcrm_delivery_<?php echo $key; ?>"><?php echo $value; ?></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<h4><?php echo $retailcrm_dict_status; ?></h4>
|
||||
<?php foreach ($statuses['opencart'] as $status): ?>
|
||||
<?php $uid = $status['order_status_id']?>
|
||||
<div class="retailcrm_unit">
|
||||
<select id="retailcrm_status_<?php echo $uid; ?>" name="retailcrm_status[<?php echo $uid; ?>]" >
|
||||
<?php foreach ($statuses['retailcrm'] as $k => $v): ?>
|
||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_status'][$uid]) && $v['code'] == $saved_settings['retailcrm_status'][$uid]):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v['name'];?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<label for="retailcrm_status_<?php echo $status['order_status_id']; ?>"><?php echo $status['name']; ?></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<h4><?php echo $retailcrm_dict_payment; ?></h4>
|
||||
<?php foreach ($payments['opencart'] as $key => $value): ?>
|
||||
<div class="retailcrm_unit">
|
||||
<select id="retailcrm_payment_<?php echo $key; ?>" name="retailcrm_payment[<?php echo $key; ?>]" >
|
||||
<?php foreach ($payments['retailcrm'] as $k => $v): ?>
|
||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_payment'][$key]) && $v['code'] == $saved_settings['retailcrm_payment'][$key]):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v['name'];?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<label for="retailcrm_payment_<?php echo $key; ?>"><?php echo $value; ?></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<?php echo $footer; ?>
|
@ -1,110 +0,0 @@
|
||||
<?php echo $header; ?>
|
||||
<?php echo $column_left;?>
|
||||
|
||||
<div id="content">
|
||||
<div class="page-header">
|
||||
<div class="container-fluid">
|
||||
<div class="pull-right">
|
||||
<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>
|
||||
<ul class="breadcrumb">
|
||||
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
|
||||
<li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-fluid">
|
||||
<?php if ($error_warning) : ?>
|
||||
<div class="alert alert-danger">
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($saved_settings['retailcrm_url'])): ?>
|
||||
<div class="alert alert-info"><i class="fa fa-exclamation-circle"></i>
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<?php echo $text_notice; ?>
|
||||
<a href="<?php echo $saved_settings['retailcrm_url']; ?>/admin/settings#t-main"><?php echo $saved_settings['retailcrm_url']; ?>/admin/settings#t-main</a>
|
||||
</div>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-retailcrm">
|
||||
<input type="hidden" name="retailcrm_status" value="1">
|
||||
|
||||
<h3><?php echo $retailcrm_base_settings; ?></h3>
|
||||
<div class="retailcrm_unit">
|
||||
<label for="retailcrm_url"><?php echo $retailcrm_url; ?></label><br>
|
||||
<input id="retailcrm_url" type="text" name="retailcrm_url" value="<?php if (isset($saved_settings['retailcrm_url'])): echo $saved_settings['retailcrm_url']; endif; ?>">
|
||||
</div>
|
||||
<div class="retailcrm_unit">
|
||||
<label for="retailcrm_apikey"><?php echo $retailcrm_apikey; ?></label><br>
|
||||
<input id="retailcrm_apikey" type="text" name="retailcrm_apikey" value="<?php if (isset($saved_settings['retailcrm_apikey'])): echo $saved_settings['retailcrm_apikey']; endif;?>">
|
||||
</div>
|
||||
|
||||
<?php if (isset($saved_settings['retailcrm_apikey']) && $saved_settings['retailcrm_apikey'] != '' && isset($saved_settings['retailcrm_url']) && $saved_settings['retailcrm_url'] != ''): ?>
|
||||
|
||||
<?php if (!empty($retailcrm_errors)) : ?>
|
||||
<?php foreach($retailcrm_errors as $retailcrm_error): ?>
|
||||
<div class="warning"><?php echo $retailcrm_error ?></div>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<h3><?php echo $retailcrm_dict_settings; ?></h3>
|
||||
|
||||
<h4><?php echo $retailcrm_dict_delivery; ?></h4>
|
||||
<?php foreach ($delivery['opencart'] as $key => $value): ?>
|
||||
<div class="retailcrm_unit">
|
||||
<select id="retailcrm_delivery_<?php echo $key; ?>" name="retailcrm_delivery[<?php echo $key; ?>]" >
|
||||
<?php foreach ($delivery['retailcrm'] as $k => $v): ?>
|
||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_delivery'][$key]) && $v['code'] == $saved_settings['retailcrm_delivery'][$key]):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v['name'];?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<label for="retailcrm_delivery_<?php echo $key; ?>"><?php echo $value; ?></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<h4><?php echo $retailcrm_dict_status; ?></h4>
|
||||
<?php foreach ($statuses['opencart'] as $status): ?>
|
||||
<?php $uid = $status['order_status_id']?>
|
||||
<div class="retailcrm_unit">
|
||||
<select id="retailcrm_status_<?php echo $uid; ?>" name="retailcrm_status[<?php echo $uid; ?>]" >
|
||||
<?php foreach ($statuses['retailcrm'] as $k => $v): ?>
|
||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_status'][$uid]) && $v['code'] == $saved_settings['retailcrm_status'][$uid]):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v['name'];?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<label for="retailcrm_status_<?php echo $status['order_status_id']; ?>"><?php echo $status['name']; ?></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<h4><?php echo $retailcrm_dict_payment; ?></h4>
|
||||
<?php foreach ($payments['opencart'] as $key => $value): ?>
|
||||
<div class="retailcrm_unit">
|
||||
<select id="retailcrm_payment_<?php echo $key; ?>" name="retailcrm_payment[<?php echo $key; ?>]" >
|
||||
<?php foreach ($payments['retailcrm'] as $k => $v): ?>
|
||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_payment'][$key]) && $v['code'] == $saved_settings['retailcrm_payment'][$key]):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v['name'];?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<label for="retailcrm_payment_<?php echo $key; ?>"><?php echo $value; ?></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php echo $footer; ?>
|
@ -18,25 +18,13 @@ class ControllerModuleRetailcrm extends Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function order_create($parameter1, $parameter2 = null)
|
||||
public function order_create($order_id)
|
||||
{
|
||||
$this->load->model('checkout/order');
|
||||
$this->load->model('account/order');
|
||||
|
||||
if($parameter2 != null)
|
||||
$order_id = $parameter2;
|
||||
else
|
||||
$order_id = $parameter1;
|
||||
|
||||
$data = $this->model_checkout_order->getOrder($order_id);
|
||||
|
||||
$data['products'] = $this->model_account_order->getOrderProducts($order_id);
|
||||
foreach($data['products'] as $key => $product) {
|
||||
$productOptions = $this->model_account_order->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if(!empty($productOptions))
|
||||
$data['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
|
||||
if (!isset($data['fromApi'])) {
|
||||
$this->load->model('setting/setting');
|
||||
@ -55,12 +43,7 @@ class ControllerModuleRetailcrm extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function order_edit($parameter1, $parameter2 = null, $parameter3 = null, $parameter4 = null) {
|
||||
if($parameter4 != null)
|
||||
$order_id = $parameter3;
|
||||
else
|
||||
$order_id = $parameter1;
|
||||
|
||||
public function order_edit($order_id) {
|
||||
$this->load->model('checkout/order');
|
||||
$this->load->model('account/order');
|
||||
|
||||
@ -70,13 +53,6 @@ class ControllerModuleRetailcrm extends Controller
|
||||
|
||||
$data['products'] = $this->model_account_order->getOrderProducts($order_id);
|
||||
|
||||
foreach($data['products'] as $key => $product) {
|
||||
$productOptions = $this->model_account_order->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if(!empty($productOptions))
|
||||
$data['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
|
||||
if (!isset($data['fromApi'])) {
|
||||
$this->load->model('setting/setting');
|
||||
$status = $this->model_setting_setting->getSetting('retailcrm');
|
||||
|
@ -10,8 +10,6 @@ class ModelRetailcrmOrder extends Model {
|
||||
$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(
|
||||
@ -93,23 +91,12 @@ class ModelRetailcrmOrder extends Model {
|
||||
|
||||
foreach ($orderProducts as $product) {
|
||||
$offerId = '';
|
||||
|
||||
if(!empty($product['option'])) {
|
||||
$options = array();
|
||||
|
||||
$productOptions = $this->model_catalog_product->getProductOptions($product['product_id']);
|
||||
|
||||
foreach($product['option'] as $option) {
|
||||
if(!in_array($option['type'], $offerOptions)) continue;
|
||||
foreach($productOptions as $productOption) {
|
||||
if($productOption['product_option_id'] = $option['product_option_id']) {
|
||||
foreach($productOption['product_option_value'] as $productOptionValue) {
|
||||
if($productOptionValue['product_option_value_id'] == $option['product_option_value_id']) {
|
||||
$options[$option['product_option_id']] = $productOptionValue['option_value_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$options[$option['product_option_id']] = $option['option_value_id'];
|
||||
}
|
||||
|
||||
ksort($options);
|
||||
@ -121,6 +108,7 @@ class ModelRetailcrmOrder extends Model {
|
||||
$offerId = implode('_', $offerId);
|
||||
}
|
||||
|
||||
|
||||
$order['items'][] = array(
|
||||
'productId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id'],
|
||||
'productName' => $product['name'],
|
||||
@ -145,8 +133,6 @@ class ModelRetailcrmOrder extends Model {
|
||||
$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(
|
||||
@ -204,23 +190,12 @@ class ModelRetailcrmOrder extends Model {
|
||||
|
||||
foreach ($orderProducts as $product) {
|
||||
$offerId = '';
|
||||
|
||||
if(!empty($product['option'])) {
|
||||
$options = array();
|
||||
|
||||
$productOptions = $this->model_catalog_product->getProductOptions($product['product_id']);
|
||||
|
||||
foreach($product['option'] as $option) {
|
||||
if(!in_array($option['type'], $offerOptions)) continue;
|
||||
foreach($productOptions as $productOption) {
|
||||
if($productOption['product_option_id'] = $option['product_option_id']) {
|
||||
foreach($productOption['product_option_value'] as $productOptionValue) {
|
||||
if($productOptionValue['product_option_value_id'] == $option['product_option_value_id']) {
|
||||
$options[$option['product_option_id']] = $productOptionValue['option_value_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$options[$option['product_option_id']] = $option['option_value_id'];
|
||||
}
|
||||
|
||||
ksort($options);
|
||||
@ -232,6 +207,7 @@ class ModelRetailcrmOrder extends Model {
|
||||
$offerId = implode('_', $offerId);
|
||||
}
|
||||
|
||||
|
||||
$order['items'][] = array(
|
||||
'productId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id'],
|
||||
'productName' => $product['name'],
|
||||
|
@ -34,17 +34,10 @@ if (!defined('DIR_APPLICATION')) {
|
||||
require_once(DIR_SYSTEM . 'startup.php');
|
||||
|
||||
// Application Classes
|
||||
if (version_compare(VERSION, '2.2', '>=')) {
|
||||
require_once(DIR_SYSTEM . 'library/cart/currency.php');
|
||||
require_once(DIR_SYSTEM . 'library/cart/user.php');
|
||||
require_once(DIR_SYSTEM . 'library/cart/weight.php');
|
||||
require_once(DIR_SYSTEM . 'library/cart/length.php');
|
||||
} else {
|
||||
require_once(DIR_SYSTEM . 'library/currency.php');
|
||||
require_once(DIR_SYSTEM . 'library/user.php');
|
||||
require_once(DIR_SYSTEM . 'library/weight.php');
|
||||
require_once(DIR_SYSTEM . 'library/length.php');
|
||||
}
|
||||
require_once(DIR_SYSTEM . 'library/currency.php');
|
||||
require_once(DIR_SYSTEM . 'library/user.php');
|
||||
require_once(DIR_SYSTEM . 'library/weight.php');
|
||||
require_once(DIR_SYSTEM . 'library/length.php');
|
||||
|
||||
// Registry
|
||||
$registry = new Registry();
|
||||
@ -68,10 +61,7 @@ foreach ($query->rows as $setting) {
|
||||
if (!$setting['serialized']) {
|
||||
$config->set($setting['key'], $setting['value']);
|
||||
} else {
|
||||
if (version_compare(VERSION, '2.1', '>='))
|
||||
$config->set($setting['key'], json_decode($setting['value']), true);
|
||||
else
|
||||
$config->set($setting['key'], unserialize($setting['value']));
|
||||
$config->set($setting['key'], unserialize($setting['value']));
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,13 +73,6 @@ $registry->set('url', $url);
|
||||
$log = new Log($config->get('config_error_filename'));
|
||||
$registry->set('log', $log);
|
||||
|
||||
|
||||
// Event
|
||||
if (version_compare(VERSION, '2.2', '>=')) {
|
||||
$event = new Event($registry);
|
||||
$registry->set('event', $event);
|
||||
}
|
||||
|
||||
function error_handler($errno, $errstr, $errfile, $errline) {
|
||||
global $log, $config;
|
||||
|
||||
@ -153,17 +136,10 @@ $registry->set('language', $language);
|
||||
$document = new Document();
|
||||
$registry->set('document', $document);
|
||||
|
||||
if (version_compare(VERSION, '2.2', '>=')) {
|
||||
$registry->set('currency', new Cart\Currency($registry));
|
||||
$registry->set('weight', new Cart\Weight($registry));
|
||||
$registry->set('length', new Cart\Length($registry));
|
||||
$registry->set('user', new Cart\User($registry));
|
||||
} else {
|
||||
$registry->set('currency', new Currency($registry));
|
||||
$registry->set('weight', new Weight($registry));
|
||||
$registry->set('length', new Length($registry));
|
||||
$registry->set('user', new User($registry));
|
||||
}
|
||||
$registry->set('currency', new Currency($registry));
|
||||
$registry->set('weight', new Weight($registry));
|
||||
$registry->set('length', new Length($registry));
|
||||
$registry->set('user', new User($registry));
|
||||
|
||||
$controller = new Front($registry);
|
||||
$action = new Action($cli_action);
|
||||
|
@ -1,2 +0,0 @@
|
||||
<?php
|
||||
echo $_SERVER['REMOTE_ADDR'];
|
@ -1,317 +0,0 @@
|
||||
<?php
|
||||
|
||||
class OpencartApiClient {
|
||||
|
||||
private $opencartStoreId = 0;
|
||||
private $cookieFileName;
|
||||
private $registry;
|
||||
private $apiToken;
|
||||
|
||||
/* Совместимость с объектами ОС, например $this->model_module_name */
|
||||
public function __get($name) {
|
||||
return $this->registry->get($name);
|
||||
}
|
||||
|
||||
public function __construct(Registry &$registry) {
|
||||
$this->registry = $registry;
|
||||
|
||||
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
||||
$this->cookieFileName = $settings['retailcrm_apikey'];
|
||||
|
||||
$this->auth();
|
||||
}
|
||||
|
||||
private function getCookieValue($cookieName) {
|
||||
$cookieFile = file_get_contents(DIR_APPLICATION . '/' . $this->cookieFileName . '.txt');
|
||||
$cookieFile = explode("\n", $cookieFile);
|
||||
|
||||
$cookies = array();
|
||||
foreach($cookieFile as $line) {
|
||||
if(empty($line) OR $line{0} == '#')
|
||||
continue;
|
||||
|
||||
$params = explode("\t", $line);
|
||||
$cookies[$params[5]] = $params[6];
|
||||
}
|
||||
|
||||
if(isset($cookies[$cookieName]))
|
||||
return $cookies[$cookieName];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function request($method, $getParams, $postParams) {
|
||||
$opencartStoreInfo = $this->model_setting_store->getStore($this->opencartStoreId);
|
||||
|
||||
if(version_compare(VERSION, '2.1.0', '>=') && !empty($this->apiToken)) {
|
||||
$getParams['token'] = $this->apiToken;
|
||||
}
|
||||
|
||||
$postParams['fromApi'] = true;
|
||||
|
||||
if ($opencartStoreInfo) {
|
||||
$url = $opencartStoreInfo['ssl'];
|
||||
} else {
|
||||
$url = HTTPS_CATALOG;
|
||||
}
|
||||
|
||||
$curl = curl_init();
|
||||
|
||||
// Set SSL if required
|
||||
if (substr($url, 0, 5) == 'https') {
|
||||
curl_setopt($curl, CURLOPT_PORT, 443);
|
||||
}
|
||||
|
||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
||||
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_FORBID_REUSE, false);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_URL, $url . 'index.php?route=api/' . $method . (!empty($getParams) ? '&' . http_build_query($getParams) : ''));
|
||||
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postParams));
|
||||
|
||||
curl_setopt($curl, CURLOPT_COOKIEFILE, DIR_APPLICATION . '/' . $this->cookieFileName . '.txt');
|
||||
curl_setopt($curl, CURLOPT_COOKIEJAR, DIR_APPLICATION . '/' . $this->cookieFileName . '.txt');
|
||||
|
||||
$json = json_decode(curl_exec($curl), true);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
private function auth() {
|
||||
$apiUsers = $this->model_user_api->getApis();
|
||||
|
||||
$api = array();
|
||||
foreach ($apiUsers as $apiUser) {
|
||||
if($apiUser['status'] == 1) {
|
||||
if(version_compare(VERSION, '2.1.0', '>=')) {
|
||||
$api = array(
|
||||
'api_id' => $apiUser['api_id'],
|
||||
'key' => $apiUser['key']
|
||||
);
|
||||
} else {
|
||||
$api = array(
|
||||
'api_id' => $apiUser['api_id'],
|
||||
'username' => $apiUser['username'],
|
||||
'password' => $apiUser['password']
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($api['api_id']))
|
||||
return false;
|
||||
|
||||
if(version_compare(VERSION, '2.1.0', '>=')) {
|
||||
$alreadyBinded = false;
|
||||
|
||||
$innerIp = $this->getInnerIpAddr();
|
||||
$apiIps = $this->model_user_api->getApiIps($api['api_id']);
|
||||
foreach($apiIps as $apiIp) {
|
||||
if($apiIp['ip'] == $innerIp)
|
||||
$alreadyBinded = true;
|
||||
}
|
||||
|
||||
if(!$alreadyBinded) {
|
||||
$this->model_user_api->addApiIp($api['api_id'], $innerIp);
|
||||
}
|
||||
}
|
||||
|
||||
$apiAnswer = $this->request('login', array(), $apiUser);
|
||||
|
||||
if(version_compare(VERSION, '2.1.0', '>=')) {
|
||||
$this->apiToken = $apiAnswer['token'];
|
||||
}
|
||||
|
||||
return $apiAnswer;
|
||||
}
|
||||
|
||||
public function editOrder($order_id, $data) {
|
||||
$data['telephone'] = trim($data['telephone']);
|
||||
$customer = array(
|
||||
'currency' => isset($data['currency']) ? $data['currency'] : '',
|
||||
'customer' => $data['customer'],
|
||||
'customer_id' => $data['customer_id'],
|
||||
'customer_group_id' => $data['customer_group_id'],
|
||||
'firstname' => $data['firstname'],
|
||||
'lastname' => $data['lastname'],
|
||||
'email' => $data['email'],
|
||||
'telephone' => !empty($data['telephone']) ? $data['telephone'] : '0000',
|
||||
'fax' => $data['fax'],
|
||||
);
|
||||
$this->request('customer', array(), $customer);
|
||||
|
||||
$products = array();
|
||||
foreach ($data['order_product'] as $order_product) {
|
||||
$products[] = array(
|
||||
'product_id' => $order_product['product_id'],
|
||||
'quantity' => $order_product['quantity'],
|
||||
'option' => $order_product['option']
|
||||
);
|
||||
}
|
||||
$this->request('cart/add', array(), array('product' => $products));
|
||||
|
||||
$payment_address = array(
|
||||
'payment_address' => $data['payment_address'],
|
||||
'firstname' => $data['payment_firstname'],
|
||||
'lastname' => $data['payment_lastname'],
|
||||
'company' => $data['payment_company'],
|
||||
'address_1'=> $data['payment_address_1'],
|
||||
'address_2' => $data['payment_address_2'],
|
||||
'city' => !empty($data['payment_city']) ? $data['payment_city'] : 'none',
|
||||
'postcode' => $data['payment_postcode'],
|
||||
'country_id' => $data['payment_country_id'],
|
||||
'zone_id' => !empty($data['payment_zone_id']) ? $data['payment_zone_id'] : 0,
|
||||
);
|
||||
$this->request('payment/address', array(), $payment_address);
|
||||
|
||||
$this->request('payment/methods', array(), array());
|
||||
$payment_method = array(
|
||||
'payment_method' => $data['payment_code']
|
||||
);
|
||||
$this->request('payment/method', array(), $payment_method);
|
||||
|
||||
$shipping_address = array(
|
||||
'shipping_address' => $data['shipping_address'],
|
||||
'firstname' => $data['shipping_firstname'],
|
||||
'lastname' => $data['shipping_lastname'],
|
||||
'company' => $data['shipping_company'],
|
||||
'address_1' => $data['shipping_address_1'],
|
||||
'address_2' => $data['shipping_address_2'],
|
||||
'city' => !empty($data['shipping_city']) ? $data['shipping_city'] : 'none',
|
||||
'postcode' => $data['shipping_postcode'],
|
||||
'country_id' => $data['shipping_country_id'],
|
||||
'zone_id' => !empty($data['shipping_zone_id']) ? $data['shipping_zone_id'] : 0,
|
||||
);
|
||||
$this->request('shipping/address', array(), $shipping_address);
|
||||
|
||||
$this->request('shipping/methods', array(), array());
|
||||
$shipping_method = array(
|
||||
'shipping_method' => $data['shipping_code']
|
||||
);
|
||||
$this->request('shipping/method', array(), $shipping_method);
|
||||
|
||||
$order = array(
|
||||
'shipping_method' => $data['shipping_code'],
|
||||
'payment_method' => $data['payment_code'],
|
||||
'order_status_id' => $data['order_status_id'],
|
||||
'comment' => $data['comment'],
|
||||
'affiliate_id' => $data['affiliate_id'],
|
||||
);
|
||||
$this->request('order/edit', array('order_id' => $order_id), $order);
|
||||
}
|
||||
|
||||
public function addOrder($data) {
|
||||
$currency = $this->getCookieValue('currency');
|
||||
if($currency) {
|
||||
$a = $this->request('currency', array(), array('currency' => $currency));
|
||||
}
|
||||
|
||||
$customer = array(
|
||||
'store_id' => $data['store_id'],
|
||||
'currency' => $currency != false ? $currency : '',
|
||||
'customer' => $data['customer'],
|
||||
'customer_id' => $data['customer_id'],
|
||||
'customer_group_id' => $data['customer_group_id'],
|
||||
'firstname' => $data['firstname'],
|
||||
'lastname' => $data['lastname'],
|
||||
'email' => $data['email'],
|
||||
'telephone' => $data['telephone'],
|
||||
'fax' => $data['fax'],
|
||||
);
|
||||
$this->request('customer', array(), $customer);
|
||||
|
||||
$products = array();
|
||||
foreach($data['order_product'] as $product) {
|
||||
$product = array(
|
||||
'product_id' => $product['product_id'],
|
||||
'quantity' => $product['quantity'],
|
||||
);
|
||||
$products[] = $product;
|
||||
}
|
||||
$this->request('cart/add', array(), array('product' => $products));
|
||||
|
||||
$payment_address = array(
|
||||
'payment_address' => $data['payment_address'],
|
||||
'firstname' => $data['payment_firstname'],
|
||||
'lastname' => $data['payment_lastname'],
|
||||
'company' => $data['payment_company'],
|
||||
'address_1' => $data['payment_address_1'],
|
||||
'address_2' => $data['payment_address_2'],
|
||||
'city' => $data['payment_city'],
|
||||
'postcode' => $data['payment_postcode'],
|
||||
'country_id' => $data['payment_country_id'],
|
||||
'zone_id' => $data['payment_zone_id'],
|
||||
);
|
||||
$this->request('payment/address', array(), $payment_address);
|
||||
|
||||
$shipping_address = array(
|
||||
'shipping_address' => $data['shipping_address'],
|
||||
'firstname' => $data['shipping_firstname'],
|
||||
'lastname' => $data['shipping_lastname'],
|
||||
'company' => $data['shipping_company'],
|
||||
'address_1' => $data['shipping_address_1'],
|
||||
'address_2' => $data['shipping_address_2'],
|
||||
'city' => $data['shipping_city'],
|
||||
'postcode' => $data['shipping_postcode'],
|
||||
'country_id' => $data['shipping_country_id'],
|
||||
'zone_id' => !empty($data['shipping_zone_id']) ? $data['shipping_zone_id'] : 0,
|
||||
);
|
||||
$this->request('shipping/address', array(), $shipping_address);
|
||||
|
||||
$this->request('shipping/methods', array(), array());
|
||||
$shipping_method = array(
|
||||
'shipping_method' => $data['shipping_code']
|
||||
);
|
||||
$this->request('shipping/method', array(), $shipping_method);
|
||||
|
||||
$this->request('payment/methods', array(), array());
|
||||
$payment_method = array(
|
||||
'payment_method' => $data['payment_code']
|
||||
);
|
||||
$this->request('payment/method', array(), $payment_method);
|
||||
|
||||
$order = array(
|
||||
'shipping_method' => $data['shipping_code'],
|
||||
'payment_method' => $data['payment_code'],
|
||||
'order_status_id' => $data['order_status_id'],
|
||||
'comment' => $data['comment'],
|
||||
'affiliate_id' => $data['affiliate_id'],
|
||||
);
|
||||
$this->request('order/add', array(), $order);
|
||||
}
|
||||
|
||||
private function getInnerIpAddr() {
|
||||
$opencartStoreInfo = $this->model_setting_store->getStore($this->opencartStoreId);
|
||||
|
||||
if ($opencartStoreInfo) {
|
||||
$url = $opencartStoreInfo['ssl'];
|
||||
} else {
|
||||
$url = HTTPS_CATALOG;
|
||||
}
|
||||
|
||||
$curl = curl_init();
|
||||
|
||||
// Set SSL if required
|
||||
if (substr($url, 0, 5) == 'https') {
|
||||
curl_setopt($curl, CURLOPT_PORT, 443);
|
||||
}
|
||||
|
||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
||||
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_FORBID_REUSE, false);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_URL, $url . 'system/cron/getmyip.php');
|
||||
|
||||
return curl_exec($curl);
|
||||
}
|
||||
}
|
47
vqmod/xml/retailcrm_create_order.xml
Normal file
47
vqmod/xml/retailcrm_create_order.xml
Normal file
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<modification>
|
||||
<id>Send order to RetailCRM when it created</id>
|
||||
<version>1.5.x</version>
|
||||
<vqmver required="true">2.3.x</vqmver>
|
||||
<author>retailcrm.ru</author>
|
||||
|
||||
<file path="catalog/controller/checkout/" name="success.php">
|
||||
<operation error="skip">
|
||||
<search position="before" ><![CDATA[$this->cart->clear()]]></search>
|
||||
<add><![CDATA[
|
||||
$this->load->model('account/order');
|
||||
$this->load->model('checkout/order');
|
||||
$this->load->model('retailcrm/order');
|
||||
|
||||
$order = $this->model_checkout_order->getOrder($this->session->data['order_id']);
|
||||
$order['products'] = $this->model_account_order->getOrderProducts($this->session->data['order_id']);
|
||||
$order['order_total'] = $this->model_account_order->getOrderTotals($this->session->data['order_id']);
|
||||
|
||||
$this->model_retailcrm_order->sendToCrm($order, $this->session->data['order_id']);
|
||||
]]></add>
|
||||
</operation>
|
||||
</file>
|
||||
|
||||
<file path="admin/model/sale/" name="order.php">
|
||||
<operation error="skip">
|
||||
<search position="after" ><![CDATA[$this->db->query("UPDATE `" . DB_PREFIX . "order` SET total = '" . (float)$total . "', affiliate_id = '" . (int)$affiliate_id . "', commission = '" . (float)$commission . "' WHERE order_id = '" . (int)$order_id . "'");]]></search>
|
||||
<add><![CDATA[
|
||||
if (!isset($data['fromApi'])) {
|
||||
$this->load->model('setting/setting');
|
||||
$status = $this->model_setting_setting->getSetting('retailcrm');
|
||||
|
||||
if (!empty($data['order_status_id'])) {
|
||||
$data['order_status'] = $status['retailcrm_status'][$data['order_status_id']];
|
||||
}
|
||||
|
||||
$this->load->model('retailcrm/order');
|
||||
if (isset ($order_query)) {
|
||||
$this->model_retailcrm_order->changeInCrm($data, $order_id);
|
||||
} else {
|
||||
$this->model_retailcrm_order->sendToCrm($data, $order_id);
|
||||
}
|
||||
}
|
||||
]]></add>
|
||||
</operation>
|
||||
</file>
|
||||
</modification>
|
Loading…
Reference in New Issue
Block a user