History fix, orders history setting

This commit is contained in:
Akolzin Dmitry 2019-03-19 16:43:54 +03:00
parent 08d071edda
commit d58b66a01b
11 changed files with 120 additions and 51 deletions

View File

@ -1,3 +1,7 @@
## v.3.3.0
* Добавена настройка записи истории изменения заказов в Opencart
* Устранен баг с вызовом события редактирования заказа при выгрузке истории изменений из retailCRM
## v.3.2.4 ## v.3.2.4
* Добавлена возможность передачи акционных цен для нескольких групп пользователей * Добавлена возможность передачи акционных цен для нескольких групп пользователей
* Добавлена передача нулевой цены для неустановленных акционных цен * Добавлена передача нулевой цены для неустановленных акционных цен

View File

@ -1 +1 @@
3.2.4 3.3.0

View File

@ -304,7 +304,9 @@ class ControllerExtensionModuleRetailcrm extends Controller
'order_number', 'order_number',
'text_order_number', 'text_order_number',
'text_currency', 'text_currency',
'text_currency_label' 'text_currency_label',
'status_changes',
'text_status_changes'
); );
$_data = &$data; $_data = &$data;

View File

@ -1,8 +1,8 @@
<?php <?php
// Heading Goes here: // Heading Goes here:
$_['heading_title'] = 'Retailcrm'; $_['heading_title'] = 'retailCRM';
$_['retailcrm_title'] = 'Retailcrm'; $_['retailcrm_title'] = 'retailCRM';
// Text // Text
$_['text_module'] = 'Modules'; $_['text_module'] = 'Modules';
@ -56,7 +56,7 @@ $_['text_error_cf_opencart'] = 'There are no custom fields in Opencart';
$_['text_error_cf_retailcrm'] = 'There are no custom fields in retailCRM'; $_['text_error_cf_retailcrm'] = 'There are no custom fields in retailCRM';
$_['text_error_save'] = 'Error when saving settings'; $_['text_error_save'] = 'Error when saving settings';
$_['text_error_log'] = 'Log size is more than 2MB'; $_['text_error_log'] = 'Log size is more than 2MB';
$_['text_error_delivery'] = 'Delivery types are not found'; $_['text_error_delivery'] = 'Delivery types are not found';
$_['text_confirm_log'] = 'Are you sure that you want to clear the log?'; $_['text_confirm_log'] = 'Are you sure that you want to clear the log?';
$_['retailcrm_dict_delivery'] = 'Delivery types'; $_['retailcrm_dict_delivery'] = 'Delivery types';
@ -70,6 +70,8 @@ $_['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'] = 'Currency setting';
$_['text_currency_label'] = 'Currency in ICML'; $_['text_currency_label'] = 'Currency in ICML';
$_['status_changes'] = 'History of changes';
$_['text_status_changes'] = 'Record changes to the order history of Opencart';
$_['column_total'] = 'Total'; $_['column_total'] = 'Total';
$_['product_summ'] = 'Sum'; $_['product_summ'] = 'Sum';

View File

