Closes #123 v3.2.0

This commit is contained in:
Akolzin Dmitry 2018-12-25 09:53:42 +03:00
parent d54e5e8c19
commit dfd6c4a76d
10 changed files with 117 additions and 31 deletions

View File

@ -1,3 +1,7 @@
## v.3.2.0
* Добавлена выгрузка картинок для категорий в ICML
* Добавлена настройка для выбора валюты, в которой будет выгружаться цена в ICML
## v.3.1.6 ## v.3.1.6
* Исправлено получение событий из БД для OC 3.0 * Исправлено получение событий из БД для OC 3.0

View File

@ -1 +1 @@
3.1.6 3.2.0

View File

@ -118,6 +118,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
$this->load->model('localisation/country'); $this->load->model('localisation/country');
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$this->load->model('extension/retailcrm/references'); $this->load->model('extension/retailcrm/references');
$this->load->model('localisation/currency');
$this->load->language('extension/module/retailcrm'); $this->load->language('extension/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');
@ -300,7 +301,9 @@ class ControllerExtensionModuleRetailcrm extends Controller
'special_price_settings', 'special_price_settings',
'special_price', 'special_price',
'order_number', 'order_number',
'text_order_number' 'text_order_number',
'text_currency',
'text_currency_label'
); );
$_data = &$data; $_data = &$data;
@ -309,6 +312,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
$_data[$text] = $this->language->get($text); $_data[$text] = $this->language->get($text);
} }
$_data['currencies'] = $this->model_localisation_currency->getCurrencies(0);
$_data['retailcrm_errors'] = array(); $_data['retailcrm_errors'] = array();
$_data['saved_settings'] = $this->model_setting_setting $_data['saved_settings'] = $this->model_setting_setting
->getSetting($this->moduleTitle); ->getSetting($this->moduleTitle);

View File

@ -68,6 +68,8 @@ $_['retailcrm_missing_status'] = 'Status of lost orders';
$_['order_number'] = 'Order number'; $_['order_number'] = 'Order number';
$_['text_order_number'] = 'Upload the order number to retailCRM'; $_['text_order_number'] = 'Upload the order number to retailCRM';
$_['text_currency'] = 'Currency setting';
$_['text_currency_label'] = 'Currency in ICML';
$_['column_total'] = 'Total'; $_['column_total'] = 'Total';
$_['product_summ'] = 'Sum'; $_['product_summ'] = 'Sum';

View File

@ -68,6 +68,8 @@ $_['retailcrm_missing_status'] = 'Estado de pedidos perdidos';
$_['order_number'] = 'Número de pedido'; $_['order_number'] = 'Número de pedido';
$_['text_order_number'] = 'Transferir número de pedido a retailCRM'; $_['text_order_number'] = 'Transferir número de pedido a retailCRM';
$_['text_currency'] = 'Ajustes de moneda';
$_['text_currency_label'] = 'Moneda en ICML';
$_['column_total'] = 'Total'; $_['column_total'] = 'Total';
$_['product_summ'] = 'Importe'; $_['product_summ'] = 'Importe';

View File

@ -68,6 +68,8 @@ $_['retailcrm_missing_status'] = 'Статус пропавших заказо
$_['order_number'] = 'Номер заказа'; $_['order_number'] = 'Номер заказа';
$_['text_order_number'] = 'Передавать номер заказа в retailCRM'; $_['text_order_number'] = 'Передавать номер заказа в retailCRM';
$_['text_currency'] = 'Настройка валюты';
$_['text_currency_label'] = 'Валюта в ICML';
$_['column_total'] = 'Итого'; $_['column_total'] = 'Итого';
$_['product_summ'] = 'Сумма'; $_['product_summ'] = 'Сумма';

View File

