mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-22 05:06:07 +03:00
изменено: admin/controller/extension/module/retailcrm.php
изменено: admin/model/extension/retailcrm/references.php изменено: admin/view/stylesheet/retailcrm.css изменено: admin/view/template/extension/module/retailcrm.tpl новый файл: catalog/controller/api/retailcrm.php
This commit is contained in:
parent
cbbf80bb44
commit
6605472329
@ -81,7 +81,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->model('extension/module');
|
||||
$this->load->model('extension/retailcrm/references');
|
||||
@ -231,7 +231,8 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
$_data['header'] = $this->load->controller('common/header');
|
||||
$_data['column_left'] = $this->load->controller('common/column_left');
|
||||
$_data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$_data['countries'] = $this->model_localisation_country->getCountries();
|
||||
|
||||
$this->response->setOutput(
|
||||
$this->load->view('extension/module/retailcrm.tpl', $_data)
|
||||
);
|
||||
|
@ -5,9 +5,20 @@ require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
||||
class ModelExtensionRetailcrmReferences extends Model
|
||||
{
|
||||
protected $retailcrm;
|
||||
private $opencartApiClient;
|
||||
|
||||
public function getOpercartDeliveryTypes()
|
||||
{
|
||||
$this->load->model('user/api');
|
||||
$this->opencartApiClient = new OpencartApiClient($this->registry);
|
||||
|
||||
return $this->opencartApiClient->request('retailcrm/getDeliveryTypes', array(), array());
|
||||
}
|
||||
|
||||
public function getDeliveryTypes()
|
||||
{
|
||||
$this->load->model('setting/store');
|
||||
|
||||
return array(
|
||||
'opencart' => $this->getOpercartDeliveryTypes(),
|
||||
'retailcrm' => $this->getApiDeliveryTypes()
|
||||
@ -30,28 +41,6 @@ class ModelExtensionRetailcrmReferences extends Model
|
||||
);
|
||||
}
|
||||
|
||||
public function getOpercartDeliveryTypes()
|
||||
{
|
||||
$deliveryMethods = array();
|
||||
$files = glob(DIR_APPLICATION . 'controller/extension/shipping/*.php');
|
||||
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
$extension = basename($file, '.php');
|
||||
|
||||
$this->load->language('extension/shipping/' . $extension);
|
||||
|
||||
if ($this->config->get($extension . '_status')) {
|
||||
$deliveryMethods[$extension.'.'.$extension] = strip_tags(
|
||||
$this->language->get('heading_title')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $deliveryMethods;
|
||||
}
|
||||
|
||||
public function getOpercartOrderStatuses()
|
||||
{
|
||||
$this->load->model('localisation/order_status');
|
||||
|
@ -1,2 +1,3 @@
|
||||
.retailcrm_unit {margin-bottom: 10px;}
|
||||
.retailcrm_unit input {width: 30%;}
|
||||
.checkbox input{width: auto;}
|
||||
|
@ -45,6 +45,19 @@
|
||||
<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>
|
||||
<h3><?php echo $retailcrm_countries_settings; ?></h3>
|
||||
<div class="retailcrm_unit">
|
||||
<div class="well well-sm" style="height: 150px; overflow: auto;">
|
||||
<?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'] != ''): ?>
|
||||
|
||||
@ -56,16 +69,21 @@
|
||||
<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['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">
|
||||
<select id="retailcrm_delivery_<?php echo $val['code']; ?>" name="retailcrm_delivery[<?php echo $val['code']; ?>]" >
|
||||
<?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; ?>
|
||||
<?php endforeach; ?>
|
||||
</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>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@ -107,4 +125,4 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php echo $footer; ?>
|
||||
<?php echo $footer; ?>
|
74
catalog/controller/api/retailcrm.php
Normal file
74
catalog/controller/api/retailcrm.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?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('localisation/zone');
|
||||
$this->load->model('localisation/country');
|
||||
$this->load->model('extension/extension');
|
||||
|
||||
$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('extension/shipping/' . $shippingModule['code']);
|
||||
|
||||
if ($this->config->get($shippingModule['code'] . '_status')) {
|
||||
if($this->{'model_extension_shipping_' . $shippingModule['code']}->getQuote($address)) {
|
||||
$quote_data[] = $this->{'model_extension_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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user