diff --git a/admin/controller/module/easy_import_nat.php b/admin/controller/module/easy_import_nat.php index 2d8c18a..0c85f13 100644 --- a/admin/controller/module/easy_import_nat.php +++ b/admin/controller/module/easy_import_nat.php @@ -508,7 +508,7 @@ class EasyImportNat extends \Opencart\System\Engine\Controller { array( 'code' => 'easy_import_nat_product_edit', 'description' => 'Easy Import/Export [NAT] Product Edit Sources', - 'trigger' => 'admin/model/catalog/product.editProduct/after', + 'trigger' => 'admin/model/catalog/product' . $sep . 'editProduct/after', 'action' => 'extension/easy_import_nat/module/easy_import_nat' . $sep . 'eventProductEditAfter', 'status' => 1, 'sort_order' => 1 @@ -516,7 +516,7 @@ class EasyImportNat extends \Opencart\System\Engine\Controller { array( 'code' => 'easy_import_nat_product_delete', 'description' => 'Easy Import/Export [NAT] Product Delete History', - 'trigger' => 'admin/model/catalog/product.deleteProduct/after', + 'trigger' => 'admin/model/catalog/product' . $sep . 'deleteProduct/after', 'action' => 'extension/easy_import_nat/module/easy_import_nat' . $sep . 'eventProductDeleteAfter', 'status' => 1, 'sort_order' => 1 @@ -649,6 +649,150 @@ class EasyImportNat extends \Opencart\System\Engine\Controller { } } + + public function eventProductFormAfter(string &$route, array &$args, string &$output): void { + $product_id = isset($this->request->get['product_id']) ? (int)$this->request->get['product_id'] : 0; + + $nat_sources = ''; + if (isset($this->request->post['nat_sources'])) { + $nat_sources = (string)$this->request->post['nat_sources']; + } elseif ($product_id) { + $q = $this->db->query("SELECT nat_sources FROM `" . DB_PREFIX . "product` WHERE product_id = '" . (int)$product_id . "'"); + if ($q->num_rows) { + $nat_sources = (string)$q->row['nat_sources']; + } + } + $sources_list = array_filter(explode(';', trim($nat_sources, ';'))); + + $history = array(); + if ($product_id) { + try { + $h_depth = (int)$this->config->get('module_easy_import_nat_history_depth'); + if ($h_depth <= 0) $h_depth = 5; + $h_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "easy_import_product_history` WHERE product_id = '" . (int)$product_id . "' ORDER BY date_added DESC, history_id DESC LIMIT " . (int)$h_depth); + $history = $h_query->rows; + } catch (\Throwable $e) {} + } + + $badges_html = ''; + if (!empty($sources_list)) { + foreach ($sources_list as $src) { + $badges_html .= ' ' . htmlspecialchars($src, ENT_QUOTES, 'UTF-8') . ' '; + } + } else { + $badges_html = '—'; + } + + $form_html = ' +
+ +
+
' . $badges_html . '
+ +
Формат: ;supplier1;supplier2; (разделитель точка с запятой)
+
+
'; + + if (!empty($history)) { + $batches_seen = array(); + $batch_options = ''; + foreach ($history as $h) { + if (!empty($h['batch_name']) && !in_array($h['batch_name'], $batches_seen)) { + $batches_seen[] = $h['batch_name']; + $batch_options .= ''; + } + } + + $rows_html = ''; + foreach ($history as $h) { + $b_name = htmlspecialchars($h['batch_name'], ENT_QUOTES, 'UTF-8'); + $b_badge = $h['batch_name'] ? ' ' . $b_name . '' : '—'; + $price_fmt = number_format((float)$h['price'], 2, '.', ''); + $special_fmt = ($h['special'] !== null && $h['special'] !== '') ? '' . number_format((float)$h['special'], 2, '.', '') . '' : '—'; + $qty_badge = ((int)$h['quantity'] > 0) ? '' . (int)$h['quantity'] . '' : '0'; + $stat_badge = ((int)$h['status'] == 1) ? 'Вкл' : 'Откл'; + + $rows_html .= ' + ' . htmlspecialchars($h['date_added'], ENT_QUOTES, 'UTF-8') . ' + ' . $b_badge . ' + ' . $price_fmt . ' + ' . $special_fmt . ' + ' . $qty_badge . ' + ' . $stat_badge . ' + '; + } + + $form_html .= ' +
+ +
+
+
+
+ + +
+
+ Последние изменения (макс. ' . count($history) . ') +
+
+
+ + + + + + + + + + + + ' . $rows_html . ' +
Дата / Время Поставщик (Batch) Цена Акция Остаток Статус
+
+
+
+
+ '; + } + + if (preg_match('#]*class=[\'"][^\'"]*tab-pane[^\'"]*[\'"][^>]*id=[\'"]tab-(seo|links|design|option|attribute)[\'"]|id=[\'"]tab-(seo|links|design)[\'"][^>]*class=[\'"][^\'"]*tab-pane#i', $output, $m, PREG_OFFSET_CAPTURE)) { + $output = substr_replace($output, $form_html, $m[0][1], 0); + } elseif (preg_match('##i', $output, $m, PREG_OFFSET_CAPTURE)) { + $output = substr_replace($output, $form_html, $m[0][1], 0); + } + } + + public function eventProductEditAfter(string &$route, array &$args, mixed &$output): void { + if (isset($args[0]) && isset($args[1]['nat_sources'])) { + $product_id = (int)$args[0]; + $this->db->query("UPDATE `" . DB_PREFIX . "product` SET nat_sources = '" . $this->db->escape($args[1]['nat_sources']) . "' WHERE product_id = '" . $product_id . "'"); + } + } + + public function eventProductDeleteAfter(string &$route, array &$args, mixed &$output): void { + if (isset($args[0])) { + $product_id = (int)$args[0]; + try { + $this->db->query("DELETE FROM `" . DB_PREFIX . "easy_import_product_history` WHERE product_id = '" . $product_id . "'"); + } catch (\Throwable $e) {} + } + } + public function backup() { if (!isset($this->request->get['user_token']) || !isset($this->session->data['user_token']) || $this->request->get['user_token'] !== $this->session->data['user_token'] || !$this->user->hasPermission('modify', 'extension/easy_import_nat/module/easy_import_nat')) { $this->load->language('extension/easy_import_nat/module/easy_import_nat'); @@ -1656,6 +1800,9 @@ public function importProcessChunk() { $ident_key = trim((string)$header[$ident_col]); $count = 0; + if ($batch === 1) { + try { $this->model_extension_easy_import_nat_module_easy_import_nat->pruneProductHistory(60); } catch (\Throwable $e) {} + } if ($batch === 1 && file_exists(DIR_CACHE . 'nat_import_log.txt')) { @file_put_contents(DIR_CACHE . 'nat_import_log.txt', "--- IMPORT STARTED [" . date('Y-m-d H:i:s') . "] ---\n"); } diff --git a/catalog/controller/module/easy_import_nat_cron.php b/catalog/controller/module/easy_import_nat_cron.php index 12c21ec..1b781f6 100644 --- a/catalog/controller/module/easy_import_nat_cron.php +++ b/catalog/controller/module/easy_import_nat_cron.php @@ -702,6 +702,7 @@ class EasyImportNatCron extends \Opencart\System\Engine\Controller { $col_binding = isset($settings['col_binding']) && is_array($settings['col_binding']) ? $settings['col_binding'] : array(); + try { $model->pruneProductHistory(60); } catch (\Throwable $e) {} $batch_name_default = isset($settings['import_batch_name']) ? preg_replace('/[^a-zA-Z0-9_\-]/', '', $settings['import_batch_name']) : ''; $missing_action = isset($settings['missing_action']) ? preg_replace('/[^a-zA-Z_]/', '', $settings['missing_action']) : 'skip'; $log_mode = isset($settings['log_mode']) ? preg_replace('/[^a-zA-Z_]/', '', $settings['log_mode']) : 'changes'; diff --git a/easy_import_export_nat_OC_40_1_0.ocmod.zip b/easy_import_export_nat_OC_40_1_0.ocmod.zip index 6971ed7..f756fc8 100644 Binary files a/easy_import_export_nat_OC_40_1_0.ocmod.zip and b/easy_import_export_nat_OC_40_1_0.ocmod.zip differ diff --git a/easy_import_nat.ocmod.zip b/easy_import_nat.ocmod.zip index 6971ed7..f756fc8 100644 Binary files a/easy_import_nat.ocmod.zip and b/easy_import_nat.ocmod.zip differ