@ -1,8 +1,8 @@
<?php <?php
// Heading Goes here: // Heading Goes here:
$_['heading_title'] = 'retailcrm'; $_['heading_title'] = 'retailCRM';
$_['retailcrm_title'] = 'retailcrm'; $_['retailcrm_title'] = 'retailCRM';
// Text // Text
$_['text_module'] = 'Módulos'; $_['text_module'] = 'Módulos';
@ -24,7 +24,7 @@ $_['retailcrm_url'] = 'Dirección del retailCRM';
$_['retailcrm_apikey'] = 'Clave de la API del retailCRM'; $_['retailcrm_apikey'] = 'Clave de la API del retailCRM';
$_['collector_site_key'] = 'Clave de la página web'; $_['collector_site_key'] = 'Clave de la página web';
$_['special_price_settings'] = 'Ajuste de la descarga del precio promocional'; $_['special_price_settings'] = 'Ajuste de la descarga del precio promocional';
$_['special_price'] = 'Tipo de precio en el que se cargará el precio de promoción'; $_['special_price'] = 'Tipo de precio en el que se cargará el precio de promoción';
$_['text_success_export'] = 'Los pedidos y los clientes han sido exportados con éxito'; $_['text_success_export'] = 'Los pedidos y los clientes han sido exportados con éxito';
$_['text_success_export_order'] = 'El pedido ha sido exportado con éxito'; $_['text_success_export_order'] = 'El pedido ha sido exportado con éxito';
@ -56,7 +56,7 @@ $_['text_error_cf_opencart'] = 'Faltan campos personalizados en Opencart';
$_['text_error_cf_retailcrm'] = 'Faltan campos personalizados en retailCRM'; $_['text_error_cf_retailcrm'] = 'Faltan campos personalizados en retailCRM';
$_['text_error_save'] = 'Error al guardar la configuración'; $_['text_error_save'] = 'Error al guardar la configuración';
$_['text_error_log'] = 'El Tamaño del registro es más de 2MB'; $_['text_error_log'] = 'El Tamaño del registro es más de 2MB';
$_['text_error_delivery'] = 'No se encontraron los métodos de envío'; $_['text_error_delivery'] = 'No se encontraron los métodos de envío';
$_['text_confirm_log'] = '¿Estás seguro de que quieres borrar el registro?'; $_['text_confirm_log'] = '¿Estás seguro de que quieres borrar el registro?';
$_['retailcrm_dict_delivery'] = 'Métodos de envío'; $_['retailcrm_dict_delivery'] = 'Métodos de envío';
@ -70,6 +70,8 @@ $_['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'] = 'Ajustes de moneda';
$_['text_currency_label'] = 'Moneda en ICML'; $_['text_currency_label'] = 'Moneda en ICML';
$_['status_changes'] = 'Historial de cambios';
$_['text_status_changes'] = 'Registrar los cambios en el historial de pedidos de Opencart';
$_['column_total'] = 'Total'; $_['column_total'] = 'Total';
$_['product_summ'] = 'Importe'; $_['product_summ'] = 'Importe';

View File

@ -1,8 +1,8 @@
<?php <?php
// Heading Goes here: // Heading Goes here:
$_['heading_title'] = 'Retailcrm'; $_['heading_title'] = 'retailCRM';
$_['retailcrm_title'] = 'Retailcrm'; $_['retailcrm_title'] = 'retailCRM';
// Text // Text
$_['text_module'] = 'Модули'; $_['text_module'] = 'Модули';
@ -24,7 +24,7 @@ $_['retailcrm_url'] = 'Адрес RetailCRM';
$_['retailcrm_apikey'] = 'Api ключ RetailCRM'; $_['retailcrm_apikey'] = 'Api ключ RetailCRM';
$_['collector_site_key'] = 'Ключ сайта'; $_['collector_site_key'] = 'Ключ сайта';
$_['special_price_settings'] = 'Настройка выгрузки акционной цены'; $_['special_price_settings'] = 'Настройка выгрузки акционной цены';
$_['special_price'] = 'Тип цены, в который будет выгружаться цена по акции'; $_['special_price'] = 'Тип цены, в который будет выгружаться цена по акции';
$_['text_success_export'] = 'Заказы и клиенты успешно выгружены'; $_['text_success_export'] = 'Заказы и клиенты успешно выгружены';
$_['text_success_export_order'] = 'Заказ успешно выгружен'; $_['text_success_export_order'] = 'Заказ успешно выгружен';
@ -56,7 +56,7 @@ $_['text_error_cf_opencart'] = 'Отсутствуют пользовате
$_['text_error_cf_retailcrm'] = 'Отсутствуют пользовательские поля в RetailCRM'; $_['text_error_cf_retailcrm'] = 'Отсутствуют пользовательские поля в RetailCRM';
$_['text_error_save'] = 'Ошибка сохранения настроек'; $_['text_error_save'] = 'Ошибка сохранения настроек';
$_['text_error_log'] = 'Размер лога более 2MB'; $_['text_error_log'] = 'Размер лога более 2MB';
$_['text_error_delivery'] = 'Не найдены типы доставки'; $_['text_error_delivery'] = 'Не найдены типы доставки';
$_['text_confirm_log'] = 'Вы уверены, что хотите очистить лог?'; $_['text_confirm_log'] = 'Вы уверены, что хотите очистить лог?';
$_['retailcrm_dict_delivery'] = 'Способы доставки'; $_['retailcrm_dict_delivery'] = 'Способы доставки';
@ -70,6 +70,8 @@ $_['order_number'] = 'Номер заказа';
$_['text_order_number'] = 'Передавать номер заказа в retailCRM'; $_['text_order_number'] = 'Передавать номер заказа в retailCRM';
$_['text_currency'] = 'Настройка валюты'; $_['text_currency'] = 'Настройка валюты';
$_['text_currency_label'] = 'Валюта в ICML'; $_['text_currency_label'] = 'Валюта в ICML';
$_['status_changes'] = 'История изменений';
$_['text_status_changes'] = 'Фиксировать изменения в истории заказа Opencart';
$_['column_total'] = 'Итого'; $_['column_total'] = 'Итого';
$_['product_summ'] = 'Сумма'; $_['product_summ'] = 'Сумма';

