fix getting shipping methods

This commit is contained in:
Akolzin Dmitry 2017-09-22 11:24:35 +03:00
parent 5178c5a4cd
commit db00b14872
12 changed files with 152 additions and 53 deletions

View File

@ -26,7 +26,10 @@ class ControllerModuleRetailcrm extends Controller
{ {
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$this->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'); $this->load->model('extension/event');
@ -78,6 +81,7 @@ class ControllerModuleRetailcrm extends Controller
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$this->load->model('extension/module'); $this->load->model('extension/module');
$this->load->model('retailcrm/references'); $this->load->model('retailcrm/references');
$this->load->model('localisation/country');
$this->load->language('module/retailcrm'); $this->load->language('module/retailcrm');
$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');
@ -112,6 +116,7 @@ class ControllerModuleRetailcrm extends Controller
'retailcrm_dict_delivery', 'retailcrm_dict_delivery',
'retailcrm_dict_status', 'retailcrm_dict_status',
'retailcrm_dict_payment', 'retailcrm_dict_payment',
'retailcrm_countries_settings'
); );
$this->load->model('extension/extension'); $this->load->model('extension/extension');
@ -216,7 +221,7 @@ class ControllerModuleRetailcrm extends Controller
$this->load->model('design/layout'); $this->load->model('design/layout');
$_data['layouts'] = $this->model_design_layout->getLayouts(); $_data['layouts'] = $this->model_design_layout->getLayouts();
$_data['countries'] = $this->model_localisation_country->getCountries();
$_data['header'] = $this->load->controller('common/header'); $_data['header'] = $this->load->controller('common/header');
$_data['column_left'] = $this->load->controller('common/column_left'); $_data['column_left'] = $this->load->controller('common/column_left');
$_data['footer'] = $this->load->controller('common/footer'); $_data['footer'] = $this->load->controller('common/footer');
@ -342,9 +347,9 @@ class ControllerModuleRetailcrm extends Controller
private function setLogs() private function setLogs()
{ {
if (version_compare(VERSION, '2.0', '>')) { if (version_compare(VERSION, '2.0', '>')) {
$logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log';
} else { } else {
$logs = DIR_SYSTEM . 'logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'logs/retailcrm.log';
} }
return $logs; return $logs;

View File

@ -10,6 +10,7 @@ $_['text_success'] = 'Setting saved';
$_['text_notice'] = 'Warning! Timezone in CRM & your shop must be equal, you must setup it here:'; $_['text_notice'] = 'Warning! Timezone in CRM & your shop must be equal, you must setup it here:';
$_['retailcrm_base_settings'] = 'Connection settings'; $_['retailcrm_base_settings'] = 'Connection settings';
$_['retailcrm_dict_settings'] = 'Dictionary settings'; $_['retailcrm_dict_settings'] = 'Dictionary settings';
$_['retailcrm_countries_settings'] = 'Trading zones setting';
$_['retailcrm_url'] = 'RetailCRM URL'; $_['retailcrm_url'] = 'RetailCRM URL';
$_['retailcrm_apikey'] = 'RetailCRM API Key'; $_['retailcrm_apikey'] = 'RetailCRM API Key';

View File

@ -10,6 +10,7 @@ $_['text_success'] = 'Настройки успешно сохра
$_['text_notice'] = 'Внимание! Часовой пояс в CRM должен совпадать с часовым поясом в магазине, настроки часового пояса CRM можно задать по адресу:'; $_['text_notice'] = 'Внимание! Часовой пояс в CRM должен совпадать с часовым поясом в магазине, настроки часового пояса CRM можно задать по адресу:';
$_['retailcrm_base_settings'] = 'Настройки соединения'; $_['retailcrm_base_settings'] = 'Настройки соединения';
$_['retailcrm_dict_settings'] = 'Настройки соответствия справочников'; $_['retailcrm_dict_settings'] = 'Настройки соответствия справочников';
$_['retailcrm_countries_settings'] = 'Настройка торговых зон';
$_['retailcrm_url'] = 'Адрес RetailCRM'; $_['retailcrm_url'] = 'Адрес RetailCRM';
$_['retailcrm_apikey'] = 'Api ключ RetailCRM'; $_['retailcrm_apikey'] = 'Api ключ RetailCRM';

View File

@ -52,9 +52,9 @@ class ModelRetailcrmCustomer extends Model {
private function setLogs() private function setLogs()
{ {
if (version_compare(VERSION, '2.0', '>')) { if (version_compare(VERSION, '2.0', '>')) {
$logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log';
} else { } else {
$logs = DIR_SYSTEM . 'logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'logs/retailcrm.log';
} }
return $logs; return $logs;

View File

@ -471,9 +471,9 @@ class ModelRetailcrmHistory extends Model
private function setLogs() private function setLogs()
{ {
if (version_compare(VERSION, '2.0', '>')) { if (version_compare(VERSION, '2.0', '>')) {
$logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log';
} else { } else {
$logs = DIR_SYSTEM . 'logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'logs/retailcrm.log';
} }
return $logs; return $logs;

View File

@ -9,14 +9,14 @@ class ModelRetailcrmOrder extends Model {
if(empty($orders)) if(empty($orders))
return false; return false;
if(empty($settings['retailcrm_url']) || empty($settings['retailcrm_apikey'])) if(empty($this->settings['retailcrm_url']) || empty($this->settings['retailcrm_apikey']))
return false; return false;
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php'; require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
$this->retailcrmApi = new RetailcrmProxy( $this->retailcrmApi = new RetailcrmProxy(
$settings['retailcrm_url'], $this->settings['retailcrm_url'],
$settings['retailcrm_apikey'], $this->settings['retailcrm_apikey'],
$this->serLogs() $this->serLogs()
); );
@ -130,9 +130,9 @@ class ModelRetailcrmOrder extends Model {
private function setLogs() private function setLogs()
{ {
if (version_compare(VERSION, '2.0', '>')) { if (version_compare(VERSION, '2.0', '>')) {
$logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log';
} else { } else {
$logs = DIR_SYSTEM . 'logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'logs/retailcrm.log';
} }
return $logs; return $logs;

View File

@ -5,9 +5,20 @@ require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
class ModelRetailcrmReferences extends Model class ModelRetailcrmReferences extends Model
{ {
protected $retailcrm; protected $retailcrm;
private $opencartApiClient;
public function getOpercartDeliveryTypes()
{
$this->load->model('user/api');
$this->opencartApiClient = new OpencartApiClient($this->registry);
return $this->opencartApiClient->getDeliveryTypes();
}
public function getDeliveryTypes() public function getDeliveryTypes()
{ {
$this->load->model('setting/store');
return array( return array(
'opencart' => $this->getOpercartDeliveryTypes(), 'opencart' => $this->getOpercartDeliveryTypes(),
'retailcrm' => $this->getApiDeliveryTypes() 'retailcrm' => $this->getApiDeliveryTypes()
@ -30,28 +41,6 @@ class ModelRetailcrmReferences extends Model
); );
} }
public function getOpercartDeliveryTypes()
{
$deliveryMethods = array();
$files = glob(DIR_APPLICATION . 'controller/shipping/*.php');
if ($files) {
foreach ($files as $file) {
$extension = basename($file, '.php');
$this->load->language('shipping/' . $extension);
if ($this->config->get($extension . '_status')) {
$deliveryMethods[$extension.'.'.$extension] = strip_tags(
$this->language->get('heading_title')
);
}
}
}
return $deliveryMethods;
}
public function getOpercartOrderStatuses() public function getOpercartOrderStatuses()
{ {
$this->load->model('localisation/order_status'); $this->load->model('localisation/order_status');
@ -139,9 +128,9 @@ class ModelRetailcrmReferences extends Model
private function setLogs() private function setLogs()
{ {
if (version_compare(VERSION, '2.0', '>')) { if (version_compare(VERSION, '2.0', '>')) {
$logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log';
} else { } else {
$logs = DIR_SYSTEM . 'logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'logs/retailcrm.log';
} }
return $logs; return $logs;

View File

@ -45,7 +45,19 @@
<label for="retailcrm_apikey"><?php echo $retailcrm_apikey; ?></label><br> <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;?>"> <input id="retailcrm_apikey" type="text" name="retailcrm_apikey" value="<?php if (isset($saved_settings['retailcrm_apikey'])): echo $saved_settings['retailcrm_apikey']; endif;?>">
</div> </div>
<h3><?php echo $retailcrm_countries_settings; ?></h3>
<div class="retailcrm_unit">
<div class="well well-sm" style="height: 150px; overflow: auto; width: 30%;">
<?php foreach($countries as $country) : ?>
<div class="checkbox">
<label>
<input type="checkbox" name="<?php echo 'retailcrm_country[]'; ?>" value="<?php echo $country['country_id']; ?>" <?php if(isset($saved_settings['retailcrm_country']) && in_array($country['country_id'], $saved_settings['retailcrm_country'])): echo 'checked'; endif;?>>
<?php echo $country['name']; ?>
</label>
</div>
<?php endforeach; ?>
</div>
</div>
<?php if (isset($saved_settings['retailcrm_apikey']) && $saved_settings['retailcrm_apikey'] != '' && isset($saved_settings['retailcrm_url']) && $saved_settings['retailcrm_url'] != ''): ?> <?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 if (!empty($retailcrm_errors)) : ?>
@ -56,18 +68,22 @@
<h3><?php echo $retailcrm_dict_settings; ?></h3> <h3><?php echo $retailcrm_dict_settings; ?></h3>
<h4><?php echo $retailcrm_dict_delivery; ?></h4> <h4><?php echo $retailcrm_dict_delivery; ?></h4>
<?php foreach ($delivery['opencart'] as $key => $value): ?> <?php foreach($delivery['opencart'] as $value): ?>
<div class="pm"><?php echo $value['title'].':'; ?></div>
<?php unset($value['title']); ?>
<?php foreach ($value as $key => $val): ?>
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<select id="retailcrm_delivery_<?php echo $key; ?>" name="retailcrm_delivery[<?php echo $key; ?>]" > <select id="retailcrm_delivery_<?php echo $val['code']; ?>" name="retailcrm_delivery[<?php echo $val['code']; ?>]" >
<?php foreach ($delivery['retailcrm'] as $k => $v): ?> <?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;?>> <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'];?> <?php echo $v['name'];?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
<label for="retailcrm_delivery_<?php echo $key; ?>"><?php echo $value; ?></label> <label for="retailcrm_pm_<?php echo $val['code']; ?>"><?php echo $val['title']; ?></label>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
<?php endforeach; ?>
<h4><?php echo $retailcrm_dict_status; ?></h4> <h4><?php echo $retailcrm_dict_status; ?></h4>
<?php foreach ($statuses['opencart'] as $status): ?> <?php foreach ($statuses['opencart'] as $status): ?>

View File

@ -0,0 +1,81 @@
<?php
class ControllerApiRetailcrm extends Controller
{
public function getDeliveryTypes()
{
$this->load->model('localisation/country');
$this->load->model('setting/setting');
$countries = $this->model_setting_setting->getSetting('retailcrm')['retailcrm_country'];
$deliveryTypes = array();
foreach ($countries as $country) {
$deliveryTypes = array_merge($deliveryTypes, $this->getDeliveryTypesByZones($country));
}
if (isset($this->request->server['HTTP_ORIGIN'])) {
$this->response->addHeader('Access-Control-Allow-Origin: ' . $this->request->server['HTTP_ORIGIN']);
$this->response->addHeader('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
$this->response->addHeader('Access-Control-Max-Age: 1000');
$this->response->addHeader('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($deliveryTypes));
}
protected function getDeliveryTypesByZones($country_id)
{
$this->load->model('extension/extension');
$this->load->model('localisation/zone');
$this->load->model('localisation/country');
$shippingModules = $this->model_extension_extension->getExtensions('shipping');
$zones = $this->model_localisation_zone->getZonesByCountryId($country_id);
$country = $this->model_localisation_country->getCountry($country_id);
$quote_data = array();
foreach ($zones as $zone) {
$address = array(
'country_id' => $country_id,
'zone_id' => $zone['zone_id'],
'iso_code_2' => $country['iso_code_2'],
'iso_code_3' => $country['iso_code_3'],
'zone_code' => $zone['code'],
'postcode' => '',
'city' => ''
);
foreach ($shippingModules as $shippingModule) {
$this->load->model('shipping/' . $shippingModule['code']);
if ($this->config->get($shippingModule['code'] . '_status')) {
if ($shippingModule['code'] == 'free') {
$free_total = $this->config->get('free_total');
if ($free_total > 0) {
$this->config->set('free_total', 0);
}
}
if($this->{'model_shipping_' . $shippingModule['code']}->getQuote($address)) {
$quote_data[] = $this->{'model_shipping_' . $shippingModule['code']}->getQuote($address);
}
}
}
}
$deliveryTypes = array();
foreach ($quote_data as $shipping) {
foreach ($shipping['quote'] as $shippingMethod) {
$deliveryTypes[$shipping['code']]['title'] = $shipping['title'];
$deliveryTypes[$shipping['code']][$shippingMethod['code']] = $shippingMethod;
}
}
return $deliveryTypes;
}
}

View File

@ -43,9 +43,9 @@ class ModelRetailcrmCustomer extends Model {
private function setLogs() private function setLogs()
{ {
if (version_compare(VERSION, '2.0', '>')) { if (version_compare(VERSION, '2.0', '>')) {
$logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log';
} else { } else {
$logs = DIR_SYSTEM . 'logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'logs/retailcrm.log';
} }
return $logs; return $logs;

View File

@ -261,9 +261,9 @@ class ModelRetailcrmOrder extends Model {
private function setLogs() private function setLogs()
{ {
if (version_compare(VERSION, '2.0', '>')) { if (version_compare(VERSION, '2.0', '>')) {
$logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log';
} else { } else {
$logs = DIR_SYSTEM . 'logs/ecomlogic.log'; $logs = DIR_SYSTEM . 'logs/retailcrm.log';
} }
return $logs; return $logs;

View File

@ -288,6 +288,12 @@ class OpencartApiClient {
$this->request('order/add', array(), $order); $this->request('order/add', array(), $order);
} }
public function getDeliveryTypes() {
$this->apiToken = $this->session->data['token'];
return $this->request('retailcrm/getDeliveryTypes', array(), array());
}
private function getInnerIpAddr() { private function getInnerIpAddr() {
$opencartStoreInfo = $this->model_setting_store->getStore($this->opencartStoreId); $opencartStoreInfo = $this->model_setting_store->getStore($this->opencartStoreId);