I am using Raiwa's code to display a banner in the stores header but changed it to an index module.
I have also changed the template code to display 2 banners side by side. The bit I can not seem to figure out is what to change/modify so that I can select 2 unique banners as at the moment it shows the same banner twice.
Code: Select all
class cm_i_index_banners extends abstract_executable_module {
const CONFIG_KEY_BASE = 'MODULE_CONTENT_INDEX_BANNERS_';
public function __construct() {
parent::__construct(__FILE__);
}
function execute() {
$content_width = MODULE_CONTENT_INDEX_BANNERS_CONTENT_WIDTH;
if (tep_not_null(MODULE_CONTENT_INDEX_BANNERS_GROUPS)) {
$banner_query = tep_db_query("SELECT a.*, ai.*
FROM
(SELECT *
FROM advert
WHERE status = '1'
AND advert_group IN (" . MODULE_CONTENT_INDEX_BANNERS_GROUPS . ")
ORDER BY rand()) a
LEFT JOIN advert_info ai ON a.advert_id = ai.advert_id AND ai.languages_id = " . (int)$_SESSION['languages_id']
. " GROUP BY advert_group");
if (tep_db_num_rows($banner_query) > 0) {
$tpl_data = [ 'group' => $this->group, 'file' => __FILE__ ];
include 'includes/modules/content/cm_template.php';
}
}
}
protected function get_parameters() {
return [
'MODULE_CONTENT_INDEX_BANNERS_STATUS' => [
'title' => 'Enable Static Index Banners',
'value' => 'True',
'desc' => 'Do you want to enable the Static Index Banner content module?',
'set_func' => "tep_cfg_select_option(['True', 'False'], ",
],
'MODULE_CONTENT_INDEX_BANNERS_CONTENT_WIDTH' => [
'title' => 'Content Width',
'value' => '12',
'desc' => 'What width container should the content be shown in?',
'set_func' => "tep_cfg_select_option(['12', '11', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1'], ",
],
'MODULE_CONTENT_INDEX_BANNERS_BANNER_WIDTH' => [
'title' => 'Banner Width',
'value' => '6',
'desc' => 'What width container should each banner be shown in?',
'set_func' => "tep_cfg_select_option(['12', '11', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1'], ",
],
'MODULE_CONTENT_INDEX_BANNERS_GROUPS' => [
'title' => 'Banner Groups',
'value' => '',
'desc' => 'Check the Banner Groups to show in this module.',
'use_func' => 'cm_i_index_banners::show_modules',
'set_func' => 'cm_i_index_banners::edit_modules(',
],
'MODULE_CONTENT_INDEX_BANNERS_SORT_ORDER' => [
'title' => 'Sort Order',
'value' => '0',
'desc' => 'Sort order of display. Lowest is displayed first.',
],
];
}
public static function readonly($value) {
return $value;
}
public static function show_modules($text) {
return nl2br(implode("\n", explode(',', str_replace('\'', '', $text))));
}
public static function edit_modules($values, $key) {
global $PHP_SELF;
$group_query = tep_db_query("SELECT DISTINCT advert_group FROM advert WHERE status = '1'");
$values_array = explode(',', $values);
$output = '';
while ($group = tep_db_fetch_array($group_query)) {
$output .= tep_draw_checkbox_field($key . 'st_group_module[]', '\'' . $group['advert_group'] . '\'', in_array('\'' . $group['advert_group'] . '\'', $values_array), null, True) . ' ' . tep_output_string($group['advert_group']) . '<br />';
}
if (!empty($output)) {
$output = '<br>' . substr($output, 0, -6);
}
$output .= tep_draw_hidden_field('configuration[' . $key . ']', '', 'id="' . $key . 'htrn_group_modules"');
$output .= '<script>
function ' . $key . 'htrn_group_update_cfg_value() {
var ' . $key . 'htrn_group_selected_modules = \'\';
if ($(\'input[name="' . $key . 'st_group_module[]"]\').length > 0) {
$(\'input[name="' . $key . 'st_group_module[]"]:checked\').each(function() {
' . $key . 'htrn_group_selected_modules += $(this).attr(\'value\') + \',\';
});
if (' . $key . 'htrn_group_selected_modules.length > 0) {
' . $key . 'htrn_group_selected_modules = ' . $key . 'htrn_group_selected_modules.substring(0, ' . $key . 'htrn_group_selected_modules.length - 1);
}
}
$(\'#' . $key . 'htrn_group_modules\').val(' . $key . 'htrn_group_selected_modules);
}
$(function() {
' . $key . 'htrn_group_update_cfg_value();
if ($(\'input[name="' . $key . 'st_group_module[]"]\').length > 0) {
$(\'input[name="' . $key . 'st_group_module[]"]\').change(function() {
' . $key . 'htrn_group_update_cfg_value();
});
}
});
</script>';
return $output;
}
}
Code: Select all
<div class="row col-sm-<?= $content_width ?> cm-i-index-banners m-0">
<div class="col-sm-6 w-100 h-auto p-1 align-center">
<?php
while ($banner_values = tep_db_fetch_array($banner_query)) {
echo '<div class="cm-i-index-banners col-sm-' . MODULE_CONTENT_INDEX_BANNERS_BANNER_WIDTH . ' w-100 h-auto m-0 p-0">';
if (tep_not_null($banner_values['advert_html_text'])) {
echo $banner_values['advert_html_text'];
} else {
if (tep_not_null($banner_values['advert_url'])) {
echo '<a href="' . tep_href_link($banner_values['advert_url'], $banner_values['advert_fragment']) . '" target="_blank" rel="noopener">' . tep_image('images/' . $banner_values['advert_image'], htmlspecialchars($banner_values['advert_title'])) . '</a>';
} else {
echo tep_image('images/' . $banner_values['advert_image'], htmlspecialchars($banner_values['advert_title']));
}
echo '</div>';
}
?>
</div>
<div class="col-sm-6 w-100 h-auto m-0 p-1 align-center">
<?php
echo '<div class="cm-i-index-banners col-sm-' . MODULE_CONTENT_INDEX_BANNERS_BANNER_WIDTH . ' w-100 h-auto m-0 p-0">';
if (tep_not_null($banner_values['advert_html_text'])) {
echo $banner_values['advert_html_text'];
} else {
if (tep_not_null($banner_values['advert_url'])) {
echo '<a href="' . tep_href_link($banner_values['advert_url'], $banner_values['advert_fragment']) . '" target="_blank" rel="noopener">' . tep_image('images/' . $banner_values['advert_image'], htmlspecialchars($banner_values['advert_title'])) . '</a>';
} else {
echo tep_image('images/' . $banner_values['advert_image'], htmlspecialchars($banner_values['advert_title']));
}
}
echo '</div>';
}
?>
</div>
</div>