View File

@ -4,9 +4,9 @@ class ModelExtensionRetailcrmHistory extends Model
{ {
/** /**
* Create order in OC * Create order in OC
* *
* @param array $order * @param array $order
* *
* @return int $order_id * @return int $order_id
*/ */
public function addOrder($order) public function addOrder($order)
@ -30,10 +30,10 @@ class ModelExtensionRetailcrmHistory extends Model
/** /**
* Edit order in OC * Edit order in OC
* *
* @param int $order_id * @param int $order_id
* @param array $order * @param array $order
* *
* @return void * @return void
*/ */
public function editOrder($order_id, $order) public function editOrder($order_id, $order)
@ -57,10 +57,10 @@ class ModelExtensionRetailcrmHistory extends Model
/** /**
* Add order products * Add order products
* *
* @param int $order_id * @param int $order_id
* @param array $products * @param array $products
* *
* @return void * @return void
*/ */
public function addOrderProducts($order_id, $products) public function addOrderProducts($order_id, $products)
@ -78,10 +78,10 @@ class ModelExtensionRetailcrmHistory extends Model
/** /**
* Add order totals * Add order totals
* *
* @param int $order_id * @param int $order_id
* @param array $totals * @param array $totals
* *
* @return void * @return void
*/ */
public function addOrderTotals($order_id, $totals) public function addOrderTotals($order_id, $totals)
@ -93,7 +93,7 @@ class ModelExtensionRetailcrmHistory extends Model
/** /**
* Get total titles * Get total titles
* *
* @return string $title * @return string $title
*/ */
protected function totalTitles() protected function totalTitles()
@ -109,23 +109,23 @@ class ModelExtensionRetailcrmHistory extends Model
/** /**
* Get country by iso code 2 * Get country by iso code 2
* *
* @param string $isoCode * @param string $isoCode
* *
* @return array * @return array
*/ */
public function getCountryByIsoCode($isoCode) public function getCountryByIsoCode($isoCode)
{ {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE iso_code_2 = '" . $isoCode . "'"); $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE iso_code_2 = '" . $isoCode . "'");
return $query->row; return $query->row;
} }
/** /**
* Get zone by name * Get zone by name
* *
* @param string $name * @param string $name
* *
* @return array * @return array
*/ */
public function getZoneByName($name) public function getZoneByName($name)
@ -137,10 +137,10 @@ class ModelExtensionRetailcrmHistory extends Model
/** /**
* Get currency * Get currency
* *
* @param string $code * @param string $code
* @param string $field (default = '') * @param string $field (default = '')
* *
* @return mixed array | string * @return mixed array | string
*/ */
public function getCurrencyByCode($code, $field = '') public function getCurrencyByCode($code, $field = '')
@ -156,10 +156,10 @@ class ModelExtensionRetailcrmHistory extends Model
/** /**
* Get language * Get language
* *
* @param string $code * @param string $code
* @param string $field (default = '') * @param string $field (default = '')
* *
* @return mixed array | string * @return mixed array | string
*/ */
public function getLanguageByCode($code, $field = '') public function getLanguageByCode($code, $field = '')
@ -175,10 +175,10 @@ class ModelExtensionRetailcrmHistory extends Model
/** /**
* Get product option value * Get product option value
* *
* @param int $option_value_id * @param int $option_value_id
* @param string $field * @param string $field
* *
* @return mixed array | string * @return mixed array | string
*/ */
public function getOptionValue($option_value_id, $field = '') public function getOptionValue($option_value_id, $field = '')

View File

@ -4,6 +4,9 @@ require_once __DIR__ . '/../history.php';
class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
{ {
/** @var bool */
public static $history_run = false;
protected $createResult; protected $createResult;
protected $settings; protected $settings;
protected $moduleTitle; protected $moduleTitle;
@ -32,7 +35,7 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
$this->load->model('setting/store'); $this->load->model('setting/store');
$this->load->model('user/api'); $this->load->model('user/api');
$this->load->model('sale/order'); $this->load->model('sale/order');
$this->load->model('customer/customer'); $this->load->model('customer/customer');
$this->load->model('extension/retailcrm/references'); $this->load->model('extension/retailcrm/references');
$this->load->model('catalog/product'); $this->load->model('catalog/product');
$this->load->model('catalog/option'); $this->load->model('catalog/option');
@ -162,9 +165,9 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
} }
$this->model_setting_setting->editSetting( $this->model_setting_setting->editSetting(
'retailcrm_history', 'retailcrm_history',
array( array(
'retailcrm_history_orders' => $sinceIdOrders, 'retailcrm_history_orders' => $sinceIdOrders,
'retailcrm_history_customers' => $sinceIdCustomers, 'retailcrm_history_customers' => $sinceIdCustomers,
'retailcrm_history_datetime' => $generatedAt 'retailcrm_history_datetime' => $generatedAt
) )
@ -183,13 +186,13 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
/** /**
* Update orders from history * Update orders from history
* *
* @param array $orders * @param array $orders
* *
* @return void * @return void
*/ */
protected function updateOrders($orders) protected function updateOrders($orders)
{ {
foreach ($orders as $order) { foreach ($orders as $order) {
$ocOrder = $this->model_sale_order->getOrder($order['externalId']); $ocOrder = $this->model_sale_order->getOrder($order['externalId']);
@ -468,19 +471,26 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
} }
$this->editOrder($order['externalId'], $data); $this->editOrder($order['externalId'], $data);
$this->opencartApiClient->addHistory($order['externalId'], $data['order_status_id']);
if (isset($this->settings[$this->moduleTitle . '_status_changes'])
&& $this->settings[$this->moduleTitle . '_status_changes']
) {
static::$history_run = true;
$this->opencartApiClient->addHistory($order['externalId'], $data['order_status_id']);
static::$history_run = false;
}
} }
} }
/** /**
* Create orders from history * Create orders from history
* *
* @param array $orders * @param array $orders
* *
* @return array * @return array
*/ */
protected function createOrders($orders) protected function createOrders($orders)
{ {
$customersIdsFix = array(); $customersIdsFix = array();
$ordersIdsFix = array(); $ordersIdsFix = array();

View File

@ -109,6 +109,26 @@
</div> </div>
</div> </div>
</fieldset> </fieldset>
<fieldset>
<legend><?php echo $status_changes; ?></legend>
<div class="form-group">
<label class="col-sm-2 control-label" for="retailcrm_status_changes"><?php echo $text_status_changes; ?></label>
<div class="col-sm-10">
<label class="radio-inline">
<input type="radio" name="retailcrm_status_changes" value="1" <?php if (isset($saved_settings['retailcrm_status_changes']) &&
$saved_settings['retailcrm_status_changes'] == 1) :
echo 'checked'; endif; ?> />
<?php echo $text_yes; ?>
</label>
<label class="radio-inline">
<input type="radio" name="retailcrm_status_changes" value="0" <?php if (!isset($saved_settings['retailcrm_status_changes']) ||
$saved_settings['retailcrm_status_changes'] == 0) :
echo 'checked'; endif; ?> />
<?php echo $text_no; ?>
</label>
</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): ?>
@ -510,7 +530,7 @@
<?php endif; ?> <?php endif; ?>
<div class="tab-pane" id="tab-logs"> <div class="tab-pane" id="tab-logs">
<fieldset style="margin-bottom: 30px;"> <fieldset style="margin-bottom: 30px;">
<legend>Retailcrm API error log</legend> <legend>retailCRM API error log</legend>
<div class="retailcrm_unit"> <div class="retailcrm_unit">
<a onclick="confirm('<?php echo $text_confirm_log; ?>') ? location.href='<?php echo $clear_retailcrm; ?>' : false;" data-toggle="tooltip" title="<?php echo $button_clear; ?>" class="btn btn-danger"><i class="fa fa-eraser"></i> <span class="hidden-xs"><?php echo $button_clear; ?></span></a> <a onclick="confirm('<?php echo $text_confirm_log; ?>') ? location.href='<?php echo $clear_retailcrm; ?>' : false;" data-toggle="tooltip" title="<?php echo $button_clear; ?>" class="btn btn-danger"><i class="fa fa-eraser"></i> <span class="hidden-xs"><?php echo $button_clear; ?></span></a>
</div> </div>

View File

@ -108,6 +108,28 @@
</div> </div>
</div> </div>
</fieldset> </fieldset>
<fieldset>
<legend>{{ status_changes }}</legend>
<div class="form-group">
<label class="col-sm-2 control-label" for="module_retailcrm_status_changes">{{ text_status_changes }}</label>
<div class="col-sm-10">
<label class="radio-inline">
<input type="radio" name="module_retailcrm_status_changes" value="1"
{% if saved_settings.retailcrm_status_changes is defined and saved_settings.retailcrm_status_changes == 1 %}
checked
{% endif %} />
{{ text_yes }}
</label>
<label class="radio-inline">
<input type="radio" name="module_retailcrm_status_changes" value="0"
{% if saved_settings.retailcrm_status_changes is not defined or saved_settings.retailcrm_status_changes == 0 %}
checked
{% endif %} />
{{ text_no }}
</label>
</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 %}
@ -161,16 +183,16 @@
<div class="col-sm-10"> <div class="col-sm-10">
<label class="control-label" class="radio-inline"> <label class="control-label" class="radio-inline">
<input type="radio" name="module_retailcrm_order_number" value="1" <input type="radio" name="module_retailcrm_order_number" value="1"
{% if saved_settings.module_retailcrm_order_number is defined and saved_settings.module_retailcrm_order_number == 1 %} {% if saved_settings.module_retailcrm_order_number is defined and saved_settings.module_retailcrm_order_number == 1 %}
checked checked
{% endif %} /> {% endif %} />
{{ text_yes }} {{ text_yes }}
</label> </label>
<label class="control-label" class="radio-inline"> <label class="control-label" class="radio-inline">
<input type="radio" name="module_retailcrm_order_number" value="0" <input type="radio" name="module_retailcrm_order_number" value="0"
{% if saved_settings.module_retailcrm_order_number is not defined or saved_settings.module_retailcrm_order_number == 0 %} {% if saved_settings.module_retailcrm_order_number is not defined or saved_settings.module_retailcrm_order_number == 0 %}
checked checked
{% endif %} /> {% endif %} />
{{ text_no }} {{ text_no }}
</label> </label>
</div> </div>
@ -623,4 +645,4 @@
$('#export_order').button('reset'); $('#export_order').button('reset');
} }
}); });
</script> </script>

View File

@ -31,6 +31,11 @@ class ControllerExtensionModuleRetailcrm extends Controller {
* @return void * @return void
*/ */
public function order_create($trigger, $data, $order_id = null) { public function order_create($trigger, $data, $order_id = null) {
if (ModelExtensionRetailcrmHistoryV45::$history_run === true) {
return;
}
$this->load->model('checkout/order'); $this->load->model('checkout/order');
$this->load->model('account/order'); $this->load->model('account/order');
$this->load->library('retailcrm/retailcrm'); $this->load->library('retailcrm/retailcrm');