Skip to content

Commit

Permalink
Add sort default type
Browse files Browse the repository at this point in the history
  • Loading branch information
Hồ Ngọc Triển committed Dec 29, 2016
1 parent cd7e21e commit 75a721c
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 30 deletions.
1 change: 1 addition & 0 deletions modules/shops/action_mysql.php
Expand Up @@ -757,6 +757,7 @@ class varchar(25) NOT NULL DEFAULT '',
$data['template_active'] = '0';
$data['download_active'] = '0';
$data['download_groups'] = '6';
$data['sortdefault'] = 0;

foreach ($data as $config_name => $config_value) {
$sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . $lang . "', " . $db->quote($module_name) . ", " . $db->quote($config_name) . ", " . $db->quote($config_value) . ")";
Expand Down
46 changes: 32 additions & 14 deletions modules/shops/admin/setting.php
Expand Up @@ -7,7 +7,6 @@
* @License GNU/GPL version 2 or any later version
* @Createdate 2-9-2010 14:43
*/

if (! defined('NV_IS_FILE_ADMIN')) {
die('Stop!!!');
}
Expand Down Expand Up @@ -71,6 +70,7 @@
$data['groups_notify'] = ! empty($_groups_notify) ? implode(',', array_intersect($_groups_notify, array_keys($groups_list))) : '';
$data['active_tooltip'] = $nv_Request->get_int('active_tooltip', 'post', 0);
$data['show_product_code'] = $nv_Request->get_int('show_product_code', 'post', 0);
$data['sortdefault'] = $nv_Request->get_int('sortdefault', 'post', 0);
$data['show_compare'] = $nv_Request->get_int('show_compare', 'post', 0);
$data['show_displays'] = $nv_Request->get_int('show_displays', 'post', 0);
$data['use_shipping'] = $nv_Request->get_int('use_shipping', 'post', 0);
Expand All @@ -93,7 +93,7 @@
$data['download_active'] = $nv_Request->get_int('download_active', 'post', 0);
$_dowload_groups = $nv_Request->get_array('download_groups', 'post', array());
$data['download_groups'] = ! empty($_dowload_groups) ? implode(',', nv_groups_post(array_intersect($_dowload_groups, array_keys($groups_list_default)))) : '';

if ($error == '') {
$sth = $db->prepare("UPDATE " . NV_CONFIG_GLOBALTABLE . " SET config_value = :config_value WHERE lang = '" . NV_LANG_DATA . "' AND module = :module_name AND config_name = :config_name");
$sth->bindParam(':module_name', $module_name, PDO::PARAM_STR);
Expand All @@ -102,16 +102,16 @@
$sth->bindParam(':config_value', $config_value, PDO::PARAM_STR);
$sth->execute();
}

$mid = intval($currencies_array[$data['money_unit']]['numeric']);

$sql = "UPDATE " . $db_config['prefix'] . "_" . $module_data . "_money_" . NV_LANG_DATA . " SET exchange = '1' WHERE id = " . $mid;
$db->query($sql);

nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['setting'], "Setting", $admin_info['userid']);
$nv_Cache->delMod('settings');
$nv_Cache->delMod($module_name);

Header("Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . '=setting');
die();
}
Expand All @@ -123,7 +123,7 @@
$sql = "SELECT * FROM " . $db_config['prefix'] . "_" . $module_data . "_payment ORDER BY weight ASC";
$result = $db->query($sql);
$num_items = $result->rowCount();

while ($row = $result->fetch()) {
$array_setting_payment[$row['payment']] = $row;
}
Expand All @@ -135,9 +135,12 @@
$xtpl->assign('MODULE_NAME', $module_name);