@ -80,11 +80,16 @@ class ModelExtensionRetailcrmIcml extends Model
foreach ($categories as $category) { foreach ($categories as $category) {
$category = $this->model_catalog_category->getCategory($category['category_id']); $category = $this->model_catalog_category->getCategory($category['category_id']);
$e = $this->eCategories->appendChild( $c = $this->dd->createElement('category');
$this->dd->createElement(
'category', $category['name'] if ($category['image']) {
) $c->appendChild(
$this->dd->createElement('picture', $this->generateImage($category['image']))
); );
}
$c->appendChild($this->dd->createElement('name', $category['name']));
$e = $this->eCategories->appendChild($c);
$e->setAttribute('id', $category['category_id']); $e->setAttribute('id', $category['category_id']);
@ -95,17 +100,16 @@ class ModelExtensionRetailcrmIcml extends Model
} }
private function addOffers() private function addOffers() {
{
$offerManufacturers = array(); $offerManufacturers = array();
$currencyForIcml = $this->retailcrm->getCurrencyForIcml();
$defaultCurrency = $this->getDefaultCurrency();
$manufacturers = $this->model_catalog_manufacturer $manufacturers = $this->model_catalog_manufacturer
->getManufacturers(array()); ->getManufacturers(array());
foreach ($manufacturers as $manufacturer) { foreach ($manufacturers as $manufacturer) {
$offerManufacturers[ $offerManufacturers[$manufacturer['manufacturer_id']] = $manufacturer['name'];
$manufacturer['manufacturer_id']
] = $manufacturer['name'];
} }
$products = $this->model_catalog_product->getProducts(array()); $products = $this->model_catalog_product->getProducts(array());
@ -190,8 +194,19 @@ class ModelExtensionRetailcrmIcml extends Model
$e->appendChild($this->dd->createElement('name')) $e->appendChild($this->dd->createElement('name'))
->appendChild($this->dd->createTextNode($product['name'])); ->appendChild($this->dd->createTextNode($product['name']));
} }
if ($currencyForIcml && $currencyForIcml != $defaultCurrency) {
$price = $this->currency->convert(
$product['price'] + $optionsValues['price'],
$this->getDefaultCurrency(),
$this->retailcrm->getCurrencyForIcml()
);
} else {
$price = $product['price'] + $optionsValues['price'];
}
$e->appendChild($this->dd->createElement('price')) $e->appendChild($this->dd->createElement('price'))
->appendChild($this->dd->createTextNode($product['price'] + $optionsValues['price'])); ->appendChild($this->dd->createTextNode($price));
/** /**
* Vendor * Vendor
*/ */
@ -299,4 +314,16 @@ class ModelExtensionRetailcrmIcml extends Model
'optionValue' => $optionValue['name'] 'optionValue' => $optionValue['name']
); );
} }
private function getDefaultCurrency() {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency");
foreach ($query->rows as $currency) {
if ($currency['value'] == 1) {
return $currency['code'];
}
}
return $query->rows[0]['code'];
}
} }

View File

@ -92,6 +92,23 @@
</div> </div>
</div> </div>
</fieldset> </fieldset>
<fieldset>
<legend><?php echo $text_currency; ?></legend>
<div class="form-group retailcrm_unit">
<label class="col-sm-2 control-label"><?php echo $text_currency; ?></label>
<div class="col-md-4 col-sm-10">
<select id="retailcrm_currency" name="retailcrm_currency" class="form-control">
<?php foreach ($currencies as $currency) :?>
<?php if ($currency['status']) :?>
<option value="<?php echo $currency['code']; ?>" <?php if(isset($saved_settings['retailcrm_currency']) && $saved_settings['retailcrm_currency'] == $currency['code']):?>selected="selected"<?php endif;?>>
<?php echo $currency['title']; ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
</div>
</fieldset>
<?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)) : ?>
<?php foreach($retailcrm_errors as $retailcrm_error): ?> <?php foreach($retailcrm_errors as $retailcrm_error): ?>

View File

