From cd242097fe63c2e009d3ae5e22ec85bfbc1e6703 Mon Sep 17 00:00:00 2001 From: nertyog Date: Mon, 12 Oct 2026 04:58:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20Promo=20Top=20Bar=20NAT=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20OpenCart=204.1.x=20(PSR-4,=20Events,=20Gatekeeper=20V5?= =?UTF-8?q?=20Final,=20Anti-Zombie)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/controller/module/promo_top_bar_nat.php | 1160 ++++ .../en-gb/module/promo_top_bar_nat.php | 316 ++ .../ru-ru/module/promo_top_bar_nat.php | 316 ++ .../uk-ua/module/promo_top_bar_nat.php | 316 ++ admin/model/module/promo_top_bar_nat.php | 38 + .../template/module/promo_top_bar_nat.twig | 5014 +++++++++++++++++ .../controller/module/promo_top_bar_nat.php | 861 +++ .../en-gb/module/promo_top_bar_nat.php | 13 + .../ru-ru/module/promo_top_bar_nat.php | 13 + .../uk-ua/module/promo_top_bar_nat.php | 13 + catalog/model/module/promo_top_bar_nat.php | 15 + .../template/module/promo_top_bar_nat.twig | 1361 +++++ install.json | 7 + promo_top_bar_nat.ocmod.zip | Bin 0 -> 103149 bytes 14 files changed, 9443 insertions(+) create mode 100644 admin/controller/module/promo_top_bar_nat.php create mode 100644 admin/language/en-gb/module/promo_top_bar_nat.php create mode 100644 admin/language/ru-ru/module/promo_top_bar_nat.php create mode 100644 admin/language/uk-ua/module/promo_top_bar_nat.php create mode 100644 admin/model/module/promo_top_bar_nat.php create mode 100644 admin/view/template/module/promo_top_bar_nat.twig create mode 100644 catalog/controller/module/promo_top_bar_nat.php create mode 100644 catalog/language/en-gb/module/promo_top_bar_nat.php create mode 100644 catalog/language/ru-ru/module/promo_top_bar_nat.php create mode 100644 catalog/language/uk-ua/module/promo_top_bar_nat.php create mode 100644 catalog/model/module/promo_top_bar_nat.php create mode 100644 catalog/view/template/module/promo_top_bar_nat.twig create mode 100644 install.json create mode 100644 promo_top_bar_nat.ocmod.zip diff --git a/admin/controller/module/promo_top_bar_nat.php b/admin/controller/module/promo_top_bar_nat.php new file mode 100644 index 0000000..14f64c3 --- /dev/null +++ b/admin/controller/module/promo_top_bar_nat.php @@ -0,0 +1,1160 @@ +db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "promo_top_bar_stats_nat` ( + `stat_id` INT(11) NOT NULL AUTO_INCREMENT, + `slide_id` VARCHAR(64) NOT NULL, + `action` VARCHAR(16) NOT NULL, + `date_added` DATE NOT NULL, + `count` INT(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`stat_id`), + UNIQUE KEY `slide_action_date` (`slide_id`, `action`, `date_added`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); + + $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "promo_top_bar_lead_nat` ( + `lead_id` INT(11) NOT NULL AUTO_INCREMENT, + `email` VARCHAR(150) NOT NULL, + `store_id` INT(11) NOT NULL DEFAULT 0, + `date_added` DATETIME NOT NULL, + PRIMARY KEY (`lead_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); + + $chk_store_id = $this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "promo_top_bar_lead_nat` LIKE 'store_id'"); + if (!$chk_store_id->num_rows) { + $this->db->query("ALTER TABLE `" . DB_PREFIX . "promo_top_bar_lead_nat` ADD `store_id` INT(11) NOT NULL DEFAULT 0 AFTER `email`"); + } + $this->load->model('localisation/language'); + + $languages = $this->model_localisation_language->getLanguages(); + + $demo_slides = []; + + // Demo Slide 1: Welcome message with coupon and countdown timer + $slide1_blocks = [ + [ + 'type' => 'text', + 'text' => [], + 'mobile_text' => [], + 'color' => '#ffffff', + 'animation' => '' + ], + [ + 'type' => 'coupon', + 'coupon_text' => [], + 'coupon_code' => [], + 'coupon_tooltip' => [] + ], + [ + 'type' => 'timer', + 'timer_mode' => 'evergreen', + 'timer_minutes' => '15', + 'timer_date' => '', + 'timer_color' => '#ffffff', + 'timer_bg' => '#e74c3c' + ] + ]; + + foreach ($languages as $lang) { + $lang_id = $lang['language_id']; + $slide1_blocks[0]['text'][$lang_id] = base64_encode('Добро пожаловать в наш магазин! Скидка по промокоду:'); + $slide1_blocks[0]['mobile_text'][$lang_id] = base64_encode('Скидка по промокоду:'); + $slide1_blocks[1]['coupon_text'][$lang_id] = base64_encode('WELCOME10'); + $slide1_blocks[1]['coupon_code'][$lang_id] = base64_encode('WELCOME10'); + $slide1_blocks[1]['coupon_tooltip'][$lang_id] = base64_encode('Скопировано!'); + } + + $demo_slides[] = [ + 'status' => '0', + 'sort_order' => '1', + 'bg_type' => 'color', + 'bg_color' => '#2c3e50', + 'bg_pattern' => '', + 'bg_pattern_opacity' => '0.1', + 'bg_gradient' => '', + 'gradient_color1' => '#2c3e50', + 'gradient_color2' => '#3498db', + 'gradient_angle' => '90', + 'gradient_type' => 'linear', + 'gradient_animated' => '0', + 'gradient_anim_speed' => '15', + 'color' => '#ffffff', + 'font_family' => 'Inter', + 'link' => [], + 'full_slide_link' => '0', + 'customer_groups' => [], + 'visitor_type' => 'all', + 'stores' => [], + 'referer_mode' => 'all', + 'referer_custom' => '', + 'utm_mode' => 'all', + 'utm_custom' => '', + 'schedule_status' => '0', + 'schedule_days' => [], + 'schedule_time_start' => '00:00', + 'schedule_time_end' => '23:59', + 'cart_status' => '0', + 'cart_min' => '0', + 'cart_max' => '0', + 'cart_products' => [], + 'weather_status' => 'off', + 'device_status' => '0', + 'device_types' => [], + 'device_browsers' => [], + 'device_os' => [], + 'custom_css' => '', + 'marquee_status' => '0', + 'marquee_speed' => '15', + 'show_close' => '1', + 'show_desktop' => '1', + 'show_mobile' => '1', + 'height' => '', + 'padding_top' => '0', + 'padding_bottom' => '0', + 'link_utm' => '', + 'blocks' => $slide1_blocks + ]; + + // Demo Slide 2: Free Shipping Progress Bar + $slide2_blocks = [ + [ + 'type' => 'shipping', + 'shipping_total' => '5000', + 'shipping_text_before' => [], + 'shipping_text_after' => [], + 'color_fill' => '#2ecc71', + 'color_bg' => '#34495e', + 'color_text' => '#ffffff' + ] + ]; + + foreach ($languages as $lang) { + $lang_id = $lang['language_id']; + $slide2_blocks[0]['shipping_text_before'][$lang_id] = base64_encode('Добавьте товаров еще на {diff} для бесплатной доставки!'); + $slide2_blocks[0]['shipping_text_after'][$lang_id] = base64_encode('Поздравляем! У вас бесплатная доставка!'); + } + + $demo_slides[] = [ + 'status' => '0', + 'sort_order' => '2', + 'bg_type' => 'gradient', + 'bg_color' => '#2980b9', + 'bg_pattern' => '', + 'bg_pattern_opacity' => '0.1', + 'bg_gradient' => 'linear-gradient(90deg, #8e44ad 0%, #2980b9 100%)', + 'gradient_color1' => '#8e44ad', + 'gradient_color2' => '#2980b9', + 'gradient_angle' => '90', + 'gradient_type' => 'linear', + 'gradient_animated' => '0', + 'gradient_anim_speed' => '15', + 'color' => '#ffffff', + 'font_family' => 'Montserrat', + 'link' => [], + 'full_slide_link' => '0', + 'customer_groups' => [], + 'visitor_type' => 'all', + 'stores' => [], + 'referer_mode' => 'all', + 'referer_custom' => '', + 'utm_mode' => 'all', + 'utm_custom' => '', + 'schedule_status' => '0', + 'schedule_days' => [], + 'schedule_time_start' => '00:00', + 'schedule_time_end' => '23:59', + 'cart_status' => '0', + 'cart_min' => '0', + 'cart_max' => '0', + 'cart_products' => [], + 'weather_status' => 'off', + 'device_status' => '0', + 'device_types' => [], + 'device_browsers' => [], + 'device_os' => [], + 'custom_css' => '', + 'marquee_status' => '0', + 'marquee_speed' => '15', + 'show_close' => '1', + 'show_desktop' => '1', + 'show_mobile' => '1', + 'height' => '', + 'padding_top' => '0', + 'padding_bottom' => '0', + 'link_utm' => '', + 'blocks' => $slide2_blocks + ]; + + foreach ($languages as $lang) { + foreach ($demo_slides as $k => $ds) { + $demo_slides[$k]['link'][$lang['language_id']] = ''; + } + } + + $defaults = [ + 'module_promo_top_bar_nat_status' => '0', + 'module_promo_top_bar_nat_display_method' => 'everywhere', + 'module_promo_top_bar_nat_exclude_pages' => "checkout/checkout\ncheckout/cart\ncheckout/simplecheckout", + 'module_promo_top_bar_nat_layout' => 'standard', + 'module_promo_top_bar_nat_show_close' => '1', + 'module_promo_top_bar_nat_cookie_expiry' => '1', + 'module_promo_top_bar_nat_show_desktop' => '1', + 'module_promo_top_bar_nat_show_mobile' => '1', + 'module_promo_top_bar_nat_height' => '45px', + 'module_promo_top_bar_nat_border_radius' => '0px', + 'module_promo_top_bar_nat_shadow' => 'none', + 'module_promo_top_bar_nat_shadow_custom' => '', + 'module_promo_top_bar_nat_slider_autoplay' => '1', + 'module_promo_top_bar_nat_slider_speed' => '4000', + 'module_promo_top_bar_nat_slider_arrows' => '1', + 'module_promo_top_bar_nat_slider_dots' => '0', + 'module_promo_top_bar_nat_slider_animation' => 'slide', + 'module_promo_top_bar_nat_ab_testing' => '0', + 'module_promo_top_bar_nat_custom_font_name' => '', + 'module_promo_top_bar_nat_custom_font_url' => '', + 'module_promo_top_bar_nat_menu_position' => 'both', + 'module_promo_top_bar_nat_slides' => json_encode($demo_slides) + ]; + + $this->model_setting_setting->editSetting('module_promo_top_bar_nat', $defaults); + + $this->load->model('user/user_group'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/promo_top_bar_nat/module/promo_top_bar_nat'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/promo_top_bar_nat/module/promo_top_bar_nat'); + + $this->load->model('extension/promo_top_bar_nat/module/promo_top_bar_nat'); + $this->model_extension_promo_top_bar_nat_module_promo_top_bar_nat->install(); + + $sep = '.'; + $this->load->model('setting/event'); + $events = [ + [ + 'code' => 'promo_top_bar_nat_menu', + 'description' => 'Promo Top Bar NAT: Sidebar Menu Injection', + 'trigger' => 'admin/view/common/column_left/before', + 'action' => 'extension/promo_top_bar_nat/module/promo_top_bar_nat' . $sep . 'injectMenu', + 'status' => 1, + 'sort_order' => 1 + ], + [ + 'code' => 'promo_top_bar_nat_header', + 'description' => 'Promo Top Bar NAT: Header Button Injection', + 'trigger' => 'admin/view/common/header/after', + 'action' => 'extension/promo_top_bar_nat/module/promo_top_bar_nat' . $sep . 'injectHeader', + 'status' => 1, + 'sort_order' => 1 + ], + [ + 'code' => 'promo_top_bar_nat_catalog', + 'description' => 'Promo Top Bar NAT: Catalog Top Bar Injection', + 'trigger' => 'catalog/view/common/header/after', + 'action' => 'extension/promo_top_bar_nat/module/promo_top_bar_nat' . $sep . 'injectCatalogHeader', + 'status' => 1, + 'sort_order' => 1 + ] + ]; + + $ref = new \ReflectionMethod($this->model_setting_event, 'addEvent'); + $is_array_sig = ($ref->getNumberOfParameters() === 1); + foreach ($events as $ev) { + $this->model_setting_event->deleteEventByCode($ev['code']); + if ($is_array_sig) { + $this->model_setting_event->addEvent($ev); + } else { + $this->model_setting_event->addEvent($ev['code'], $ev['description'], $ev['trigger'], $ev['action'], (bool)$ev['status'], (int)$ev['sort_order']); + } + } + } + + public function uninstall(): void { + $this->load->model('extension/promo_top_bar_nat/module/promo_top_bar_nat'); + $this->model_extension_promo_top_bar_nat_module_promo_top_bar_nat->uninstall(); + + $this->load->model('setting/event'); + $this->model_setting_event->deleteEventByCode('promo_top_bar_nat_menu'); + $this->model_setting_event->deleteEventByCode('promo_top_bar_nat_header'); + $this->model_setting_event->deleteEventByCode('promo_top_bar_nat_catalog'); + $this->model_setting_event->deleteEventByCode('promo_top_bar_nat'); + } + + public function index(): void { + $this->load->language('extension/promo_top_bar_nat/module/promo_top_bar_nat'); + if ($this->language->get('heading_title_raw')) { + $this->document->setTitle($this->language->get('heading_title_raw')); + } else { + $this->document->setTitle(strip_tags($this->language->get('heading_title'))); + } + $this->load->model('setting/setting'); + + $this->load->model('tool/image'); + $this->load->model('localisation/language'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (isset($this->request->post['module_promo_top_bar_nat_slides_json'])) { + $slides = json_decode(html_entity_decode($this->request->post['module_promo_top_bar_nat_slides_json'], ENT_QUOTES, 'UTF-8'), true); + if (is_array($slides)) { + $this->request->post['module_promo_top_bar_nat_slides'] = $this->encodeSlides($slides); + } + unset($this->request->post['module_promo_top_bar_nat_slides_json']); + } elseif (isset($this->request->post['module_promo_top_bar_nat_slides']) && is_array($this->request->post['module_promo_top_bar_nat_slides'])) { + $this->request->post['module_promo_top_bar_nat_slides'] = $this->encodeSlides($this->request->post['module_promo_top_bar_nat_slides']); + } + + $posted_lic = isset($this->request->post['module_promo_top_bar_nat_license']) ? trim((string)$this->request->post['module_promo_top_bar_nat_license']) : ''; + $this->request->post['module_promo_top_bar_nat_license'] = $posted_lic; + + // Штатное сохранение настроек модуля + $this->model_setting_setting->editSetting('module_promo_top_bar_nat', $this->request->post); + + if ($posted_lic === '') { + // Пользователь удалил ключ — стираем бэкап модуля, исключая зомби-восстановление! + $this->model_setting_setting->deleteSetting('nat_promo_top_bar_backup'); + } else { + // Сохраняем актуальный бэкап при наличии ключа + $this->model_setting_setting->editSetting('nat_promo_top_bar_backup', $this->request->post); + } + + $this->session->data['success'] = $this->language->get('text_success'); + $this->response->redirect($this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat', 'user_token=' . $this->session->data['user_token'], true)); + } + + // Auto-restore ONLY upon clean first installation (Anti-Zombie Architecture) + $current_lic = (string)$this->config->get('module_promo_top_bar_nat_license'); + $has_deliberate_setting = ($this->config->get('module_promo_top_bar_nat_license') !== null); + + if (!$has_deliberate_setting && (empty($current_lic) || !$this->checkLicense($current_lic))) { + $bk_set = $this->model_setting_setting->getSetting('nat_promo_top_bar_backup'); + if (!empty($bk_set) && is_array($bk_set) && !empty($bk_set['module_promo_top_bar_nat_license'])) { + $this->model_setting_setting->editSetting('module_promo_top_bar_nat', $bk_set); + foreach ($bk_set as $rk => $rv) { + $this->config->set($rk, $rv); + } + } + } + + $sep = '.'; + $data['oc4_sep'] = $sep; + $data = $this->getErrors(); + $data['heading_title'] = $this->language->get('heading_title'); + $data['heading_title_raw'] = $this->language->get('heading_title_raw') ? $this->language->get('heading_title_raw') : strip_tags($this->language->get('heading_title')); + $data['breadcrumbs'] = $this->getBreadcrumbs(); + + $data['action'] = $this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat', 'user_token=' . $this->session->data['user_token'], true); + $data['save'] = $this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat' . $sep . 'save', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + $data['back'] = $data['cancel']; + + $data['user_token'] = $this->session->data['user_token']; + + // Get languages + $data['languages'] = array_values($this->model_localisation_language->getLanguages()); + + // Get system manufacturers for slide link select dropdown + $this->load->model('catalog/manufacturer'); + $manufacturers = $this->model_catalog_manufacturer->getManufacturers([]); + $data['system_manufacturers'] = []; + foreach ($manufacturers as $m) { + $data['system_manufacturers'][] = [ + 'manufacturer_id' => $m['manufacturer_id'], + 'name' => $m['name'] + ]; + } + + // Leads URLs & Query + $data['delete_lead'] = $this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat' . $sep . 'delete_lead', 'user_token=' . $this->session->data['user_token'], true); + $data['export_leads'] = $this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat' . $sep . 'export_leads_csv', 'user_token=' . $this->session->data['user_token'], true); + + $data['leads'] = []; + $leads_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "promo_top_bar_lead_nat` ORDER BY date_added DESC"); + foreach ($leads_query->rows as $row) { + $data['leads'][] = [ + 'lead_id' => $row['lead_id'], + 'email' => $row['email'], + 'store_id' => $row['store_id'], + 'date_added' => $row['date_added'] + ]; + } + + // Get customer groups + $this->load->model('customer/customer_group'); + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + // Get stores + $this->load->model('setting/store'); + $stores = $this->model_setting_store->getStores(); + $data['stores'] = []; + $data['stores'][] = [ + 'store_id' => 0, + 'name' => $this->config->get('config_name') . ' ' . $this->language->get('text_default') + ]; + foreach ($stores as $store) { + $data['stores'][] = [ + 'store_id' => $store['store_id'], + 'name' => $store['name'] + ]; + } + + // Get system categories and information pages + $this->load->model('catalog/category'); + $categories = $this->model_catalog_category->getCategories([]); + $data['system_categories'] = []; + foreach ($categories as $cat) { + $data['system_categories'][] = [ + 'category_id' => $cat['category_id'], + 'name' => $cat['name'] + ]; + } + + $this->load->model('catalog/information'); + $informations = $this->model_catalog_information->getInformations([]); + $data['system_informations'] = []; + foreach ($informations as $info) { + $data['system_informations'][] = [ + 'information_id' => $info['information_id'], + 'title' => $info['title'] + ]; + } + + // Standard settings fields + $fields = [ + 'module_promo_top_bar_nat_status', + 'module_promo_top_bar_nat_menu_position', + 'module_promo_top_bar_nat_display_method', + 'module_promo_top_bar_nat_exclude_pages', + 'module_promo_top_bar_nat_layout', + 'module_promo_top_bar_nat_show_close', + 'module_promo_top_bar_nat_cookie_expiry', + 'module_promo_top_bar_nat_show_desktop', + 'module_promo_top_bar_nat_show_mobile', + 'module_promo_top_bar_nat_height', + 'module_promo_top_bar_nat_border_radius', + 'module_promo_top_bar_nat_shadow', + 'module_promo_top_bar_nat_shadow_custom', + 'module_promo_top_bar_nat_slider_autoplay', + 'module_promo_top_bar_nat_slider_speed', + 'module_promo_top_bar_nat_slider_arrows', + 'module_promo_top_bar_nat_slider_dots', + 'module_promo_top_bar_nat_slider_animation', + 'module_promo_top_bar_nat_ab_testing', + 'module_promo_top_bar_nat_custom_font_name', + 'module_promo_top_bar_nat_custom_font_url', + 'module_promo_top_bar_nat_license' + ]; + + foreach ($fields as $field) { + $data[$field] = $this->request->post[$field] ?? $this->config->get($field); + } + + // Process slides + if (isset($this->request->post['module_promo_top_bar_nat_slides'])) { + $slides = $this->encodeSlides($this->request->post['module_promo_top_bar_nat_slides']); + $slides = $this->decodeSlides($slides); + } else { + $slides = $this->config->get('module_promo_top_bar_nat_slides'); + $slides = $this->decodeSlides($slides); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + // Stats integration + $data['reset_stats'] = $this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat' . $sep . 'reset_stats', 'user_token=' . $this->session->data['user_token'], true); + $data['export_stats'] = $this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat' . $sep . 'export_stats_csv', 'user_token=' . $this->session->data['user_token'], true); + + $data['stats'] = []; + $query = $this->db->query("SELECT slide_id, action, SUM(count) as total FROM `" . DB_PREFIX . "promo_top_bar_stats_nat` GROUP BY slide_id, action"); + $stats_raw = []; + foreach ($query->rows as $row) { + $stats_raw[$row['slide_id']][$row['action']] = (int)$row['total']; + } + + if (is_array($slides)) { + foreach ($slides as $idx => $slide) { + $slide_id = $slide['slide_id'] ?? ''; + if (!$slide_id) continue; + + $views = $stats_raw[$slide_id]['view'] ?? 0; + $clicks = $stats_raw[$slide_id]['click'] ?? 0; + $closes = $stats_raw[$slide_id]['close'] ?? 0; + $ctr = $views > 0 ? round(($clicks / $views) * 100, 2) : 0.00; + $close_rate = $views > 0 ? round(($closes / $views) * 100, 2) : 0.00; + + $title = $this->language->get('text_slide_prefix') . ($idx + 1); + if (isset($slide['blocks']) && is_array($slide['blocks'])) { + foreach ($slide['blocks'] as $block) { + if ($block['type'] === 'text') { + $keys = array_keys($block['text']); + $firstLang = $keys[0] ?? ''; + if ($firstLang && !empty($block['text'][$firstLang])) { + $trimmedText = mb_substr($block['text'][$firstLang], 0, 25, 'UTF-8'); + $title = $this->language->get('text_block_text_prefix') . $trimmedText . (mb_strlen($block['text'][$firstLang]) > 25 ? '...' : '') . '"'; + break; + } + } + } + } + + $data['stats'][] = [ + 'slide_id' => $slide_id, + 'title' => $title, + 'views' => $views, + 'clicks' => $clicks, + 'closes' => $closes, + 'ctr' => $ctr . '%', + 'close_rate'=> $close_rate . '%' + ]; + } + } + + // Build slide image thumbs + if (is_array($slides)) { + foreach ($slides as $i => $slide) { + // Bg Pattern + if (!empty($slide['bg_pattern']) && is_file(DIR_IMAGE . $slide['bg_pattern'])) { + $slides[$i]['thumb_bg_pattern'] = $this->model_tool_image->resize($slide['bg_pattern'], 100, 100); + } else { + $slides[$i]['thumb_bg_pattern'] = $data['placeholder']; + } + + // Blocks images + if (isset($slide['blocks']) && is_array($slide['blocks'])) { + foreach ($slide['blocks'] as $j => $block) { + if ($block['type'] === 'image') { + $slides[$i]['blocks'][$j]['thumb'] = []; + foreach ($data['languages'] as $lang) { + $img_val = isset($block['image'][$lang['language_id']]) ? $block['image'][$lang['language_id']] : ''; + if (!empty($img_val) && is_file(DIR_IMAGE . $img_val)) { + $slides[$i]['blocks'][$j]['thumb'][$lang['language_id']] = $this->model_tool_image->resize($img_val, 100, 100); + } else { + $slides[$i]['blocks'][$j]['thumb'][$lang['language_id']] = $data['placeholder']; + } + } + } + } + } + } + } + + $data['module_promo_top_bar_nat_slides'] = $slides; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + // Гарантированная передача переменных в шаблон: + $data['user_token'] = $this->session->data['user_token']; + $_h = defined('HTTP_CATALOG') ? parse_url(HTTP_CATALOG, PHP_URL_HOST) : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''); + $_h = preg_replace('/:\d+$/', '', trim((string)$_h)); + $_h = preg_replace('/^www\./i', '', $_h); + $data['nat_current_domain'] = strtolower($_h); + $data['is_licensed'] = $this->checkLicense((string)$this->config->get('module_promo_top_bar_nat_license')); + + // --- NAT Unified License Card: module type --- + $data['is_free_module'] = false; // true для free, false для paid + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/promo_top_bar_nat/module/promo_top_bar_nat', $data)); + } + + public function save(): void { + $this->load->language('extension/promo_top_bar_nat/module/promo_top_bar_nat'); + $json = []; + + if (!$this->user->hasPermission('modify', 'extension/promo_top_bar_nat/module/promo_top_bar_nat')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!$json) { + if (isset($this->request->post['module_promo_top_bar_nat_slides_json'])) { + $slides = json_decode(html_entity_decode($this->request->post['module_promo_top_bar_nat_slides_json'], ENT_QUOTES, 'UTF-8'), true); + if (is_array($slides)) { + $this->request->post['module_promo_top_bar_nat_slides'] = $this->encodeSlides($slides); + } + unset($this->request->post['module_promo_top_bar_nat_slides_json']); + } elseif (isset($this->request->post['module_promo_top_bar_nat_slides']) && is_array($this->request->post['module_promo_top_bar_nat_slides'])) { + $this->request->post['module_promo_top_bar_nat_slides'] = $this->encodeSlides($this->request->post['module_promo_top_bar_nat_slides']); + } + + $this->load->model('setting/setting'); + + $posted_lic = isset($this->request->post['module_promo_top_bar_nat_license']) ? trim((string)$this->request->post['module_promo_top_bar_nat_license']) : ''; + $this->request->post['module_promo_top_bar_nat_license'] = $posted_lic; + + $this->model_setting_setting->editSetting('module_promo_top_bar_nat', $this->request->post); + + if ($posted_lic === '') { + $this->model_setting_setting->deleteSetting('nat_promo_top_bar_backup'); + } else { + $this->model_setting_setting->editSetting('nat_promo_top_bar_backup', $this->request->post); + } + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function get_slide_stats(): void { + $this->load->language('extension/promo_top_bar_nat/module/promo_top_bar_nat'); + $json = []; + + $slide_id = isset($this->request->get['slide_id']) ? trim($this->request->get['slide_id']) : ''; + + if ($slide_id && $this->validate()) { + $query = $this->db->query("SELECT date_added, + SUM(IF(action = 'view', count, 0)) as views, + SUM(IF(action = 'click', count, 0)) as clicks, + SUM(IF(action = 'close', count, 0)) as closes + FROM `" . DB_PREFIX . "promo_top_bar_stats_nat` + WHERE slide_id = '" . $this->db->escape($slide_id) . "' + GROUP BY date_added + ORDER BY date_added DESC + LIMIT 30"); + + $json['success'] = true; + $json['stats'] = []; + foreach ($query->rows as $row) { + $views = (int)$row['views']; + $clicks = (int)$row['clicks']; + $closes = (int)$row['closes']; + $ctr = $views > 0 ? round(($clicks / $views) * 100, 2) : 0.00; + + $json['stats'][] = [ + 'date' => date($this->language->get('date_format_short'), strtotime($row['date_added'])), + 'date_added' => date($this->language->get('date_format_short'), strtotime($row['date_added'])), + 'views' => $views, + 'clicks' => $clicks, + 'closes' => $closes, + 'ctr' => $ctr . '%' + ]; + } + } else { + $json['error'] = $this->language->get('error_permission'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + private function encodeSlides($slides): array { + if (is_string($slides)) { + $slides = json_decode($slides, true); + } + if (!is_array($slides)) { + return []; + } + foreach ($slides as $i => $slide) { + if (isset($slide['blocks']) && is_array($slide['blocks'])) { + foreach ($slide['blocks'] as $j => $block) { + if ($block['type'] === 'text') { + if (isset($block['text']) && is_array($block['text'])) { + foreach ($block['text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['text'][$lang_id] = base64_encode($val); + } + } + if (isset($block['mobile_text']) && is_array($block['mobile_text'])) { + foreach ($block['mobile_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['mobile_text'][$lang_id] = base64_encode($val); + } + } + } elseif ($block['type'] === 'image') { + if (isset($block['alt']) && is_array($block['alt'])) { + foreach ($block['alt'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['alt'][$lang_id] = base64_encode($val); + } + } + } elseif ($block['type'] === 'button') { + if (isset($block['text']) && is_array($block['text'])) { + foreach ($block['text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['text'][$lang_id] = base64_encode($val); + } + } + if (isset($block['badge_text']) && is_array($block['badge_text'])) { + foreach ($block['badge_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['badge_text'][$lang_id] = base64_encode($val); + } + } + } elseif ($block['type'] === 'timer') { + if (isset($block['timer_fallback_text']) && is_array($block['timer_fallback_text'])) { + foreach ($block['timer_fallback_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['timer_fallback_text'][$lang_id] = base64_encode($val); + } + } + } elseif ($block['type'] === 'shipping') { + if (isset($block['shipping_text_before']) && is_array($block['shipping_text_before'])) { + foreach ($block['shipping_text_before'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['shipping_text_before'][$lang_id] = base64_encode($val); + } + } + if (isset($block['shipping_text_after']) && is_array($block['shipping_text_after'])) { + foreach ($block['shipping_text_after'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['shipping_text_after'][$lang_id] = base64_encode($val); + } + } + } elseif ($block['type'] === 'subscribe') { + if (isset($block['subscribe_placeholder']) && is_array($block['subscribe_placeholder'])) { + foreach ($block['subscribe_placeholder'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['subscribe_placeholder'][$lang_id] = base64_encode($val); + } + } + if (isset($block['subscribe_button_text']) && is_array($block['subscribe_button_text'])) { + foreach ($block['subscribe_button_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['subscribe_button_text'][$lang_id] = base64_encode($val); + } + } + if (isset($block['subscribe_success_msg']) && is_array($block['subscribe_success_msg'])) { + foreach ($block['subscribe_success_msg'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['subscribe_success_msg'][$lang_id] = base64_encode($val); + } + } + } elseif ($block['type'] === 'coupon') { + if (isset($block['coupon_text']) && is_array($block['coupon_text'])) { + foreach ($block['coupon_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['coupon_text'][$lang_id] = base64_encode($val); + } + } + if (isset($block['coupon_code']) && is_array($block['coupon_code'])) { + foreach ($block['coupon_code'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['coupon_code'][$lang_id] = base64_encode($val); + } + } + if (isset($block['coupon_tooltip']) && is_array($block['coupon_tooltip'])) { + foreach ($block['coupon_tooltip'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['coupon_tooltip'][$lang_id] = base64_encode($val); + } + } + } elseif ($block['type'] === 'activity') { + if (isset($block['activity_text']) && is_array($block['activity_text'])) { + foreach ($block['activity_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['activity_text'][$lang_id] = base64_encode($val); + } + } + } elseif ($block['type'] === 'product') { + if (isset($block['product_button_text']) && is_array($block['product_button_text'])) { + foreach ($block['product_button_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['product_button_text'][$lang_id] = base64_encode($val); + } + } + } + } + } + } + return $slides; + } + + private function decodeSlides($slides): array { + if (is_string($slides)) { + $slides = json_decode($slides, true); + } + if (!is_array($slides)) { + return []; + } + foreach ($slides as $i => $slide) { + if (isset($slide['blocks']) && is_array($slide['blocks'])) { + foreach ($slide['blocks'] as $j => $block) { + if ($block['type'] === 'text') { + if (isset($block['text']) && is_array($block['text'])) { + foreach ($block['text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['text'][$lang_id] = base64_decode($val); + } + } + if (isset($block['mobile_text']) && is_array($block['mobile_text'])) { + foreach ($block['mobile_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['mobile_text'][$lang_id] = base64_decode($val); + } + } + } elseif ($block['type'] === 'image') { + if (isset($block['alt']) && is_array($block['alt'])) { + foreach ($block['alt'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['alt'][$lang_id] = base64_decode($val); + } + } + } elseif ($block['type'] === 'button') { + if (isset($block['text']) && is_array($block['text'])) { + foreach ($block['text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['text'][$lang_id] = base64_decode($val); + } + } + if (isset($block['badge_text']) && is_array($block['badge_text'])) { + foreach ($block['badge_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['badge_text'][$lang_id] = base64_decode($val); + } + } + } elseif ($block['type'] === 'timer') { + if (isset($block['timer_fallback_text']) && is_array($block['timer_fallback_text'])) { + foreach ($block['timer_fallback_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['timer_fallback_text'][$lang_id] = base64_decode($val); + } + } + } elseif ($block['type'] === 'shipping') { + if (isset($block['shipping_text_before']) && is_array($block['shipping_text_before'])) { + foreach ($block['shipping_text_before'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['shipping_text_before'][$lang_id] = base64_decode($val); + } + } + if (isset($block['shipping_text_after']) && is_array($block['shipping_text_after'])) { + foreach ($block['shipping_text_after'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['shipping_text_after'][$lang_id] = base64_decode($val); + } + } + } elseif ($block['type'] === 'subscribe') { + if (isset($block['subscribe_placeholder']) && is_array($block['subscribe_placeholder'])) { + foreach ($block['subscribe_placeholder'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['subscribe_placeholder'][$lang_id] = base64_decode($val); + } + } + if (isset($block['subscribe_button_text']) && is_array($block['subscribe_button_text'])) { + foreach ($block['subscribe_button_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['subscribe_button_text'][$lang_id] = base64_decode($val); + } + } + if (isset($block['subscribe_success_msg']) && is_array($block['subscribe_success_msg'])) { + foreach ($block['subscribe_success_msg'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['subscribe_success_msg'][$lang_id] = base64_decode($val); + } + } + } elseif ($block['type'] === 'coupon') { + if (isset($block['coupon_text']) && is_array($block['coupon_text'])) { + foreach ($block['coupon_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['coupon_text'][$lang_id] = base64_decode($val); + } + } + if (isset($block['coupon_code']) && is_array($block['coupon_code'])) { + foreach ($block['coupon_code'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['coupon_code'][$lang_id] = base64_decode($val); + } + } + if (isset($block['coupon_tooltip']) && is_array($block['coupon_tooltip'])) { + foreach ($block['coupon_tooltip'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['coupon_tooltip'][$lang_id] = base64_decode($val); + } + } + } elseif ($block['type'] === 'activity') { + if (isset($block['activity_text']) && is_array($block['activity_text'])) { + foreach ($block['activity_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['activity_text'][$lang_id] = base64_decode($val); + } + } + } elseif ($block['type'] === 'product') { + if (isset($block['product_button_text']) && is_array($block['product_button_text'])) { + foreach ($block['product_button_text'] as $lang_id => $val) { + $slides[$i]['blocks'][$j]['product_button_text'][$lang_id] = base64_decode($val); + } + } + } + } + } + } + return $slides; + } + + private function validate(): bool { + if (!$this->user->hasPermission('modify', 'extension/promo_top_bar_nat/module/promo_top_bar_nat')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + + + return !$this->error; + } + + public function reset_stats(): void { + $this->load->language('extension/promo_top_bar_nat/module/promo_top_bar_nat'); + if ($this->validate()) { + $this->db->query("TRUNCATE TABLE `" . DB_PREFIX . "promo_top_bar_stats_nat`"); + $this->session->data['success'] = $this->language->get('text_success_reset'); + } else { + $this->session->data['error'] = $this->language->get('error_permission'); + } + $this->response->redirect($this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function export_stats_csv(): void { + if (!$this->validate()) { + $this->response->redirect($this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat', 'user_token=' . $this->session->data['user_token'], true)); + return; + } + + $slides = $this->config->get('module_promo_top_bar_nat_slides'); + $slides = $this->decodeSlides($slides); + + $query = $this->db->query("SELECT slide_id, action, SUM(count) as total FROM `" . DB_PREFIX . "promo_top_bar_stats_nat` GROUP BY slide_id, action"); + $stats_raw = []; + foreach ($query->rows as $row) { + $stats_raw[$row['slide_id']][$row['action']] = (int)$row['total']; + } + + $filename = "promo_top_bar_stats_" . date('Y-m-d') . ".csv"; + + header('Content-Type: text/csv; charset=utf-8'); + header('Content-Disposition: attachment; filename=' . $filename); + + $output = fopen('php://output', 'w'); + fprintf($output, chr(0xEF).chr(0xBB).chr(0xBF)); // UTF-8 BOM + + fputcsv($output, [ + $this->language->get('text_csv_slide_id'), + $this->language->get('text_csv_slide_title'), + $this->language->get('text_csv_views'), + $this->language->get('text_csv_clicks'), + $this->language->get('text_csv_closes'), + $this->language->get('text_csv_ctr') + ]); + + if (is_array($slides)) { + foreach ($slides as $idx => $slide) { + $slide_id = $slide['slide_id'] ?? ''; + if (!$slide_id) continue; + + $views = $stats_raw[$slide_id]['view'] ?? 0; + $clicks = $stats_raw[$slide_id]['click'] ?? 0; + $closes = $stats_raw[$slide_id]['close'] ?? 0; + $ctr = $views > 0 ? round(($clicks / $views) * 100, 2) : 0.00; + $close_rate = $views > 0 ? round(($closes / $views) * 100, 2) : 0.00; + + $title = $this->language->get('text_slide_prefix') . ($idx + 1); + if (isset($slide['blocks']) && is_array($slide['blocks'])) { + foreach ($slide['blocks'] as $block) { + if ($block['type'] === 'text') { + $keys = array_keys($block['text']); + $firstLang = $keys[0] ?? ''; + if ($firstLang && !empty($block['text'][$firstLang])) { + $trimmedText = mb_substr($block['text'][$firstLang], 0, 25, 'UTF-8'); + $title = $this->language->get('text_block_text_prefix') . $trimmedText . (mb_strlen($block['text'][$firstLang]) > 25 ? '...' : '') . '"'; + break; + } + } + } + } + + fputcsv($output, [$slide_id, $title, $views, $clicks, $closes, $ctr . '%']); + } + } + + fclose($output); + exit; + } + + public function delete_lead(): void { + $this->load->language('extension/promo_top_bar_nat/module/promo_top_bar_nat'); + + if (!$this->user->hasPermission('modify', 'extension/promo_top_bar_nat/module/promo_top_bar_nat')) { + $this->session->data['error'] = $this->language->get('error_permission'); + $this->response->redirect($this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat', 'user_token=' . $this->session->data['user_token'], true)); + return; + } + + $id = isset($this->request->get['lead_id']) ? (int)$this->request->get['lead_id'] : (isset($this->request->post['lead_id']) ? (int)$this->request->post['lead_id'] : 0); + if ($id) { + $this->db->query("DELETE FROM `" . DB_PREFIX . "promo_top_bar_lead_nat` WHERE lead_id = '" . $id . "'"); + } + + $this->session->data['success'] = $this->language->get('text_success_delete_lead'); + $this->response->redirect($this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function export_leads_csv(): void { + $this->load->language('extension/promo_top_bar_nat/module/promo_top_bar_nat'); + + if (!$this->user->hasPermission('modify', 'extension/promo_top_bar_nat/module/promo_top_bar_nat')) { + $this->session->data['error'] = $this->language->get('error_permission'); + $this->response->redirect($this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat', 'user_token=' . $this->session->data['user_token'], true)); + return; + } + + $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "promo_top_bar_lead_nat` ORDER BY date_added DESC"); + + $filename = "promo_top_bar_leads_" . date('Y-m-d') . ".csv"; + + header('Content-Type: text/csv; charset=utf-8'); + header('Content-Disposition: attachment; filename=' . $filename); + + $output = fopen('php://output', 'w'); + fprintf($output, chr(0xEF).chr(0xBB).chr(0xBF)); // UTF-8 BOM + + fputcsv($output, ['ID', 'Email / Contact', 'Store ID', 'Date Added']); + + foreach ($query->rows as $row) { + fputcsv($output, [$row['lead_id'], $row['email'], $row['store_id'], $row['date_added']]); + } + + fclose($output); + exit; + } + + public function purgeAllData(): void { + $json = array(); + if (!$this->user->hasPermission('modify', 'extension/promo_top_bar_nat/module/promo_top_bar_nat')) { + $json['error'] = 'Permission denied'; + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + return; + } + $this->load->model('setting/setting'); + $this->model_setting_setting->deleteSetting('module_promo_top_bar_nat'); + $this->model_setting_setting->deleteSetting('nat_promo_top_bar_backup'); + + $json['success'] = true; + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + private function checkLicense(string $key): bool { + if (empty($key)) return false; + + $host = $this->request->server['HTTP_HOST'] ?? ''; + if (!$host) { + $host = defined('HTTP_SERVER') ? HTTP_SERVER : ''; + } + + $domain = str_replace(['http://', 'https://', 'www.'], '', strtolower($host)); + $domain = explode('/', $domain)[0]; + $domain = explode(':', $domain)[0]; + + $parts = explode('.', $domain); + + $v_p1 = 'kto_'; + $v_p2 = 'lomaet_'; + $v_p3 = 'promo_'; + $v_p4 = 'top_'; + $v_p5 = 'bar_'; + $v_p6 = 'tot_'; + $v_p7 = 'rediska'; + $salt = $v_p1 . $v_p2 . $v_p3 . $v_p4 . $v_p5 . $v_p6 . $v_p7; + + while (count($parts) >= 2) { + $check_domain = implode('.', $parts); + $hash = md5($check_domain . $salt); + $valid_key = strtoupper( + substr($hash, 0, 4) . '-' . + substr($hash, 4, 4) . '-' . + substr($hash, 8, 4) . '-' . + substr($hash, 12, 4) + ); + if ($key === $valid_key) { + return true; + } + array_shift($parts); + } + + return false; + } + + private function getErrors(): array { + $data = []; + foreach (['warning'] as $key) { + $data['error_' . $key] = $this->error[$key] ?? ''; + } + return $data; + } + + private function getBreadcrumbs(): array { + return [ + [ + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ], + [ + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ], + [ + 'text' => strip_tags($this->language->get('heading_title_raw') ? $this->language->get('heading_title_raw') : $this->language->get('heading_title')), + 'href' => $this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat', 'user_token=' . $this->session->data['user_token'], true) + ], + ]; + } + + public function injectMenu(string &$route, array &$data, mixed &$output = null): void { + try { + $is_installed = is_file(DIR_EXTENSION . 'promo_top_bar_nat/admin/controller/module/promo_top_bar_nat.php') || is_file(DIR_APPLICATION . 'controller/extension/module/promo_top_bar_nat.php'); + if ($is_installed) { + $nat_status = $this->config->get('module_promo_top_bar_nat_status'); + if ($nat_status === null || $nat_status) { + $nat_pos = $this->config->get('module_promo_top_bar_nat_menu_position'); + if (empty($nat_pos)) { $nat_pos = 'both'; } + if ($nat_pos == 'sidebar' || $nat_pos == 'both') { + if ($this->user->hasPermission('access', 'extension/promo_top_bar_nat/module/promo_top_bar_nat')) { + $token = isset($this->session->data['user_token']) ? $this->session->data['user_token'] : ''; + $nat_item = [ + 'name' => 'Promo Top Bar', + 'href' => $this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat', 'user_token=' . $token, true), + 'children' => [] + ]; + + $nat_menu_index = -1; + if (isset($data['menus'])) { + foreach ($data['menus'] as $k => $menu) { + if (isset($menu['id']) && $menu['id'] == 'menu-nat') { + $nat_menu_index = $k; + break; + } + } + } + + if ($nat_menu_index > -1) { + $exists = false; + foreach ($data['menus'][$nat_menu_index]['children'] as $child) { + if ($child['name'] == 'Promo Top Bar') { $exists = true; break; } + } + if (!$exists) { + $data['menus'][$nat_menu_index]['children'][] = $nat_item; + } + } else { + $data['menus'][] = [ + 'id' => 'menu-nat', + 'icon' => 'fa-space-shuttle fa-rotate-270 nat-nav-icon', + 'name' => '[NAT] Modules', + 'href' => '', + 'children' => [$nat_item] + ]; + } + } + } + } + } + } catch (\Throwable $e) {} + } + + public function injectHeader(string &$route, array &$data, mixed &$output): void { + try { + $is_installed = is_file(DIR_EXTENSION . 'promo_top_bar_nat/admin/controller/module/promo_top_bar_nat.php') || is_file(DIR_APPLICATION . 'controller/extension/module/promo_top_bar_nat.php'); + if ($is_installed) { + $style = ''; + if (strpos($output, '') !== false) { + $output = str_replace('', $style . '', $output); + } else { + $output = $style . $output; + } + + $nat_status = $this->config->get('module_promo_top_bar_nat_status'); + if ($nat_status === null || $nat_status) { + $nat_pos = $this->config->get('module_promo_top_bar_nat_menu_position'); + if (empty($nat_pos)) { $nat_pos = 'both'; } + if ($nat_pos == 'header' || $nat_pos == 'both') { + if ($this->user->hasPermission('access', 'extension/promo_top_bar_nat/module/promo_top_bar_nat')) { + $token = isset($this->session->data['user_token']) ? $this->session->data['user_token'] : ''; + $link = $this->url->link('extension/promo_top_bar_nat/module/promo_top_bar_nat', 'user_token=' . $token, true); + $btn = ''; + if (strpos($output, '