// Số sản phẩm hiển thị trên một dòng
for ($i = 1; $i <= 10; $i++) {
for ($i = 1; $i <= 10; $i ++) {
if (24 % $i == 0) {
$xtpl->assign('PER_ROW', array( 'value' => $i, 'selected' => $data['per_row'] == $i ? 'selected="selected"' : '' ));
$xtpl->assign('PER_ROW', array(
'value' => $i,
'selected' => $data['per_row'] == $i ? 'selected="selected"' : ''
));
$xtpl->parse('main.per_row');
}
}
Expand Down Expand Up @@ -256,7 +259,7 @@

// Tien te
$result = $db->query("SELECT code, currency FROM " . $db_config['prefix'] . "_" . $module_data . "_money_" . NV_LANG_DATA . " ORDER BY code DESC");
while (list($code, $currency) = $result->fetch(3)) {
while (list ($code, $currency) = $result->fetch(3)) {
$array_temp = array();
$array_temp['value'] = $code;
$array_temp['title'] = $code . " - " . $currency;
Expand All @@ -267,7 +270,7 @@

// Don vi khoi luong
$result = $db->query("SELECT code, title FROM " . $db_config['prefix'] . "_" . $module_data . "_weight_" . NV_LANG_DATA . " ORDER BY code DESC");
while (list($code, $title) = $result->fetch(3)) {
while (list ($code, $title) = $result->fetch(3)) {
$array_temp = array();
$array_temp['value'] = $code;
$array_temp['title'] = $code . " - " . $title;
Expand All @@ -285,7 +288,7 @@
));
$xtpl->parse('main.download_groups');
}
if (!$data['download_active']) {
if (! $data['download_active']) {
$xtpl->parse('main.download_groups_none');
}

Expand All @@ -300,7 +303,7 @@
$a = 0;
$all_page = sizeof($array_setting_payment);
$payment = $nv_Request->get_string('payment', 'get', 0);

foreach ($array_setting_payment as $value) {
$value['titleactive'] = (! empty($value['active'])) ? $lang_global['yes'] : $lang_global['no'];
$value['link_edit'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=payport&amp;payment=" . $value['payment'];
Expand All @@ -311,14 +314,29 @@
$value['slect_weight'] = drawselect_number($value['payment'], 1, $all_page + 1, $value['weight'], "nv_chang_pays('" . $value['payment'] . "',this,url_change_weight,url_back);");
$xtpl->assign('DATA_PM', $value);
$xtpl->parse('main.payment.paymentloop');
++$a;
++ $a;
}
$xtpl->assign('url_back', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op);
$xtpl->assign('url_change', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=changepay");
$xtpl->assign('url_active', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=actpay");
$xtpl->parse('main.payment');
}

$array_sortdefault = array(
0 => $lang_module['setting_sortdefault_0'],
1 => $lang_module['setting_sortdefault_1'],
2 => $lang_module['setting_sortdefault_2']
);
foreach ($array_sortdefault as $index => $value) {
$sl = $data['sortdefault'] == $index ? 'selected="selected"' : '';
$xtpl->assign('SORTDEFAULT', array(
'index' => $index,
'value' => $value,
'selected' => $sl
));
$xtpl->parse('main.sortdefault');
}

$xtpl->parse('main');

$contents .= $xtpl->text('main');
Expand Down
26 changes: 16 additions & 10 deletions modules/shops/blocks/global.block_bxproduct_center.php
Expand Up @@ -22,14 +22,14 @@
*/
function nv_block_config_bxproduct_center_blocks($module, $data_block, $lang_block)
{
global $db_config, $site_mods;
global $db_config, $site_mods, $nv_Cache;

$html = "<tr>";
$html .= " <td>" . $lang_block['blockid'] . "</td>";
$html .= " <td><select name=\"config_blockid\" class=\"form-control w200\">\n";

$sql = "SELECT bid, " . NV_LANG_DATA . "_title," . NV_LANG_DATA . "_alias FROM " . $db_config['prefix'] . "_" . $site_mods[$module]['module_data'] . "_block_cat ORDER BY weight ASC";
$list = nv_db_cache($sql, 'catid', $module);
$list = $nv_Cache->db($sql, 'catid', $module);

foreach ($list as $l) {
$sel = ($data_block['blockid'] == $l['bid']) ? ' selected' : '';
Expand Down Expand Up @@ -161,7 +161,7 @@ function nv_get_price_tmp($mod_name, $mod_data, $mod_file, $pro_id)
*/
function nv_global_bxproduct_center($block_config)
{
global $site_mods, $global_config, $module_config, $lang_module, $module_name, $global_array_shops_cat, $db_config, $my_head, $db, $pro_config, $money_config, $blockID;
global $site_mods, $global_config, $module_config, $lang_module, $module_name, $global_array_shops_cat, $db_config, $my_head, $db, $pro_config, $money_config, $blockID, $nv_Cache;

$module = $block_config['module'];
$mod_data = $site_mods[$module]['module_data'];
Expand Down Expand Up @@ -200,7 +200,7 @@ function nv_global_bxproduct_center($block_config)
}

$sql = 'SELECT catid, parentid, lev, ' . NV_LANG_DATA . '_title AS title, ' . NV_LANG_DATA . '_alias AS alias, viewcat, numsubcat, subcatid, numlinks, ' . NV_LANG_DATA . '_description AS description, inhome, ' . NV_LANG_DATA . '_keywords AS keywords, groups_view, typeprice FROM ' . $db_config['prefix'] . '_' . $mod_data . '_catalogs ORDER BY sort ASC';
$list = nv_db_cache($sql, 'catid', $module);
$list = $nv_Cache->db($sql, 'catid', $module);
foreach ($list as $row) {
$global_array_shops_cat[$row['catid']] = array('catid' => $row['catid'], 'parentid' => $row['parentid'], 'title' => $row['title'], 'alias' => $row['alias'], 'link' => NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&amp;' . NV_NAME_VARIABLE . '=' . $module . '&amp;' . NV_OP_VARIABLE . '=' . $row['alias'], 'viewcat' => $row['viewcat'], 'numsubcat' => $row['numsubcat'], 'subcatid' => $row['subcatid'], 'numlinks' => $row['numlinks'], 'description' => $row['description'], 'inhome' => $row['inhome'], 'keywords' => $row['keywords'], 'groups_view' => $row['groups_view'], 'lev' => $row['lev'], 'typeprice' => $row['typeprice']);
}
Expand All @@ -210,7 +210,7 @@ function nv_global_bxproduct_center($block_config)
// Lay ty gia ngoai te
$sql = 'SELECT code, currency, exchange, round, number_format FROM ' . $db_config['prefix'] . '_' . $mod_data . '_money_' . NV_LANG_DATA;
$cache_file = NV_LANG_DATA . '_' . md5($sql) . '_' . NV_CACHE_PREFIX . '.cache';
if (($cache = nv_get_cache($module, $cache_file)) != false) {
if (($cache = $nv_Cache->getItem($module, $cache_file)) != false) {
$money_config = unserialize($cache);
} else {
$money_config = array();
Expand All @@ -220,7 +220,7 @@ function nv_global_bxproduct_center($block_config)
}
$result->closeCursor();
$cache = serialize($money_config);
nv_set_cache($module, $cache_file, $cache);
$nv_Cache->setItem($module, $cache_file, $cache);
}
}

Expand All @@ -238,11 +238,17 @@ function nv_global_bxproduct_center($block_config)
$xtpl->assign('PAGER', $pager);
$xtpl->assign('BLOCKID', $blockID);

//$xtpl->assign( 'WIDTH', $pro_config['homewidth'] );

$db->sqlreset()->select('t1.id, t1.listcatid, t1.' . NV_LANG_DATA . '_title AS title, t1.' . NV_LANG_DATA . '_alias AS alias, t1.homeimgfile, t1.homeimgthumb , t1.homeimgalt, t1.showprice, t1.discount_id')->from($db_config['prefix'] . '_' . $mod_data . '_rows t1')->join('INNER JOIN ' . $db_config['prefix'] . '_' . $mod_data . '_block t2 ON t1.id = t2.id')->where('t2.bid= ' . $block_config['blockid'] . ' AND t1.status =1')->order('t1.id DESC')->limit($num_get);
if ($pro_config['sortdefault'] == 0) {
$orderby = 't1.id DESC';
} elseif ($pro_config['sortdefault'] == 1) {
$orderby = 't1.product_price ASC, t1.id DESC';
} else {
$orderby = 't1.product_price DESC, t1.id DESC';
}

$db->sqlreset()->select('t1.id, t1.listcatid, t1.' . NV_LANG_DATA . '_title AS title, t1.' . NV_LANG_DATA . '_alias AS alias, t1.homeimgfile, t1.homeimgthumb , t1.homeimgalt, t1.showprice, t1.discount_id')->from($db_config['prefix'] . '_' . $mod_data . '_rows t1')->join('INNER JOIN ' . $db_config['prefix'] . '_' . $mod_data . '_block t2 ON t1.id = t2.id')->where('t2.bid= ' . $block_config['blockid'] . ' AND t1.status =1')->order($orderby)->limit($num_get);

$list = nv_db_cache($db->sql(), '', $module);
$list = $nv_Cache->db($db->sql(), '', $module);
foreach ($list as $row) {
$link = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&amp;' . NV_NAME_VARIABLE . '=' . $module . '&amp;' . NV_OP_VARIABLE . '=' . $global_array_shops_cat[$row['listcatid']]['alias'] . '/' . $row['alias'] . $global_config['rewrite_exturl'];

Expand Down
10 changes: 9 additions & 1 deletion modules/shops/blocks/global.block_product_center.php
Expand Up @@ -187,12 +187,20 @@ function nv_global_product_center($block_config)
$xtpl->assign('NUMVIEW', $num_view);
//$xtpl->assign( 'WIDTH', $pro_config['homewidth'] );

if ($pro_config['sortdefault'] == 0) {
$orderby = 't1.id DESC';
} elseif ($pro_config['sortdefault'] == 1) {
$orderby = 't1.product_price ASC, t1.id DESC';
} else {
$orderby = 't1.product_price DESC, t1.id DESC';
}

$db->sqlreset()
->select('t1.id, t1.listcatid, t1.' . NV_LANG_DATA . '_title AS title, t1.' . NV_LANG_DATA . '_alias AS alias, t1.homeimgfile, t1.homeimgthumb , t1.homeimgalt, t1.showprice, t1.discount_id')
->from($db_config['prefix'] . '_' . $mod_data . '_rows t1')
->join('INNER JOIN ' . $db_config['prefix'] . '_' . $mod_data . '_block t2 ON t1.id = t2.id')
->where('t2.bid= ' . $block_config['blockid'] . ' AND t1.status =1')
->order('t1.id DESC')
->order($orderby)
->limit($num_get);

$list = $nv_Cache->db($db->sql(), '', $module);
Expand Down
10 changes: 9 additions & 1 deletion modules/shops/blocks/module.block_product_center.php
Expand Up @@ -47,12 +47,20 @@ function nv_product_center($block_config)
$result = $db->query($db->sql());
$bid = $result->fetchColumn();

if ($pro_config['sortdefault'] == 0) {
$orderby = 't1.id DESC';
} elseif ($pro_config['sortdefault'] == 1) {
$orderby = 't1.product_price ASC, t1.id DESC';
} else {
$orderby = 't1.product_price DESC, t1.id DESC';
}

$db->sqlreset()
->select('t1.id, t1.listcatid, t1.' . NV_LANG_DATA . '_title AS title, t1.' . NV_LANG_DATA . '_alias AS alias, t1.homeimgfile, t1.homeimgthumb , t1.homeimgalt, t1.showprice, t1.discount_id')
->from($db_config['prefix'] . '_' . $module_data . '_rows t1')
->join('INNER JOIN ' . $db_config['prefix'] . '_' . $module_data . '_block t2 ON t1.id = t2.id')
->where('t2.bid= ' . $bid . ' AND t1.status =1')
->order('t1.id DESC')
->order($orderby)
->limit($num);

$array = $nv_Cache->db($db->sql(), 'id', $module_name);
Expand Down
2 changes: 1 addition & 1 deletion modules/shops/funcs/group.php
Expand Up @@ -30,7 +30,7 @@

$nv_Request->get_int('sorts', 'session', 0);
$sorts = $nv_Request->get_int('sort', 'post', 0);
$sorts_old = $nv_Request->get_int('sorts', 'session', 0);
$sorts_old = $nv_Request->get_int('sorts', 'session', $pro_config['sortdefault']);
$sorts = $nv_Request->get_int('sorts', 'post', $sorts_old);

$nv_Request->get_string('viewtype', 'session', '');
Expand Down
2 changes: 1 addition & 1 deletion modules/shops/funcs/main.php
Expand Up @@ -17,7 +17,7 @@

$nv_Request->get_int('sorts', 'session', 0);
$sorts = $nv_Request->get_int('sort', 'post', 0);
$sorts_old = $nv_Request->get_int('sorts', 'session', 0);
$sorts_old = $nv_Request->get_int('sorts', 'session', $pro_config['sortdefault']);
$sorts = $nv_Request->get_int('sorts', 'post', $sorts_old);

$compare_id = $nv_Request->get_string($module_data . '_compare_id', 'session', '');
Expand Down
10 changes: 9 additions & 1 deletion modules/shops/funcs/search.php
Expand Up @@ -69,6 +69,14 @@ function BoldKeywordInStr($str, $keyword)
$dbkey = $db->dblikeescape($key);
$where = "AND ( product_code LIKE '%" . $dbkey . "%' OR " . NV_LANG_DATA . "_title LIKE '%" . $dbkey . "%' OR " . NV_LANG_DATA . "_bodytext LIKE '%" . $dbkey . "%' ) ";

if ($pro_config['sortdefault'] == 0) {
$orderby = 'id DESC';
} elseif ($pro_config['sortdefault'] == 1) {
$orderby = 'product_price ASC, t1.id DESC';
} else {
$orderby = 'product_price DESC, t1.id DESC';
}

if ($catid != 0) {
if ($global_array_shops_cat[$catid]['numsubcat'] == 0) {
$where .= 'AND listcatid=' . $catid;
Expand All @@ -94,7 +102,7 @@ function BoldKeywordInStr($str, $keyword)

$numRecord = $db->query($db->sql())->fetchColumn();

$db->select('id, ' . NV_LANG_DATA . '_title, ' . NV_LANG_DATA . '_alias, listcatid, ' . NV_LANG_DATA . '_hometext, publtime, homeimgfile, homeimgthumb')->order('id DESC')->limit($per_pages)->offset(($page - 1) * $per_page);
$db->select('id, ' . NV_LANG_DATA . '_title, ' . NV_LANG_DATA . '_alias, listcatid, ' . NV_LANG_DATA . '_hometext, publtime, homeimgfile, homeimgthumb')->order($orderby)->limit($per_pages)->offset(($page - 1) * $per_page);

$result = $db->query($db->sql());

Expand Down
2 changes: 1 addition & 1 deletion modules/shops/funcs/viewcat.php
Expand Up @@ -58,7 +58,7 @@
$cache_file = '';
$nv_Request->get_int('sorts', 'session', 0);
$sorts = $nv_Request->get_int('sort', 'post', 0);
$sorts_old = $nv_Request->get_int('sorts', 'session', 0);
$sorts_old = $nv_Request->get_int('sorts', 'session', $pro_config['sortdefault']);
$sorts = $nv_Request->get_int('sorts', 'post', $sorts_old);

$nv_Request->get_string('viewtype', 'session', '');
Expand Down
4 changes: 4 additions & 0 deletions modules/shops/language/admin_vi.php
Expand Up @@ -128,6 +128,10 @@
$lang_module['setting_group_notify_note'] = 'Các thành viên thuộc nhóm được chọn sẽ nhận thông báo qua email khi có hoạt động mới (đơn hàng mới, hoàn tất thanh toán,...).';
$lang_module['setting_active_tooltip'] = 'Bật chức năng tooltip cho sản phẩm';
$lang_module['setting_show_product_code'] = 'Hiển thị mã sản phẩm';
$lang_module['setting_sortdefault'] = 'Sắp xếp mặc định';
$lang_module['setting_sortdefault_0'] = 'Sản phẩm mới lên đầu';
$lang_module['setting_sortdefault_1'] = 'Giá tăng dần';
$lang_module['setting_sortdefault_2'] = 'Giá giảm dần';
$lang_module['setting_active_wishlist'] = 'Sử dụng chức năng Sản phẩm yêu thích';
$lang_module['setting_active_gift'] = 'Sử dụng chức năng nhận quà tặng';
$lang_module['setting_active_warehouse'] = 'Sử dụng chức năng nhập kho';
Expand Down
10 changes: 10 additions & 0 deletions themes/admin_default/modules/shops/setting.tpl
Expand Up @@ -171,6 +171,16 @@
<td><strong>{LANG.setting_show_product_code}</strong></td>
<td><input type="checkbox" value="1" name="show_product_code" {ck_show_product_code} id="show_product_code" /></td>
</tr>
<tr>
<td><strong>{LANG.setting_sortdefault}</strong></td>
<td>
<select name="sortdefault" class="form-control w200">
<!-- BEGIN: sortdefault -->
<option value="{SORTDEFAULT.index}" {SORTDEFAULT.selected}>{SORTDEFAULT.value}</option>
<!-- END: sortdefault -->
</select>
</td>
</tr>
</tbody>
</table>
</div>
Expand Down

0 comments on commit 75a721c

Please sign in to comment.