@ -91,6 +91,23 @@
</div> </div>
</div> </div>
</fieldset> </fieldset>
<fieldset>
<legend>{{ text_currency }}</legend>
<div class="form-group retailcrm_unit">
<label class="col-sm-2 control-label">{{ text_currency_label }}</label>
<div class="col-md-4 col-sm-10">
<select id="module_retailcrm_currency" name="module_retailcrm_currency" class="form-control">
{% for currency in currencies %}
{% if currency.status == 1 %}
<option value="{{ currency.code }}" {% if saved_settings.module_retailcrm_currency is defined and saved_settings.module_retailcrm_currency == currency.code %} selected="selected" {% endif %}>
{{ currency.title }}
</option>
{% endif %}
{% endfor %}
</select>
</div>
</div>
</fieldset>
{% if saved_settings.module_retailcrm_apikey is defined and saved_settings.module_retailcrm_apikey and saved_settings.module_retailcrm_url is defined and saved_settings.module_retailcrm_url %} {% if saved_settings.module_retailcrm_apikey is defined and saved_settings.module_retailcrm_apikey and saved_settings.module_retailcrm_url is defined and saved_settings.module_retailcrm_url %}
{% if retailcrm_errors|length %} {% if retailcrm_errors|length %}
{% for retailcrm_error in retailcrm_errors %} {% for retailcrm_error in retailcrm_errors %}
@ -170,7 +187,7 @@
{% if key != 'title' %} {% if key != 'title' %}
<div class="form-group retailcrm_unit"> <div class="form-group retailcrm_unit">
<div class="col-lg-4 col-md-6 col-sm-6"> <div class="col-lg-4 col-md-6 col-sm-6">
<select id="retailcrm_delivery_{{ val.code }}" name="module_retailcrm_delivery[{{ val.code }}]" > <select id="retailcrm_delivery_{{ val.code }}" name="module_retailcrm_delivery[{{ val.code }}]" class="form-control">
{% for k, v in delivery.retailcrm %} {% for k, v in delivery.retailcrm %}
<option value="{{ v.code }}" {% if saved_settings.module_retailcrm_delivery[key] is defined and v.code == saved_settings.module_retailcrm_delivery[key] %} selected="selected" {% endif %}> <option value="{{ v.code }}" {% if saved_settings.module_retailcrm_delivery[key] is defined and v.code == saved_settings.module_retailcrm_delivery[key] %} selected="selected" {% endif %}>
{{ v.name }} {{ v.name }}
@ -179,7 +196,7 @@
</select> </select>
</div> </div>
<div class="col-lg-4 col-md-6 col-sm-6"> <div class="col-lg-4 col-md-6 col-sm-6">
<label class="col-sm-2 control-label" for="retailcrm_pm_{{ val.code }}">{{ val.title }}</label> <label class="control-label" for="retailcrm_pm_{{ val.code }}">{{ val.title }}</label>
</div> </div>
</div> </div>
{% endif %} {% endif %}

View File

@ -8,8 +8,7 @@ class Retailcrm {
protected $apiClient; protected $apiClient;
protected $registry; protected $registry;
public function __construct($registry) public function __construct($registry) {
{
$this->registry = $registry; $this->registry = $registry;
} }
@ -26,8 +25,7 @@ class Retailcrm {
* *
* @return mixed object | boolean * @return mixed object | boolean
*/ */
public function getApiClient($apiUrl = null, $apiKey = null, $apiVersion = null) public function getApiClient($apiUrl = null, $apiKey = null, $apiVersion = null) {
{
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$setting = $this->model_setting_setting->getSetting($this->getModuleTitle()); $setting = $this->model_setting_setting->getSetting($this->getModuleTitle());
@ -55,8 +53,7 @@ class Retailcrm {
* *
* @return \OpencartApiClient * @return \OpencartApiClient
*/ */
public function getOcApiClient($registry) public function getOcApiClient($registry) {
{
return new \OpencartApiClient($registry); return new \OpencartApiClient($registry);
} }
@ -65,8 +62,7 @@ class Retailcrm {
* *
* @return string $title * @return string $title
*/ */
public function getModuleTitle() public function getModuleTitle() {
{
if (version_compare(VERSION, '3.0', '<')) { if (version_compare(VERSION, '3.0', '<')) {
$title = 'retailcrm'; $title = 'retailcrm';
} else { } else {
@ -81,8 +77,7 @@ class Retailcrm {
* *
* @return string $token * @return string $token
*/ */
public function getTokenTitle() public function getTokenTitle() {
{
if (version_compare(VERSION, '3.0', '<')) { if (version_compare(VERSION, '3.0', '<')) {
$token = 'token'; $token = 'token';
} else { } else {
@ -92,8 +87,7 @@ class Retailcrm {
return $token; return $token;
} }
public function getOffers($product) public function getOffers($product) {
{
// Формируем офферы отнсительно доступных опций // Формируем офферы отнсительно доступных опций
$options = $this->model_catalog_product->getProductOptions($product['product_id']); $options = $this->model_catalog_product->getProductOptions($product['product_id']);
$offerOptions = array('select', 'radio'); $offerOptions = array('select', 'radio');
@ -165,4 +159,21 @@ class Retailcrm {
return $offers; return $offers;
} }
/**
* @return mixed
*/
public function getCurrencyForIcml() {
$this->load->model('setting/setting');
$setting = $this->model_setting_setting->getSetting($this->getModuleTitle());
if (isset($setting[$this->getModuleTitle() . '_currency'])
&& $this->currency->has($setting[$this->getModuleTitle() . '_currency'])
) {
return $setting[$this->getModuleTitle() . '_currency'];
}
return false;
}
} }