/** * Listing ajax des catégories */ public function displayAjaxCategoriesList() { //Insertion des styles admin nécessaire à l'affichage des actions ajax foreach ($this->css_files as $css_key => $css_type) { echo '<link rel="stylesheet" type="text/css" href="' . $css_key . '" type="' . $css_type . '"/>'; } //Géneration du tree des catégories if (_PS_VERSION_ < '1.6') { $categoryTree = new Helper(); echo $categoryTree->renderCategoryTree(2, array(), 'id-category-for-insert'); } else { $categoryTree = new HelperTreeCategories('categories-tree', $this->l('Check the category to display the link')); echo $categoryTree->setAttribute()->setInputName('id-category-for-insert')->render(); } }
public function getContent() { global $cookie; $html = ''; if (Tools::isSubmit('SubmitFilter')) { if (!Tools::getValue('layered_tpl_name')) { $html .= ' <div class="error"> <span style="float:right"> <a href="" id="hideError"><img src="../img/admin/close.png" alt="X"></a> </span> <img src="../img/admin/error2.png">' . $this->l('Filter template name required (cannot be empty)') . ' </div>'; } else { if (isset($_POST['id_layered_filter']) && $_POST['id_layered_filter']) { Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'layered_filter WHERE id_layered_filter = ' . (int) Tools::getValue('id_layered_filter')); $this->buildLayeredCategories(); } if (Tools::getValue('scope') == 1) { Db::getInstance()->execute('TRUNCATE TABLE ' . _DB_PREFIX_ . 'layered_filter'); $categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT id_category FROM ' . _DB_PREFIX_ . 'category'); foreach ($categories as $category) { $_POST['categoryBox'][] = (int) $category['id_category']; } } $id_layered_filter = (int) $_POST['id_layered_filter']; if (!$id_layered_filter) { $id_layered_filter = (int) Db::getInstance()->Insert_ID(); } $shop_list = array(); if (isset($_POST['checkBoxShopAsso_layered_filter'])) { foreach ($_POST['checkBoxShopAsso_layered_filter'] as $id_shop => $row) { $assos[] = array('id_object' => (int) $id_layered_filter, 'id_shop' => (int) $id_shop); $shop_list[] = (int) $id_shop; } } else { $shop_list = array(Context::getContext()->shop->id); } if (count($_POST['categoryBox'])) { /* Clean categoryBox before use */ if (isset($_POST['categoryBox']) && is_array($_POST['categoryBox'])) { foreach ($_POST['categoryBox'] as &$category_box_tmp) { $category_box_tmp = (int) $category_box_tmp; } } $filter_values = array(); foreach ($_POST['categoryBox'] as $idc) { $filter_values['categories'][] = (int) $idc; } $filter_values['shop_list'] = $shop_list; $values = false; foreach ($_POST['categoryBox'] as $id_category_layered) { foreach ($_POST as $key => $value) { if (substr($key, 0, 17) == 'layered_selection' && $value == 'on') { $values = true; $type = 0; $limit = 0; if (Tools::getValue($key . '_filter_type')) { $type = Tools::getValue($key . '_filter_type'); } if (Tools::getValue($key . '_filter_show_limit')) { $limit = Tools::getValue($key . '_filter_show_limit'); } $filter_values[$key] = array('filter_type' => (int) $type, 'filter_show_limit' => (int) $limit); } } } Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'layered_filter_shop WHERE `id_layered_filter` = ' . (int) $id_layered_filter); if (isset($assos)) { foreach ($assos as $asso) { Db::getInstance()->execute('INSERT INTO ' . _DB_PREFIX_ . 'layered_filter_shop (`id_layered_filter`, `id_shop`) VALUES(' . $id_layered_filter . ', ' . (int) $asso['id_shop'] . ')'); } } $values_to_insert = array('name' => pSQL(Tools::getValue('layered_tpl_name')), 'filters' => pSQL(serialize($filter_values)), 'n_categories' => (int) count($filter_values['categories']), 'date_add' => date('Y-m-d H:i:s')); if (isset($_POST['id_layered_filter']) && $_POST['id_layered_filter']) { $values_to_insert['id_layered_filter'] = (int) Tools::getValue('id_layered_filter'); } Db::getInstance()->autoExecute(_DB_PREFIX_ . 'layered_filter', $values_to_insert, 'INSERT'); $this->buildLayeredCategories(); $html .= '<div class="conf">' . $this->l('Your filter') . ' "' . Tools::safeOutput(Tools::getValue('layered_tpl_name')) . '" ' . (isset($_POST['id_layered_filter']) && $_POST['id_layered_filter'] ? $this->l('was updated successfully.') : $this->l('was added successfully.')) . '</div>'; } } } else { if (Tools::isSubmit('submitLayeredSettings')) { Configuration::updateValue('PS_LAYERED_HIDE_0_VALUES', (int) Tools::getValue('ps_layered_hide_0_values')); Configuration::updateValue('PS_LAYERED_SHOW_QTIES', (int) Tools::getValue('ps_layered_show_qties')); Configuration::updateValue('PS_LAYERED_FULL_TREE', (int) Tools::getValue('ps_layered_full_tree')); Configuration::updateValue('PS_LAYERED_FILTER_PRICE_USETAX', (int) Tools::getValue('ps_layered_filter_price_usetax')); Configuration::updateValue('PS_LAYERED_FILTER_CATEGORY_DEPTH', (int) Tools::getValue('ps_layered_filter_category_depth')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_QTY', (int) Tools::getValue('ps_layered_filter_index_availability')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_CDT', (int) Tools::getValue('ps_layered_filter_index_condition')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_MNF', (int) Tools::getValue('ps_layered_filter_index_manufacturer')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_CAT', (int) Tools::getValue('ps_layered_filter_index_category')); $html .= ' <div class="conf">' . $this->l('Settings saved successfully') . '</div>'; } else { if (isset($_GET['deleteFilterTemplate'])) { $layered_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT filters FROM ' . _DB_PREFIX_ . 'layered_filter WHERE id_layered_filter = ' . (int) $_GET['id_layered_filter']); if ($layered_values) { Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'layered_filter WHERE id_layered_filter = ' . (int) $_GET['id_layered_filter'] . ' LIMIT 1'); $this->buildLayeredCategories(); $html .= ' <div class="conf">' . $this->l('Filter template deleted, categories updated (reverted to default Filter template).') . ' </div>'; } else { $html .= ' <div class="error"> <img src="../img/admin/error.png" alt="" title="" /> ' . $this->l('Filter template not found') . ' </div>'; } } } } $html .= ' <div id="ajax-message-ok" class="conf ajax-message" style="display: none"> <span class="message"></span> </div> <div id="ajax-message-ko" class="error ajax-message" style="display: none"> <span class="message"></span> </div> <h2>' . $this->l('Layered navigation') . '</h2> <fieldset class="width4"> <legend><img src="../img/admin/cog.gif" alt="" />' . $this->l('Indexes and caches') . '</legend> <span id="indexing-warning" style="display: none; color:red; font-weight: bold">' . $this->l('Indexing is in progress. Please do not leave this page') . '<br/><br/></span>'; if (!Configuration::getGlobalValue('PS_LAYERED_INDEXED')) { $html .= ' <script type="text/javascript"> $(document).ready(function() { $(\'#url-indexer\').click(); $(\'#full-index\').click(); }); </script>'; } $category_ist = array(); foreach (Db::getInstance()->executeS('SELECT id_category FROM `' . _DB_PREFIX_ . 'category`') as $category) { if ($category['id_category'] != 1) { $category_ist[] = $category['id_category']; } } $domain = Tools::getProtocol(Tools::usingSecureMode()) . $_SERVER['HTTP_HOST']; $html .= ' <a class="bold ajaxcall-recurcive" style="width: 250px; text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px" href="' . $domain . __PS_BASE_URI__ . 'modules/blocklayered/blocklayered-price-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10) . '">' . $this->l('Index all missing prices') . '</a> <br /> <a class="bold ajaxcall-recurcive" style="width: 250px; text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px" id="full-index" href="' . $domain . __PS_BASE_URI__ . 'modules/blocklayered/blocklayered-price-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10) . '&full=1">' . $this->l('Rebuild entire price index') . '</a> <br /> <a class="bold ajaxcall" id="attribute-indexer" rel="attribute" style="width: 250px; text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px" id="full-index" href="' . $domain . __PS_BASE_URI__ . 'modules/blocklayered/blocklayered-attribute-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10) . '">' . $this->l('Build attribute index') . '</a> <br /> <a class="bold ajaxcall" id="url-indexer" rel="price" style="width: 250px; text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px" id="full-index" href="' . $domain . __PS_BASE_URI__ . 'modules/blocklayered/blocklayered-url-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10) . '&truncate=1">' . $this->l('Build URL index') . '</a> <br /> <br /> ' . $this->l('You can set a cron job that will rebuild price index using the following URL:') . '<br /><b>' . $domain . __PS_BASE_URI__ . 'modules/blocklayered/blocklayered-price-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10) . '&full=1</b> <br /> ' . $this->l('You can set a cron job that will rebuild URL index using the following URL:') . '<br /><b>' . $domain . __PS_BASE_URI__ . 'modules/blocklayered/blocklayered-url-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10) . '&truncate=1</b> <br /> ' . $this->l('You can set a cron job that will rebuild attribute index using the following URL:') . '<br /><b>' . $domain . __PS_BASE_URI__ . 'modules/blocklayered/blocklayered-attribute-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10) . '</b> <br /><br /> ' . $this->l('A nightly rebuild is recommended.') . ' <script type="text/javascript"> $(\'.ajaxcall\').click(function() { if (this.legend == undefined) this.legend = $(this).html(); if (this.running == undefined) this.running = false; if (this.running == true) return false; $(\'.ajax-message\').hide(); this.running = true; if (typeof(this.restartAllowed) == \'undefined\' || this.restartAllowed) { $(this).html(this.legend+\' ' . addslashes($this->l('(in progress)')) . '\'); $(\'#indexing-warning\').show(); } this.restartAllowed = false; var type = $(this).attr(\'rel\'); $.ajax({ url: this.href+\'&ajax=1\', context: this, dataType: \'json\', cache: \'false\', success: function(res) { this.running = false; this.restartAllowed = true; $(\'#indexing-warning\').hide(); $(this).html(this.legend); if (type == \'price\') $(\'#ajax-message-ok span\').html(\'' . addslashes($this->l('URL indexation finished')) . '\'); else $(\'#ajax-message-ok span\').html(\'' . addslashes($this->l('Attribute indexation finished')) . '\'); $(\'#ajax-message-ok\').show(); return; }, error: function(res) { this.restartAllowed = true; $(\'#indexing-warning\').hide(); if (type == \'price\') $(\'#ajax-message-ko span\').html(\'' . addslashes($this->l('URL indexation failed')) . '\'); else $(\'#ajax-message-ko span\').html(\'' . addslashes($this->l('Attribute indexation failed')) . '\'); $(\'#ajax-message-ko\').show(); $(this).html(this.legend); this.running = false; } }); return false; }); $(\'.ajaxcall-recurcive\').each(function(it, elm) { $(elm).click(function() { if (this.cursor == undefined) this.cursor = 0; if (this.legend == undefined) this.legend = $(this).html(); if (this.running == undefined) this.running = false; if (this.running == true) return false; $(\'.ajax-message\').hide(); this.running = true; if (typeof(this.restartAllowed) == \'undefined\' || this.restartAllowed) { $(this).html(this.legend+\' ' . addslashes($this->l('(in progress)')) . '\'); $(\'#indexing-warning\').show(); } this.restartAllowed = false; $.ajax({ url: this.href+\'&ajax=1&cursor=\'+this.cursor, context: this, dataType: \'json\', cache: \'false\', success: function(res) { this.running = false; if (res.result) { this.cursor = 0; $(\'#indexing-warning\').hide(); $(this).html(this.legend); $(\'#ajax-message-ok span\').html(\'' . addslashes($this->l('Price indexation finished')) . '\'); $(\'#ajax-message-ok\').show(); return; } this.cursor = parseInt(res.cursor); $(this).html(this.legend+\' ' . addslashes($this->l('(in progress, %s products price to index)')) . '\'.replace(\'%s\', res.count)); $(this).click(); }, error: function(res) { this.restartAllowed = true; $(\'#indexing-warning\').hide(); $(\'#ajax-message-ko span\').html(\'' . addslashes($this->l('Price indexation failed')) . '\'); $(\'#ajax-message-ko\').show(); $(this).html(this.legend); this.cursor = 0; this.running = false; } }); return false; }); }); </script> </fieldset> <br /> <fieldset class="width4"> <legend><img src="../img/admin/cog.gif" alt="" />' . $this->l('Existing filter templates') . '</legend>'; $filters_templates = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'layered_filter ORDER BY date_add DESC'); if (count($filters_templates)) { $html .= '<p>' . count($filters_templates) . ' ' . $this->l('filter templates are configured:') . '</p> <table id="table-filter-templates" class="table" style="width: 700px;"> <tr> <th>' . $this->l('ID') . '</th> <th>' . $this->l('Name') . '</th> <th>' . $this->l('Categories') . '</th> <th>' . $this->l('Created on') . '</th> <th>' . $this->l('Actions') . '</th> </tr>'; foreach ($filters_templates as $filters_template) { /* Clean request URI first */ $_SERVER['REQUEST_URI'] = preg_replace('/&deleteFilterTemplate=[0-9]*&id_layered_filter=[0-9]*/', '', $_SERVER['REQUEST_URI']); $html .= ' <tr> <td>' . (int) $filters_template['id_layered_filter'] . '</td> <td style="text-align: left; padding-left: 10px; width: 270px;">' . $filters_template['name'] . '</td> <td style="text-align: center;">' . (int) $filters_template['n_categories'] . '</td> <td>' . Tools::displayDate($filters_template['date_add'], null, true) . '</td> <td> <a href="#" onclick="return updElements(' . ($filters_template['n_categories'] ? 0 : 1) . ', ' . (int) $filters_template['id_layered_filter'] . ');"> <img src="../img/admin/edit.gif" alt="" title="' . $this->l('Edit') . '" /></a> <a href="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&deleteFilterTemplate=1&id_layered_filter=' . (int) $filters_template['id_layered_filter'] . '" onclick="return confirm(\'' . addslashes(sprintf($this->l('Delete filter template #%d?'), (int) $filters_template['id_layered_filter'])) . '\');"> <img src="../img/admin/delete.gif" alt="" title="' . $this->l('Delete') . '" /></a> </td> </tr>'; } $html .= ' </table>'; } else { $html .= $this->l('No filter template found.'); } $html .= ' </fieldset><br /> <fieldset class="width4"> <legend><img src="../img/admin/cog.gif" alt="" />' . $this->l('Build your own filter template') . '</legend> <link rel="stylesheet" href="' . _PS_CSS_DIR_ . 'jquery-ui-1.8.10.custom.css" /> <style type="text/css"> #error-filter-name { display: none; } #layered_container_left ul, #layered_container_right ul { list-style-type: none; padding-left: 0px; } .ui-effects-transfer { border: 1px solid #CCC; } .ui-state-highlight { height: 1.5em; line-height: 1.2em; } ul#selected_filters, #layered_container_right ul { list-style-type: none; margin: 0; padding: 0; } ul#selected_filters li, #layered_container_right ul li { width: 326px; font-size: 11px; padding: 8px 9px 7px 20px; height: 14px; margin-bottom: 5px; } ul#selected_filters li span.ui-icon { position: absolute; margin-top: -2px; margin-left: -18px; } #layered_container_right ul li span { display: none; } #layered_container_right ul li { padding-left: 8px; position: relative; } #layered_container_left ul li { cursor: move; position: relative; } #layered-cat-counter { display: none; } #layered-step-2, #layered-step-3 { display: none; } #layered-step-2 h3 { margin-top: 0; } #table-filter-templates tr th, #table-filter-templates tr td { text-align: center; } .filter_type { width: 70px; position: absolute; right: 53px; top: 5px;} .filter_show_limit { position: absolute; width: 40px; right: 5px; top: 5px; } #layered-step-3 .alert { width: auto; } #fancybox-content { height: 400px !important; overflow: auto !important; } </style> <form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post" onsubmit="return checkForm();">'; $html .= ' <h2>' . $this->l('Step 1/3 - Select categories') . '</h2> <p style="margin-top: 20px;"> <span style="color: #585A69;display: block;float: left;font-weight: bold;text-align: right;width: 200px;" >' . $this->l('Use this template for:') . '</span> <input type="radio" id="scope_1" name="scope" value="1" style="margin-left: 15px;" onclick="$(\'#error-treeview\').hide(); $(\'#layered-step-2\').show(); updElements(1, 0);" /> <label for="scope_1" style="float: none;">' . $this->l('All categories') . '</label> <input type="radio" id="scope_2" name="scope" value="2" style="margin-left: 15px;" class="layered-category-selection" onclick="$(\'label a#inline\').click(); $(\'#layered-step-2\').show();" /> <style> .link { color: black; cursor: pointer; text-decoration: underline; } .link:hover { color: gray; } </style> <label for="scope_2" style="float: none;"><a id="inline" href="#layered-categories-selection" style="text-decoration: underline;"></a>' . preg_replace('/\\*([^*]+)\\*/Usi', '<span class="link">$1</span>', $this->l('*Specific* categories')) . ' (<span id="layered-cat-counter"></span> ' . $this->l('selected') . ')</label> </p>'; $shops = Shop::getShops(true, null, true); if (count($shops) > 1) { $helper = new HelperForm(); $helper->id = null; $helper->table = 'layered_filter'; $helper->identifier = 'id_layered_filter'; if (Shop::isFeatureActive()) { $html .= '<span style="color: #585A69;display: block;float: left;font-weight: bold;text-align: right;width: 200px;" >' . $this->l('Choose shop association:') . '</span>'; $html .= '<div id="shop_association" style="width: 300px;margin-left: 215px;">' . $helper->renderAssoShop() . '</div>'; } } $html .= ' <div id="error-treeview" class="error" style="display: none;"> <img src="../img/admin/error2.png" alt="" /> ' . $this->l('Please select at least one specific category or select "All categories".') . ' </div> <div style="display: none;"> <div id="layered-categories-selection" style="padding: 10px; text-align: left;"> <h2>' . $this->l('Categories using this template') . '</h2> <ol style="padding-left: 20px;"> <li>' . $this->l('Select one ore more category using this filter template') . '</li> <li>' . $this->l('Press "Save this selection" or close the window to save') . '</li> </ol>'; $selected_cat = array(); // Translations are not automatic for the moment ;) if (Shop::getContext() == Shop::CONTEXT_SHOP) { $root_category = Category::getRootCategory(); $root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name); } else { $root_category = array('id_category' => '0', 'name' => $this->l('Root')); } $helper = new Helper(); $html .= $helper->renderCategoryTree(null, $selected_cat, 'categoryBox'); $html .= ' <br /> <center><input type="button" class="button" value="' . $this->l('Save this selection') . '" onclick="$.fancybox.close();" /></center> </div> </div> <div id="layered-step-2"> <hr size="1" noshade /> <h2>' . $this->l('Step 2/3 - Select filters') . '</h2> <div id="layered_container"> <div id="layered_container_left" style="width: 360px; float: left; height: 200px; overflow-y: auto;"> <h3>' . $this->l('Selected filters') . ' <span id="num_sel_filters">(0)</span></h3> <p id="no-filters">' . $this->l('No filters selected yet.') . '</p> <ul id="selected_filters"></ul> </div> <div id="layered-ajax-refresh"> ' . $this->ajaxCallBackOffice() . ' </div> </div> <div class="clear"></div> <hr size="1" noshade />'; $this->context->controller->addJQueryPlugin('fancybox'); $this->context->controller->addJQueryUI('ui.sortable'); $this->context->controller->addJQueryUI('ui.draggable'); $this->context->controller->addJQueryUI('effects.transfer'); $id_lang = Context::getContext()->cookie->id_lang; $html .= ' <script type="text/javascript"> function updLayCounters(showAlert) { $(\'#num_sel_filters\').html(\'(\'+$(\'ul#selected_filters\').find(\'li\').length+\')\'); $(\'#num_avail_filters\').html(\'(\'+$(\'#layered_container_right ul\').find(\'li\').length+\')\'); if ($(\'ul#selected_filters\').find(\'li\').length >= 1) { $(\'#layered-step-3\').show(); $(\'#layered-step-3 .alert\').hide(); } else { if (showAlert) $(\'#layered-step-3\').show(); else $(\'#layered-step-3\').hide(); $(\'#layered-step-3 .alert\').show(); } } function updPositions() { $(\'#layered_container_left li\').each(function(idx) { $(this).find(\'span.position\').html(parseInt(1+idx)+\'. \'); }); } function updCatCounter() { $(\'#layered-cat-counter\').html($(\'#categories-treeview\').find(\'input:checked\').length); $(\'#layered-cat-counter\').show(); } function updHeight() { $(\'#layered_container_left\').css(\'height\', 30+(1+$(\'#layered_container_left\').find(\'li\').length)*34); $(\'#layered_container_right\').css(\'height\', 30+(1+$(\'#layered_container_right\').find(\'li\').length)*34); } function updElements(all, id_layered_filter) { if ($(\'#error-treeview\').is(\':hidden\')) $(\'#layered-step-2\').show(); else $(\'#layered-step-2\').hide(); $(\'#layered-ajax-refresh\').css(\'background-color\', \'black\'); $(\'#layered-ajax-refresh\').css(\'opacity\', \'0.2\'); $(\'#layered-ajax-refresh\').html(\'<div style="margin: 0 auto; padding: 10px; text-align: center;">\' +\'<img src="../img/admin/ajax-loader-big.gif" alt="" /><br /><p style="color: white;">' . addslashes($this->l('Loading...')) . '</p></div>\'); $.ajax( { type: \'POST\', url: \'' . __PS_BASE_URI__ . '\' + \'modules/blocklayered/blocklayered-ajax-back.php\', data: \'layered_token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10) . '&id_lang=' . $id_lang . '&\' +(all ? \'\' : $(\'input[name="categoryBox[]"]\').serialize()+\'&\') +(id_layered_filter ? \'id_layered_filter=\'+parseInt(id_layered_filter) : \'\') +\'&base_folder=' . urlencode(_PS_ADMIN_DIR_) . '\', success: function(result) { $(\'#layered-ajax-refresh\').css(\'background-color\', \'transparent\'); $(\'#layered-ajax-refresh\').css(\'opacity\', \'1\'); $(\'#layered-ajax-refresh\').html(result); $(\'#layered_container_right li input\').each(function() { if ($(\'#layered_container_left\').find(\'input[id="\'+$(this).attr(\'id\')+\'"]\').length > 0) $(this).parent().remove(); }); updHeight(); updLayCounters(true); } }); return false; } function checkForm() { if ($(\'#layered_tpl_name\').val() == \'\') { $(\'#error-filter-name\').show(); return false; } else if ($(\'#scope_1\').attr(\'checked\') && $(\'#n_existing\').val() > 0) if (!confirm(\'' . addslashes($this->l('You selected -All categories-, all existing filter templates will be deleted, OK?')) . '\')) return false; return true; } function launch() { $(\'#layered_container input\').live(\'click\', function () { if ($(this).parent().hasClass(\'layered_right\')) { $(\'p#no-filters\').hide(); $(this).parent().css(\'background\', \'url("../img/jquery-ui/ui-bg_glass_100_fdf5ce_1x400.png") repeat-x scroll 50% 50% #FDF5CE\'); $(this).parent().removeClass(\'layered_right\'); $(this).parent().addClass(\'layered_left\'); $(this).effect(\'transfer\', { to: $(\'#layered_container_left ul#selected_filters\') }, 300, function() { $(this).parent().appendTo(\'ul#selected_filters\'); updLayCounters(false); updHeight(); updPositions(); }); } else { $(this).parent().css(\'background\', \'url("../img/jquery-ui/ui-bg_glass_100_f6f6f6_1x400.png") repeat-x scroll 50% 50% #F6F6F6\'); $(this).effect(\'transfer\', { to: $(\'#layered_container_right ul#all_filters\') }, 300, function() { $(this).parent().removeClass(\'layered_left\'); $(this).parent().addClass(\'layered_right\'); $(this).parent().appendTo(\'ul#all_filters\'); updLayCounters(true); updHeight(); updPositions(); if ($(\'#layered_container_left ul\').length == 0) $(\'p#no-filters\').show(); }); } enableSortable(); }); $(\'label a#inline\').fancybox({ \'hideOnContentClick\': false, \'onClosed\': function() { lock_treeview_hidding = false; $(\'#categories-treeview\').parent().parent().hide(); updCatCounter(); if ($(\'#categories-treeview\').find(\'input:checked\').length == 0) $(\'#error-treeview\').show(); else $(\'#error-treeview\').hide(); updElements(0, 0); }, \'onComplete\': function() { lock_treeview_hidding = true; $(\'#categories-treeview\').parent().parent().show(); if($($(\'#categories-treeview li\')[0]).attr(\'cleaned\')) return; if($($(\'#categories-treeview li\')[0]).attr(\'cleaned\', true)) $($(\'#categories-treeview li\')[0]).removeClass(\'static\'); $($(\'#categories-treeview li span\')[0]).trigger(\'click\'); $($(\'#categories-treeview li\')[0]).children(\'div\').remove(); $($(\'#categories-treeview li\')[0]). removeClass(\'collapsable lastCollapsable\'). addClass(\'last static\'); $(\'.hitarea\').live(\'click\', function(it) { $(this).parent().find(\'> .category_label\').click(); }); } }); updHeight(); updLayCounters(false); updPositions(); updCatCounter(); enableSortable(); } function enableSortable() { $(function() { $(\'ul#selected_filters\').sortable({ axis: \'y\', update: function() { updPositions(); }, placeholder: \'ui-state-highlight\' }); $(\'ul#selected_filters\').disableSelection(); }); } $(document).ready(function() { launch(); }); </script> </div> <div id="layered-step-3"> <div id="error-filter-name" class="error"> <img src="../img/admin/error.png" alt="" title="" />' . $this->l('Errors:') . ' <ul> <li>' . $this->l('Filter template name required (cannot be empty)') . '</li> </ul> </div> <h2>' . $this->l('Step 3/3 - Name your template') . '</h2> <p>' . $this->l('Template name:') . ' <input type="text" id="layered_tpl_name" onkeyup="if ($(this).val() != \'\') { $(\'#error-filter-name\').hide(); } else { $(\'#error-filter-name\').show(); }" name="layered_tpl_name" maxlength="64" value="' . sprintf($this->l('My template %s'), date('Y-m-d')) . '" style="width: 200px; font-size: 11px;" /> <span style="font-size: 10px; font-style: italic;">(' . $this->l('only as a reminder') . ')</span></p> <hr size="1" noshade /> <p class="alert">' . $this->l('No filters selected, the blocklayered will be disable for the categories seleted.') . '</p> <br /> <center><input type="submit" class="button" name="SubmitFilter" value="' . $this->l('Save this filter template') . '" /></center> </div> <input type="hidden" name="id_layered_filter" id="id_layered_filter" value="0" /> <input type="hidden" name="n_existing" id="n_existing" value="' . (int) count($filters_templates) . '" /> </form> </fieldset><br /> <fieldset class="width4"> <legend><img src="../img/admin/cog.gif" alt="" /> ' . $this->l('Configuration') . '</legend> <form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post"> <table border="0" style="font-size: 11px; width: 100%; margin: 0 auto;" class="table"> <tr> <th style="text-align: center;">' . $this->l('Option') . '</th> <th style="text-align: center; width: 200px;">' . $this->l('Value') . '</th> </tr> <tr> <td style="text-align: right;">' . $this->l('Hide filter values with no product is matching') . '</td> <td style="text-align: center;"> <img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" /> ' . $this->l('Yes') . ' <input type="radio" name="ps_layered_hide_0_values" value="1" ' . (Configuration::get('PS_LAYERED_HIDE_0_VALUES') ? 'checked="checked"' : '') . ' /> <img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" style="margin-left: 10px;" /> ' . $this->l('No') . ' <input type="radio" name="ps_layered_hide_0_values" value="0" ' . (!Configuration::get('PS_LAYERED_HIDE_0_VALUES') ? 'checked="checked"' : '') . ' /> </td> </tr> <tr> <td style="text-align: right;">' . $this->l('Show the number of matching products') . '</td> <td style="text-align: center;"> <img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" /> ' . $this->l('Yes') . ' <input type="radio" name="ps_layered_show_qties" value="1" ' . (Configuration::get('PS_LAYERED_SHOW_QTIES') ? 'checked="checked"' : '') . ' /> <img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" style="margin-left: 10px;" /> ' . $this->l('No') . ' <input type="radio" name="ps_layered_show_qties" value="0" ' . (!Configuration::get('PS_LAYERED_SHOW_QTIES') ? 'checked="checked"' : '') . ' /> </td> </tr> <tr> <td style="text-align: right;">' . $this->l('Show products from subcategories') . '</td> <td style="text-align: center;"> <img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" /> ' . $this->l('Yes') . ' <input type="radio" name="ps_layered_full_tree" value="1" ' . (Configuration::get('PS_LAYERED_FULL_TREE') ? 'checked="checked"' : '') . ' /> <img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" style="margin-left: 10px;" /> ' . $this->l('No') . ' <input type="radio" name="ps_layered_full_tree" value="0" ' . (!Configuration::get('PS_LAYERED_FULL_TREE') ? 'checked="checked"' : '') . ' /> </td> </tr> <tr style="text-align: center;"> <td style="text-align: right;">' . $this->l('Category filter depth (0 for no limits, 1 by default)') . '</td> <td> <input type="text" name="ps_layered_filter_category_depth" value="' . (Configuration::get('PS_LAYERED_FILTER_CATEGORY_DEPTH') !== false ? Configuration::get('PS_LAYERED_FILTER_CATEGORY_DEPTH') : 1) . '" /> </td> </tr> <tr style="text-align: center;"> <td style="text-align: right;">' . $this->l('Use tax to filter price') . '</td> <td> <img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" /> ' . $this->l('Yes') . ' <input type="radio" name="ps_layered_filter_price_usetax" value="1" ' . (Configuration::get('PS_LAYERED_FILTER_PRICE_USETAX') ? 'checked="checked"' : '') . ' /> <img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" style="margin-left: 10px;" /> ' . $this->l('No') . ' <input type="radio" name="ps_layered_filter_price_usetax" value="0" ' . (!Configuration::get('PS_LAYERED_FILTER_PRICE_USETAX') ? 'checked="checked"' : '') . ' /> </td> </tr> <tr style="text-align: center;"> <td style="text-align: right;">' . $this->l('Allow indexing robots (google, yahoo, bing, ...) to use condition filter') . '</td> <td> <img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" /> ' . $this->l('Yes') . ' <input type="radio" name="ps_layered_filter_index_condition" value="1" ' . (Configuration::get('PS_LAYERED_FILTER_INDEX_CDT') ? 'checked="checked"' : '') . ' /> <img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" style="margin-left: 10px;" /> ' . $this->l('No') . ' <input type="radio" name="ps_layered_filter_index_condition" value="0" ' . (!Configuration::get('PS_LAYERED_FILTER_INDEX_CDT') ? 'checked="checked"' : '') . ' /> </td> </tr> <tr style="text-align: center;"> <td style="text-align: right;">' . $this->l('Allow indexing robots (google, yahoo, bing, ...) to use availability filter') . '</td> <td> <img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" /> ' . $this->l('Yes') . ' <input type="radio" name="ps_layered_filter_index_availability" value="1" ' . (Configuration::get('PS_LAYERED_FILTER_INDEX_QTY') ? 'checked="checked"' : '') . ' /> <img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" style="margin-left: 10px;" /> ' . $this->l('No') . ' <input type="radio" name="ps_layered_filter_index_availability" value="0" ' . (!Configuration::get('PS_LAYERED_FILTER_INDEX_QTY') ? 'checked="checked"' : '') . ' /> </td> </tr> <tr style="text-align: center;"> <td style="text-align: right;">' . $this->l('Allow indexing robots (google, yahoo, bing, ...) to use manufacturer filter') . '</td> <td> <img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" /> ' . $this->l('Yes') . ' <input type="radio" name="ps_layered_filter_index_manufacturer" value="1" ' . (Configuration::get('PS_LAYERED_FILTER_INDEX_MNF') ? 'checked="checked"' : '') . ' /> <img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" style="margin-left: 10px;" /> ' . $this->l('No') . ' <input type="radio" name="ps_layered_filter_index_manufacturer" value="0" ' . (!Configuration::get('PS_LAYERED_FILTER_INDEX_MNF') ? 'checked="checked"' : '') . ' /> </td> </tr> <tr style="text-align: center;"> <td style="text-align: right;">' . $this->l('Allow indexing robots (google, yahoo, bing, ...) to use category filter') . '</td> <td> <img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" /> ' . $this->l('Yes') . ' <input type="radio" name="ps_layered_filter_index_category" value="1" ' . (Configuration::get('PS_LAYERED_FILTER_INDEX_CAT') ? 'checked="checked"' : '') . ' /> <img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" style="margin-left: 10px;" /> ' . $this->l('No') . ' <input type="radio" name="ps_layered_filter_index_category" value="0" ' . (!Configuration::get('PS_LAYERED_FILTER_INDEX_CAT') ? 'checked="checked"' : '') . ' /> </td> </tr> </table> <p style="text-align: center;"><input type="submit" class="button" name="submitLayeredSettings" value="' . $this->l('Save configuration') . '" /></p> </form> </fieldset>'; return $html; }
public function initCategoriesAssociation($id_root = null) { if (is_null($id_root)) { $id_root = Configuration::get('PS_ROOT_CATEGORY'); } $id_shop = (int) Tools::getValue('id_shop'); $shop = new Shop($id_shop); $selected_cat = Shop::getCategories($id_shop); if (empty($selected_cat)) { // get first category root and preselect all these children $root_categories = Category::getRootCategories(); $root_category = new Category($root_categories[0]['id_category']); $children = $root_category->getAllChildren($this->context->language->id); $selected_cat[] = $root_categories[0]['id_category']; foreach ($children as $child) { $selected_cat[] = $child->id; } } if (Shop::getContext() == Shop::CONTEXT_SHOP && Tools::isSubmit('id_shop')) { $root_category = new Category($shop->id_category); } else { $root_category = new Category($id_root); } $root_category = array('id_category' => $root_category->id, 'name' => $root_category->name[$this->context->language->id]); $helper = new Helper(); return $helper->renderCategoryTree($root_category, $selected_cat, 'categoryBox', false, true); }
/** * @deprecated 1.5.0 */ public static function renderAdminCategorieTree($translations, $selected_cat = array(), $input_name = 'categoryBox', $use_radio = false, $use_search = false, $disabled_categories = array(), $use_in_popup = false) { Tools::displayAsDeprecated(); $helper = new Helper(); if (isset($translations['Root'])) { $root = $translations['Root']; } else { if (isset($translations['Home'])) { $root = array('name' => $translations['Home'], 'id_category' => 1); } else { throw new PrestaShopException('Missing root category parameter.'); } } return $helper->renderCategoryTree($root, $selected_cat, $input_name, $use_radio, $use_search, $disabled_categories, $use_in_popup); }
public function initFormAssociations($obj) { $product = $obj; $data = $this->createTemplate($this->tpl_form); // Prepare Categories tree for display in Associations tab $root = Category::getRootCategory(); $default_category = $this->context->cookie->id_category_products_filter ? $this->context->cookie->id_category_products_filter : Context::getContext()->shop->id_category; if (!$product->id || !$product->isAssociatedToShop()) { $selected_cat = Category::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->default_form_language); } else { if (Tools::isSubmit('categoryBox')) { $selected_cat = Category::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->default_form_language); } else { $selected_cat = Product::getProductCategoriesFull($product->id, $this->default_form_language); } } // Multishop block $data->assign('feature_shop_active', Shop::isFeatureActive()); $helper = new HelperForm(); if ($this->object && $this->object->id) { $helper->id = $this->object->id; } else { $helper->id = null; } $helper->table = $this->table; $helper->identifier = $this->identifier; // Accessories block $accessories = Product::getAccessoriesLight($this->context->language->id, $product->id); if ($post_accessories = Tools::getValue('inputAccessories')) { $post_accessories_tab = explode('-', Tools::getValue('inputAccessories')); foreach ($post_accessories_tab as $accessory_id) { if (!$this->haveThisAccessory($accessory_id, $accessories) && ($accessory = Product::getAccessoryById($accessory_id))) { $accessories[] = $accessory; } } } $data->assign('accessories', $accessories); $product->manufacturer_name = Manufacturer::getNameById($product->id_manufacturer); $tab_root = array('id_category' => $root->id, 'name' => $root->name); $helper = new Helper(); $category_tree = $helper->renderCategoryTree($tab_root, $selected_cat, 'categoryBox', false, true, array(), false, true); $data->assign(array('default_category' => $default_category, 'selected_cat_ids' => implode(',', array_keys($selected_cat)), 'selected_cat' => $selected_cat, 'id_category_default' => $product->getDefaultCategory(), 'category_tree' => $category_tree, 'product' => $product, 'link' => $this->context->link, 'is_shop_context' => Shop::getContext() == Shop::CONTEXT_SHOP)); $this->tpl_form_vars['custom_form'] = $data->fetch(); }
public function initCategoriesAssociation($id_root = null, $id_criterion = 0) { if (is_null($id_root)) { $id_root = Configuration::get('PS_ROOT_CATEGORY'); } $id_shop = (int) Tools::getValue('id_shop'); $shop = new Shop($id_shop); if ($id_criterion == 0) { $selected_cat = array(); } else { $pdc_object = new ProductCommentCriterion($id_criterion); $selected_cat = $pdc_object->getCategories(); } if (Shop::getContext() == Shop::CONTEXT_SHOP && Tools::isSubmit('id_shop')) { $root_category = new Category($shop->id_category); } else { $root_category = new Category($id_root); } $root_category = array('id_category' => $root_category->id, 'name' => $root_category->name[$this->context->language->id]); $helper = new Helper(); return $helper->renderCategoryTree($root_category, $selected_cat, 'categoryBox', false, true); }
public function getContent() { global $cookie; $message = ''; if (Tools::isSubmit('SubmitFilter')) { if (!Tools::getValue('layered_tpl_name')) { $message = $this->displayError($this->l('Filter template name required (cannot be empty)')); } elseif (!Tools::getValue('categoryBox')) { $message = $this->displayError($this->l('You must select at least one category.')); } else { if (Tools::getValue('id_layered_filter')) { Db::getInstance()->execute(' DELETE FROM ' . _DB_PREFIX_ . 'layered_filter WHERE id_layered_filter = ' . (int) Tools::getValue('id_layered_filter')); $this->buildLayeredCategories(); } if (Tools::getValue('scope') == 1) { Db::getInstance()->execute('TRUNCATE TABLE ' . _DB_PREFIX_ . 'layered_filter'); $categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT id_category FROM ' . _DB_PREFIX_ . 'category'); foreach ($categories as $category) { $_POST['categoryBox'][] = (int) $category['id_category']; } } $id_layered_filter = (int) Tools::getValue('id_layered_filter'); if (!$id_layered_filter) { $id_layered_filter = (int) Db::getInstance()->Insert_ID(); } $shop_list = array(); if (isset($_POST['checkBoxShopAsso_layered_filter'])) { foreach ($_POST['checkBoxShopAsso_layered_filter'] as $id_shop => $row) { $assos[] = array('id_object' => (int) $id_layered_filter, 'id_shop' => (int) $id_shop); $shop_list[] = (int) $id_shop; } } else { $shop_list = array(Context::getContext()->shop->id); } Db::getInstance()->execute(' DELETE FROM ' . _DB_PREFIX_ . 'layered_filter_shop WHERE `id_layered_filter` = ' . (int) $id_layered_filter); if (count($_POST['categoryBox'])) { /* Clean categoryBox before use */ if (isset($_POST['categoryBox']) && is_array($_POST['categoryBox'])) { foreach ($_POST['categoryBox'] as &$category_box_tmp) { $category_box_tmp = (int) $category_box_tmp; } } $filter_values = array(); foreach ($_POST['categoryBox'] as $idc) { $filter_values['categories'][] = (int) $idc; } $filter_values['shop_list'] = $shop_list; $values = false; foreach ($_POST['categoryBox'] as $id_category_layered) { foreach ($_POST as $key => $value) { if (substr($key, 0, 17) == 'layered_selection' && $value == 'on') { $values = true; $type = 0; $limit = 0; if (Tools::getValue($key . '_filter_type')) { $type = Tools::getValue($key . '_filter_type'); } if (Tools::getValue($key . '_filter_show_limit')) { $limit = Tools::getValue($key . '_filter_show_limit'); } $filter_values[$key] = array('filter_type' => (int) $type, 'filter_show_limit' => (int) $limit); } } } $values_to_insert = array('name' => pSQL(Tools::getValue('layered_tpl_name')), 'filters' => pSQL(serialize($filter_values)), 'n_categories' => (int) count($filter_values['categories']), 'date_add' => date('Y-m-d H:i:s')); if (isset($_POST['id_layered_filter']) && $_POST['id_layered_filter']) { $values_to_insert['id_layered_filter'] = (int) Tools::getValue('id_layered_filter'); } Db::getInstance()->autoExecute(_DB_PREFIX_ . 'layered_filter', $values_to_insert, 'INSERT'); $id_layered_filter = (int) Db::getInstance()->Insert_ID(); if (isset($assos)) { foreach ($assos as $asso) { Db::getInstance()->execute(' INSERT INTO ' . _DB_PREFIX_ . 'layered_filter_shop (`id_layered_filter`, `id_shop`) VALUES(' . $id_layered_filter . ', ' . (int) $asso['id_shop'] . ')'); } } $this->buildLayeredCategories(); $message = $this->displayConfirmation($this->l('Your filter') . ' "' . Tools::safeOutput(Tools::getValue('layered_tpl_name')) . '" ' . (isset($_POST['id_layered_filter']) && $_POST['id_layered_filter'] ? $this->l('was updated successfully.') : $this->l('was added successfully.'))); } } } else { if (Tools::isSubmit('submitLayeredSettings')) { Configuration::updateValue('PS_LAYERED_HIDE_0_VALUES', (int) Tools::getValue('ps_layered_hide_0_values')); Configuration::updateValue('PS_LAYERED_SHOW_QTIES', (int) Tools::getValue('ps_layered_show_qties')); Configuration::updateValue('PS_LAYERED_FULL_TREE', (int) Tools::getValue('ps_layered_full_tree')); Configuration::updateValue('PS_LAYERED_FILTER_PRICE_USETAX', (int) Tools::getValue('ps_layered_filter_price_usetax')); Configuration::updateValue('PS_LAYERED_FILTER_CATEGORY_DEPTH', (int) Tools::getValue('ps_layered_filter_category_depth')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_QTY', (int) Tools::getValue('ps_layered_filter_index_availability')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_CDT', (int) Tools::getValue('ps_layered_filter_index_condition')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_MNF', (int) Tools::getValue('ps_layered_filter_index_manufacturer')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_CAT', (int) Tools::getValue('ps_layered_filter_index_category')); if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { $message = '<div class="alert alert-success">' . $this->l('Settings saved successfully') . '</div>'; } else { $message = '<div class="conf">' . $this->l('Settings saved successfully') . '</div>'; } } else { if (Tools::getValue('deleteFilterTemplate')) { $layered_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT filters FROM ' . _DB_PREFIX_ . 'layered_filter WHERE id_layered_filter = ' . (int) Tools::getValue('id_layered_filter')); if ($layered_values) { Db::getInstance()->execute(' DELETE FROM ' . _DB_PREFIX_ . 'layered_filter WHERE id_layered_filter = ' . (int) Tools::getValue('id_layered_filter') . ' LIMIT 1'); $this->buildLayeredCategories(); $message = $this->displayConfirmation($this->l('Filter template deleted, categories updated (reverted to default Filter template).')); } else { $message = $this->displayError($this->l('Filter template not found')); } } } } $category_box = array(); $attribute_groups = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT ag.id_attribute_group, ag.is_color_group, agl.name, COUNT(DISTINCT(a.id_attribute)) n FROM ' . _DB_PREFIX_ . 'attribute_group ag LEFT JOIN ' . _DB_PREFIX_ . 'attribute_group_lang agl ON (agl.id_attribute_group = ag.id_attribute_group) LEFT JOIN ' . _DB_PREFIX_ . 'attribute a ON (a.id_attribute_group = ag.id_attribute_group) WHERE agl.id_lang = ' . (int) $cookie->id_lang . ' GROUP BY ag.id_attribute_group'); $features = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT fl.id_feature, fl.name, COUNT(DISTINCT(fv.id_feature_value)) n FROM ' . _DB_PREFIX_ . 'feature_lang fl LEFT JOIN ' . _DB_PREFIX_ . 'feature_value fv ON (fv.id_feature = fl.id_feature) WHERE (fv.custom IS NULL OR fv.custom = 0) AND fl.id_lang = ' . (int) $cookie->id_lang . ' GROUP BY fl.id_feature'); if (Shop::isFeatureActive() && count(Shop::getShops(true, null, true)) > 1) { $helper = new HelperForm(); $helper->id = Tools::getValue('id_layered_filter', null); $helper->table = 'layered_filter'; $helper->identifier = 'id_layered_filter'; $this->context->smarty->assign('asso_shops', $helper->renderAssoShop()); } if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { $tree_categories_helper = new HelperTreeCategories('categories-treeview'); $tree_categories_helper->setRootCategory(Shop::getContext() == Shop::CONTEXT_SHOP ? Category::getRootCategory()->id_category : 0)->setUseCheckBox(true); } else { if (Shop::getContext() == Shop::CONTEXT_SHOP) { $root_category = Category::getRootCategory(); $root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name); } else { $root_category = array('id_category' => '0', 'name' => $this->l('Root')); } $tree_categories_helper = new Helper(); } $module_url = Tools::getProtocol(Tools::usingSecureMode()) . $_SERVER['HTTP_HOST'] . $this->getPathUri(); if (method_exists($this->context->controller, 'addJquery')) { $this->context->controller->addJS($this->_path . 'js/blocklayered_admin.js'); if (version_compare(_PS_VERSION_, '1.6.0.3', '>=') === true) { $this->context->controller->addjqueryPlugin('sortable'); } elseif (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { $this->context->controller->addJS(_PS_JS_DIR_ . 'jquery/plugins/jquery.sortable.js'); } else { $this->context->controller->addJS($this->_path . 'js/jquery.sortable.js'); } } if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { $this->context->controller->addCSS($this->_path . 'css/blocklayered_admin_1.6.css'); } else { $this->context->controller->addCSS($this->_path . 'css/blocklayered_admin.css'); } if (Tools::getValue('add_new_filters_template')) { $this->context->smarty->assign(array('current_url' => $this->context->link->getAdminLink('AdminModules') . '&configure=blocklayered&tab_module=front_office_features&module_name=blocklayered', 'uri' => $this->getPathUri(), 'id_layered_filter' => 0, 'template_name' => sprintf($this->l('My template - %s'), date('Y-m-d')), 'attribute_groups' => $attribute_groups, 'features' => $features, 'total_filters' => 6 + count($attribute_groups) + count($features))); if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { $this->context->smarty->assign('categories_tree', $tree_categories_helper->render()); } else { $this->context->smarty->assign('categories_tree', $tree_categories_helper->renderCategoryTree($root_category, array(), 'categoryBox')); } if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { return $this->display(__FILE__, 'views/templates/admin/add_1.6.tpl'); } else { return $this->display(__FILE__, 'views/templates/admin/add.tpl'); } } else { if (Tools::getValue('edit_filters_template')) { $template = Db::getInstance()->getRow(' SELECT * FROM `' . _DB_PREFIX_ . 'layered_filter` WHERE id_layered_filter = ' . (int) Tools::getValue('id_layered_filter')); $filters = unserialize($template['filters']); if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { $tree_categories_helper->setSelectedCategories($filters['categories']); $this->context->smarty->assign('categories_tree', $tree_categories_helper->render()); } else { $this->context->smarty->assign('categories_tree', $tree_categories_helper->renderCategoryTree($root_category, $filters['categories'], 'categoryBox')); } $select_shops = $filters['shop_list']; unset($filters['categories']); unset($filters['shop_list']); $this->context->smarty->assign(array('current_url' => $this->context->link->getAdminLink('AdminModules') . '&configure=blocklayered&tab_module=front_office_features&module_name=blocklayered', 'uri' => $this->getPathUri(), 'id_layered_filter' => (int) Tools::getValue('id_layered_filter'), 'template_name' => $template['name'], 'attribute_groups' => $attribute_groups, 'features' => $features, 'filters' => Tools::jsonEncode($filters), 'total_filters' => 6 + count($attribute_groups) + count($features))); if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { return $this->display(__FILE__, 'views/templates/admin/add_1.6.tpl'); } else { return $this->display(__FILE__, 'views/templates/admin/add.tpl'); } } else { $this->context->smarty->assign(array('message' => $message, 'uri' => $this->getPathUri(), 'PS_LAYERED_INDEXED' => Configuration::getGlobalValue('PS_LAYERED_INDEXED'), 'current_url' => Tools::safeOutput(preg_replace('/&deleteFilterTemplate=[0-9]*&id_layered_filter=[0-9]*/', '', $_SERVER['REQUEST_URI'])), 'id_lang' => Context::getContext()->cookie->id_lang, 'token' => substr(Tools::encrypt('blocklayered/index'), 0, 10), 'base_folder' => urlencode(_PS_ADMIN_DIR_), 'price_indexer_url' => $module_url . 'blocklayered-price-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10), 'full_price_indexer_url' => $module_url . 'blocklayered-price-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10) . '&full=1', 'attribute_indexer_url' => $module_url . 'blocklayered-attribute-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10), 'url_indexer_url' => $module_url . 'blocklayered-url-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10) . '&truncate=1', 'filters_templates' => Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'layered_filter ORDER BY date_add DESC'), 'hide_values' => Configuration::get('PS_LAYERED_HIDE_0_VALUES'), 'show_quantities' => Configuration::get('PS_LAYERED_SHOW_QTIES'), 'full_tree' => Configuration::get('PS_LAYERED_FULL_TREE'), 'category_depth' => Configuration::get('PS_LAYERED_FILTER_CATEGORY_DEPTH'), 'price_use_tax' => Configuration::get('PS_LAYERED_FILTER_PRICE_USETAX'), 'index_cdt' => Configuration::get('PS_LAYERED_FILTER_INDEX_CDT'), 'index_qty' => Configuration::get('PS_LAYERED_FILTER_INDEX_QTY'), 'index_mnf' => Configuration::get('PS_LAYERED_FILTER_INDEX_MNF'), 'index_cat' => Configuration::get('PS_LAYERED_FILTER_INDEX_CAT'), 'limit_warning' => $this->displayLimitPostWarning(21 + count($attribute_groups) * 3 + count($features) * 3))); if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { return $this->display(__FILE__, 'views/templates/admin/view_1.6.tpl'); } else { return $this->display(__FILE__, 'views/templates/admin/view.tpl'); } } } }
public static function find($id_lang, $expr, $page_number = 1, $page_size = 1, $order_by = 'position', $order_way = 'desc', $ajax = false, $use_cookie = true, Context $context = null) { if (!$context) { $context = Context::getContext(); } $db = Db::getInstance(_PS_USE_SQL_SLAVE_); if ($page_number < 1) { $page_number = 1; } if ($page_size < 1) { $page_size = 1; } if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) { return false; } $intersect_array = array(); $score_array = array(); $words = explode(' ', Search::sanitize($expr, $id_lang, false, $context->language->iso_code)); foreach ($words as $key => $word) { if (!empty($word) && strlen($word) >= (int) Configuration::get('PS_SEARCH_MINWORDLEN')) { $word = str_replace('%', '\\%', $word); $word = str_replace('_', '\\_', $word); $start_search = Configuration::get('PS_SEARCH_START') ? '%' : ''; $end_search = Configuration::get('PS_SEARCH_END') ? '' : '%'; $intersect_array[] = 'SELECT si.id_product FROM ' . _DB_PREFIX_ . 'search_word sw LEFT JOIN ' . _DB_PREFIX_ . 'search_index si ON sw.id_word = si.id_word WHERE sw.id_lang = ' . (int) $id_lang . ' AND sw.id_shop = ' . $context->shop->id . ' AND sw.word LIKE ' . ($word[0] == '-' ? ' \'' . $start_search . pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)) . $end_search . '\'' : ' \'' . $start_search . pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)) . $end_search . '\''); if ($word[0] != '-') { $score_array[] = 'sw.word LIKE \'' . $start_search . pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)) . $end_search . '\''; } } else { unset($words[$key]); } } if (!count($words)) { return $ajax ? array() : array('total' => 0, 'result' => array(), 'painters' => array()); } $score = ''; if (count($score_array)) { $score = ',( SELECT SUM(weight) FROM ' . _DB_PREFIX_ . 'search_word sw LEFT JOIN ' . _DB_PREFIX_ . 'search_index si ON sw.id_word = si.id_word WHERE sw.id_lang = ' . (int) $id_lang . ' AND sw.id_shop = ' . $context->shop->id . ' AND si.id_product = p.id_product AND (' . implode(' OR ', $score_array) . ') ) position'; } $sql_groups = ''; if (Group::isFeatureActive()) { $groups = FrontController::getCurrentCustomerGroups(); $sql_groups = 'AND cg.`id_group` ' . (count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1'); } $results = $db->executeS(' SELECT cp.`id_product` FROM `' . _DB_PREFIX_ . 'category_product` cp ' . (Group::isFeatureActive() ? 'INNER JOIN `' . _DB_PREFIX_ . 'category_group` cg ON cp.`id_category` = cg.`id_category`' : '') . ' INNER JOIN `' . _DB_PREFIX_ . 'category` c ON cp.`id_category` = c.`id_category` INNER JOIN `' . _DB_PREFIX_ . 'product` p ON cp.`id_product` = p.`id_product` ' . Shop::addSqlAssociation('product', 'p', false) . ' WHERE c.`active` = 1 AND product_shop.`active` = 1 AND product_shop.`visibility` IN ("both", "search") AND product_shop.indexed = 1 ' . $sql_groups); $eligible_products = array(); foreach ($results as $row) { $eligible_products[] = $row['id_product']; } foreach ($intersect_array as $query) { $eligible_products2 = array(); foreach ($db->executeS($query) as $row) { $eligible_products2[] = $row['id_product']; } $eligible_products = array_intersect($eligible_products, $eligible_products2); if (!count($eligible_products)) { return $ajax ? array() : array('total' => 0, 'result' => array(), 'painters' => array()); } } $eligible_products = array_unique($eligible_products); $product_pool = ''; foreach ($eligible_products as $id_product) { if ($id_product) { $product_pool .= (int) $id_product . ','; } } if (empty($product_pool)) { return $ajax ? array() : array('total' => 0, 'result' => array()); } $product_pool = strpos($product_pool, ',') === false ? ' = ' . (int) $product_pool . ' ' : ' IN (' . rtrim($product_pool, ',') . ') '; if ($ajax) { $sql = 'SELECT DISTINCT p.id_product, pl.name pname, cl.name cname, cl.link_rewrite crewrite, pl.link_rewrite prewrite ' . $score . ' FROM ' . _DB_PREFIX_ . 'product p INNER JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON ( p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . ' ) ' . Shop::addSqlAssociation('product', 'p') . ' INNER JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON ( product_shop.`id_category_default` = cl.`id_category` AND cl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl') . ' ) WHERE p.`id_product` ' . $product_pool . ' ORDER BY position DESC LIMIT 10'; return $db->executeS($sql); } if (strpos($order_by, '.') > 0) { $order_by = explode('.', $order_by); $order_by = pSQL($order_by[0]) . '.`' . pSQL($order_by[1]) . '`'; } $alias = ''; if ($order_by == 'price') { $alias = 'product_shop.'; } elseif (in_array($order_by, array('date_upd', 'date_add'))) { $alias = 'p.'; } $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` manufacturer_name ' . $score . (Combination::isFeatureActive() ? ', MAX(product_attribute_shop.`id_product_attribute`) id_product_attribute' : '') . ', DATEDIFF( p.`date_add`, DATE_SUB( NOW(), INTERVAL ' . (Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . ' DAY ) ) > 0 new' . (Combination::isFeatureActive() ? ', MAX(product_attribute_shop.minimal_quantity) AS product_attribute_minimal_quantity' : '') . ' FROM ' . _DB_PREFIX_ . 'product p ' . Shop::addSqlAssociation('product', 'p') . ' INNER JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON ( p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . ' ) ' . (Combination::isFeatureActive() ? 'LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (p.`id_product` = pa.`id_product`) ' . Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1') . ' ' . Product::sqlStock('p', 'product_attribute_shop', false, $context->shop) : Product::sqlStock('p', 'product', false, Context::getContext()->shop)) . ' LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product`)' . Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1') . ' LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ') WHERE p.`id_product` ' . $product_pool . ' GROUP BY product_shop.id_product ' . ($order_by ? 'ORDER BY ' . $alias . $order_by : '') . ($order_way ? ' ' . $order_way : '') . ' LIMIT ' . (int) (($page_number - 1) * $page_size) . ',' . (int) $page_size; $result = $db->executeS($sql); $helper = new Helper(); $categoryTree = $helper->renderCategoryTree(); $sql = 'SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'product p ' . Shop::addSqlAssociation('product', 'p') . ' INNER JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON ( p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . ' ) LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` WHERE p.`id_product` ' . $product_pool; $total = $db->getValue($sql); if (!$result) { $result_properties = false; } else { $result_properties = Product::getProductsProperties((int) $id_lang, $result); } $sql = 'SELECT c.*, c_lang.* FROM ' . _DB_PREFIX_ . 'category c INNER JOIN ' . _DB_PREFIX_ . 'category_lang c_lang ON ( c.id_category = c_lang.id_category) WHERE c_lang.name LIKE ' . ($word[0] == '-' ? ' \'' . $end_search . pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)) . $end_search . '\'' : ' \'' . $end_search . pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)) . $end_search . '\'') . 'AND c.id_parent = 14'; $painters = $db->executeS($sql); return array('total' => $total, 'result' => $result_properties, 'painters' => $painters); }
public function getContent() { $this->instanceDefaultStates(); $this->_postProcess(); $order_states = OrderState::getOrderStates($this->context->language->id); $currency = new Currency((int) Configuration::get('PS_CURRENCY_DEFAULT')); $id_lang_default = (int) Configuration::get('PS_LANG_DEFAULT'); $languages = Language::getLanguages(false); $languageIds = 'voucher_details¤default_loyalty_state¤none_award_loyalty_state¤convert_loyalty_state¤validation_loyalty_state¤cancel_loyalty_state'; $this->html .= ' <script type="text/javascript"> id_language = Number(' . $id_lang_default . '); </script> <h2>' . $this->l('Loyalty Program') . '</h2> <form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post"> <fieldset> <legend>' . $this->l('Settings') . '</legend> <label>' . $this->l('Ratio') . '</label> <div class="margin-form"> <input type="text" size="2" id="point_rate" name="point_rate" value="' . (double) Configuration::get('PS_LOYALTY_POINT_RATE') . '" /> ' . $currency->sign . ' <label for="point_rate" class="t"> = ' . $this->l('1 reward point') . '.</label> <br /> <label for="point_value" class="t">' . $this->l('1 point = ') . '</label> <input type="text" size="2" name="point_value" id="point_value" value="' . (double) Configuration::get('PS_LOYALTY_POINT_VALUE') . '" /> ' . $currency->sign . ' <label for="point_value" class="t">' . $this->l('for the discount') . '.</label> </div> <div class="clear"></div> <label>' . $this->l('Voucher details') . '</label> <div class="margin-form">'; foreach ($languages as $language) { $this->html .= ' <div id="voucher_details_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $id_lang_default ? 'block' : 'none') . '; float: left;"> <input size="33" type="text" name="voucher_details_' . $language['id_lang'] . '" value="' . Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int) $language['id_lang']) . '" /> </div>'; } $this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'voucher_details', true); $this->html .= ' </div> <div class="clear" style="margin-top: 20px"></div> <label>' . $this->l('Minimum amount in which the voucher can be used') . '</label> <div class="margin-form"> <input type="text" size="2" name="minimal" value="' . (double) Configuration::get('PS_LOYALTY_MINIMAL') . '" /> ' . $currency->sign . ' </div> <div class="clear" style="margin-top: 20px"></div> <label>' . $this->l('Give points on discounted products') . ' </label> <div class="margin-form"> <input type="radio" name="PS_LOYALTY_NONE_AWARD" id="PS_LOYALTY_NONE_AWARD_on" value="1" ' . (Configuration::get('PS_LOYALTY_NONE_AWARD') ? 'checked="checked" ' : '') . '/> <label class="t" for="PS_LOYALTY_NONE_AWARD_on"><img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Yes') . '" /></label> <input type="radio" name="PS_LOYALTY_NONE_AWARD" id="PS_LOYALTY_NONE_AWARD_off" value="0" ' . (!Configuration::get('PS_LOYALTY_NONE_AWARD') ? 'checked="checked" ' : '') . '/> <label class="t" for="PS_LOYALTY_NONE_AWARD_off"><img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('No') . '" /></label> </div> <div class="clear"></div> <label>' . $this->l('Points are awarded when the order is') . '</label> <div class="margin-form" style="margin-top:10px"> <select id="id_order_state_validation" name="id_order_state_validation">'; foreach ($order_states as $order_state) { $this->html .= '<option value="' . $order_state['id_order_state'] . '" style="background-color:' . $order_state['color'] . ';"'; if ((int) $this->loyaltyStateValidation->id_order_state == $order_state['id_order_state']) { $this->html .= ' selected="selected"'; } $this->html .= '>' . $order_state['name'] . '</option>'; } $this->html .= '</select> </div> <div class="clear"></div> <label>' . $this->l('Points are cancelled when the order is') . '</label> <div class="margin-form" style="margin-top:10px"> <select id="id_order_state_cancel" name="id_order_state_cancel">'; foreach ($order_states as $order_state) { $this->html .= '<option value="' . $order_state['id_order_state'] . '" style="background-color:' . $order_state['color'] . ';"'; if ((int) $this->loyaltyStateCancel->id_order_state == $order_state['id_order_state']) { $this->html .= ' selected="selected"'; } $this->html .= '>' . $order_state['name'] . '</option>'; } $this->html .= '</select> </div> <div class="clear"></div> <label>' . $this->l('Vouchers created by the loyalty system can be used in the following categories :') . '</label>'; $index = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY')); $indexedCategories = isset($_POST['categoryBox']) ? $_POST['categoryBox'] : $index; $helper = new Helper(); $this->html .= '<div class="margin-form">' . $helper->renderCategoryTree(null, $indexedCategories) . '</div>'; $this->html .= ' <p style="padding-left:200px;">' . $this->l('Mark the box(es) of categories in which loyalty vouchers are usable.') . '</p> <div class="clear"></div> <h3 style="margin-top:20px">' . $this->l('Loyalty points progression') . '</h3> <label>' . $this->l('Initial') . '</label> <div class="margin-form">'; foreach ($languages as $language) { $this->html .= ' <div id="default_loyalty_state_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $id_lang_default ? 'block' : 'none') . '; float: left;"> <input size="33" type="text" name="default_loyalty_state_' . $language['id_lang'] . '" value="' . (isset($this->loyaltyStateDefault->name[(int) $language['id_lang']]) ? $this->loyaltyStateDefault->name[(int) $language['id_lang']] : $this->loyaltyStateDefault->name[(int) $id_lang_default]) . '" /> </div>'; } $this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'default_loyalty_state', true); $this->html .= ' </div> <div class="clear"></div> <label>' . $this->l('Unavailable') . '</label> <div class="margin-form">'; foreach ($languages as $language) { $this->html .= ' <div id="none_award_loyalty_state_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $id_lang_default ? 'block' : 'none') . '; float: left;"> <input size="33" type="text" name="none_award_loyalty_state_' . $language['id_lang'] . '" value="' . (isset($this->loyaltyStateNoneAward->name[(int) $language['id_lang']]) ? $this->loyaltyStateNoneAward->name[(int) $language['id_lang']] : $this->loyaltyStateNoneAward->name[(int) $id_lang_default]) . '" /> </div>'; } $this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'none_award_loyalty_state', true); $this->html .= ' </div> <div class="clear"></div> <label>' . $this->l('Converted') . '</label> <div class="margin-form">'; foreach ($languages as $language) { $this->html .= ' <div id="convert_loyalty_state_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $id_lang_default ? 'block' : 'none') . '; float: left;"> <input size="33" type="text" name="convert_loyalty_state_' . $language['id_lang'] . '" value="' . (isset($this->loyaltyStateConvert->name[(int) $language['id_lang']]) ? $this->loyaltyStateConvert->name[(int) $language['id_lang']] : $this->loyaltyStateConvert->name[(int) $id_lang_default]) . '" /> </div>'; } $this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'convert_loyalty_state', true); $this->html .= ' </div> <div class="clear"></div> <label>' . $this->l('Validation') . '</label> <div class="margin-form">'; foreach ($languages as $language) { $this->html .= ' <div id="validation_loyalty_state_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $id_lang_default ? 'block' : 'none') . '; float: left;"> <input size="33" type="text" name="validation_loyalty_state_' . $language['id_lang'] . '" value="' . (isset($this->loyaltyStateValidation->name[(int) $language['id_lang']]) ? $this->loyaltyStateValidation->name[(int) $language['id_lang']] : $this->loyaltyStateValidation->name[(int) $id_lang_default]) . '" /> </div>'; } $this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'validation_loyalty_state', true); $this->html .= ' </div> <div class="clear"></div> <label>' . $this->l('Cancelled') . '</label> <div class="margin-form">'; foreach ($languages as $language) { $this->html .= ' <div id="cancel_loyalty_state_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $id_lang_default ? 'block' : 'none') . '; float: left;"> <input size="33" type="text" name="cancel_loyalty_state_' . $language['id_lang'] . '" value="' . (isset($this->loyaltyStateCancel->name[(int) $language['id_lang']]) ? $this->loyaltyStateCancel->name[(int) $language['id_lang']] : $this->loyaltyStateCancel->name[(int) $id_lang_default]) . '" /> </div>'; } $this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'cancel_loyalty_state', true); $this->html .= ' </div> <div class="clear center"> <input type="submit" style="margin-top:20px" name="submitLoyalty" id="submitLoyalty" value="' . $this->l(' Save ') . '" class="button" /> </div> </fieldset> </form>'; return $this->html; }
public function renderForm() { if (!($group = $this->loadObject(true))) { return; } $this->fields_form = array('legend' => array('title' => $this->l('Customer group'), 'image' => '../img/admin/tab-groups.gif'), 'submit' => array('title' => $this->l(' Save '), 'class' => 'button'), 'input' => array(array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 33, 'required' => true, 'lang' => true, 'hint' => $this->l('Forbidden characters:') . ' 0-9!<>,;?=+()@#"�{}_$%:'), array('type' => 'text', 'label' => $this->l('Discount (%):'), 'name' => 'reduction', 'size' => 33, 'desc' => $this->l('Will automatically apply this value as a discount on all products for members of this customer group.')), array('type' => 'select', 'label' => $this->l('Price display method:'), 'name' => 'price_display_method', 'desc' => $this->l('How prices are displayed in the order summary for this customer group.'), 'options' => array('query' => array(array('id_method' => PS_TAX_EXC, 'name' => $this->l('Tax excluded')), array('id_method' => PS_TAX_INC, 'name' => $this->l('Tax included'))), 'id' => 'id_method', 'name' => 'name')), array('type' => 'radio', 'label' => $this->l('Show prices:'), 'name' => 'show_prices', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'show_prices_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'show_prices_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Customers in this group can view price')), array('type' => 'group_discount_category', 'label' => $this->l('Category discount:'), 'name' => 'reduction', 'size' => 33, 'values' => $group->id ? $this->formatCategoryDiscountList((int) $group->id) : array()), array('type' => 'modules', 'label' => array('auth_modules' => $this->l('Authorized modules:'), 'unauth_modules' => $this->l('Unauthorized modules:')), 'name' => 'auth_modules', 'values' => $this->formatModuleListAuth($group->id)))); if (Shop::isFeatureActive()) { $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso'); } $this->fields_value['reduction'] = isset($group->reduction) ? $group->reduction : 0; $helper = new Helper(); $this->tpl_form_vars['categoryTreeView'] = $helper->renderCategoryTree(null, array(), 'id_category', true, false, array(), true, true); return parent::renderForm(); }