Skip to content

Commit 240c53d

Browse files
Merge pull request #706 from hqc210185/develop
bổ sung issue
2 parents e254c79 + b2c39e5 commit 240c53d

File tree

11 files changed

+143
-45
lines changed

11 files changed

+143
-45
lines changed

modules/shops/blocks/global.block_search.php

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,18 @@ function nv_search_product($block_config)
3232

3333
include NV_ROOTDIR . '/modules/' . $mod_file . '/language/' . NV_LANG_DATA . '.php';
3434

35-
$keyword = $nv_Request->get_string('keyword', 'get');
36-
$price1_temp = $nv_Request->get_string('price1', 'get', '');
37-
$price2_temp = $nv_Request->get_string('price2', 'get', '');
35+
$keyword = $nv_Request->get_string('q', 'get');
36+
$price1 = $nv_Request->get_string('price1', 'get', '');
37+
$price2 = $nv_Request->get_string('price2', 'get', '');
3838
$typemoney = $nv_Request->get_string('typemoney', 'get', '');
39-
$cataid = $nv_Request->get_int('cata', 'get', 0);
39+
$cataid = $nv_Request->get_int('catid', 'get', 0);
40+
41+
$price1 = preg_replace('/[^0-9,\.]/', '', $price1);
42+
$price2 = preg_replace('/[^0-9,\.]/', '', $price2);
4043

4144
if ($cataid == 0) {
4245
$cataid = $catid;
4346
}
44-
if ($price1_temp == '') {
45-
$price1 = -1;
46-
} else {
47-
$price1 = floatval($price1_temp);
48-
}
49-
if ($price2_temp == '') {
50-
$price2 = -1;
51-
} else {
52-
$price2 = floatval($price2_temp);
53-
}
5447

5548
if (file_exists(NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/modules/' . $mod_file . '/block.search.tpl')) {
5649
$block_theme = $global_config['module_theme'];
@@ -95,13 +88,6 @@ function nv_search_product($block_config)
9588
$xtpl->parse('main.typemoney');
9689
}
9790

98-
if ($price1 == -1) {
99-
$price1 = '';
100-
}
101-
if ($price2 == -1) {
102-
$price2 = '';
103-
}
104-
10591
$xtpl->assign('value_keyword', $keyword);
10692
$xtpl->assign('value_price1', $price1);
10793
$xtpl->assign('value_price2', $price2);

modules/shops/funcs/search.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,22 @@ function BoldKeywordInStr($str, $keyword)
3030
$from_date = $nv_Request->get_title('from_date', 'get', '', 1);
3131
$to_date = $nv_Request->get_title('to_date', 'get', '', 1);
3232
$catid = $nv_Request->get_int('catid', 'get', 0);
33+
$price1_temp = $nv_Request->get_string('price1', 'get', '');
34+
$price2_temp = $nv_Request->get_string('price2', 'get', '');
35+
36+
$price1_temp = preg_replace('/[^0-9,\.]/', '', $price1_temp);
37+
$price2_temp = preg_replace('/[^0-9,\.]/', '', $price2_temp);
38+
39+
$price1_sql = preg_replace('/[^0-9]/', '', $price1_temp);
40+
$price2_sql = preg_replace('/[^0-9]/', '', $price2_temp);
41+
$typemoney = $nv_Request->get_string('typemoney', 'get', '');
42+
3343
$check_num = $nv_Request->get_int('choose', 'get', 1);
3444
$pages = $nv_Request->get_int('page', 'get', 1);
3545
$date_array['from_date'] = $from_date;
3646
$date_array['to_date'] = $to_date;
47+
$array_price['price1'] = $price1_temp;
48+
$array_price['price2'] = $price2_temp;
3749
$per_pages = 20;
3850

3951
$page_url = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=search';
@@ -66,8 +78,7 @@ function BoldKeywordInStr($str, $keyword)
6678
);
6779
}
6880

69-
$contents = call_user_func('search_theme', $key, $check_num, $date_array, $array_cat_search);
70-
81+
$contents = call_user_func('search_theme', $key, $check_num, $date_array, $array_cat_search, $array_price, $typemoney);
7182
$where = '';
7283
$tbl_src = '';
7384

@@ -101,6 +112,18 @@ function BoldKeywordInStr($str, $keyword)
101112
$where .= " AND ( publtime < $fdate AND publtime >= $tdate ) ";
102113
}
103114

115+
if (!empty($price1_sql)) {
116+
$where .= " AND product_price >= " . $price1_sql;
117+
}
118+
119+
if (!empty($price2_sql)) {
120+
$where .= " AND product_price <= " . $price2_sql;
121+
}
122+
123+
if (!empty($typemoney)) {
124+
$where .= " AND money_unit = " . $db->quote($typemoney);
125+
}
126+
104127
$table_search = $db_config['prefix'] . '_' . $module_data . '_rows';
105128

106129
// Fetch Limit

modules/shops/funcs/viewcat.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@
117117
$page_url .= '/page-' . $page;
118118
}
119119
$canonicalUrl = getCanonicalUrl($page_url);
120-
121120
if (empty($contents)) {
122121
$data_content = [];
123122

@@ -173,6 +172,33 @@
173172
$data_content['count'] = 0;
174173
$data_content['data'] = [];
175174

175+
// Lấy dữ liệu cho cat cha
176+
$array_info_i = $global_array_shops_cat[$catid];
177+
$db->sqlreset()
178+
->select('COUNT(*)')
179+
->from($db_config['prefix'] . '_' . $module_data . '_rows t1')
180+
->join('INNER JOIN ' . $db_config['prefix'] . '_' . $module_data . '_catalogs t2 ON t2.catid = t1.listcatid')
181+
->where('t1.listcatid = ' . $catid . ' AND t1.status = 1');
182+
183+
$num_pro_parent = $db->query($db->sql())->fetchColumn();
184+
185+
$db->select('t1.id, t1.listcatid, t1.publtime, t1.' . NV_LANG_DATA . '_title,
186+
t1.' . NV_LANG_DATA . '_alias, t1.' . NV_LANG_DATA . '_hometext, t1.homeimgalt, t1.homeimgfile,
187+
t1.homeimgthumb, t1.product_code, t1.product_number, t1.product_price, t1.money_unit, t1.discount_id,
188+
t1.showprice, t1.' . NV_LANG_DATA . '_gift_content, t1.gift_from,
189+
t1.gift_to, t2.newday, t2.image')
190+
->order($orderby)
191+
->limit($array_info_i['numlinks'])
192+
->offset(($page - 1) * $array_info_i['numlinks']);
193+
$result = $db->query($db->sql());
194+
195+
$data_content_parent = GetDataIn($result, $catid);
196+
$data_content_parent['count'] = $num_pro_parent;
197+
$base_url_parent = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&amp;' . NV_NAME_VARIABLE . '=' . $module_name . '&amp;' . NV_OP_VARIABLE . '=' . $global_array_shops_cat[$catid]['alias'];
198+
$pages = nv_alias_page('', $base_url_parent, $num_pro_parent, $array_info_i['numlinks'], $page);
199+
$content_parent_html = nv_template_viewgrid($data_content_parent['data'], $pages);
200+
// =========================
201+
176202
$array_subcatid = explode(',', $global_array_shops_cat[$catid]['subcatid']);
177203

178204
foreach ($array_subcatid as $catid_i) {
@@ -245,11 +271,11 @@
245271
$data_content['count'] += $num_pro;
246272
}
247273

248-
if ($page > 1) {
249-
nv_redirect_location(NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name, true);
250-
}
274+
$content_parent['html'] = $content_parent_html;
275+
$content_parent['page'] = $page;
276+
$data_content['count'] += $num_pro_parent; // Cộng thêm số lượng sản phẩm ở loại sản phẩm cha
251277

252-
$contents = call_user_func('nv_template_viewcat', $data_content, $compare_id, '', $sorts);
278+
$contents = call_user_func('nv_template_viewcat', $data_content, $compare_id, '', $sorts, 'viewgrid', $content_parent);
253279
} else {
254280
/*
255281
* Hiển thị danh sách sản phẩm

modules/shops/global.functions.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,13 @@ function GetGroupID($pro_id, $group_by_parent = 0)
514514
global $db, $db_config, $module_data, $global_array_group;
515515

516516
$data = array();
517-
$result = $db->query('SELECT group_id FROM ' . $db_config['prefix'] . '_' . $module_data . '_group_items where pro_id=' . $pro_id);
517+
$db->sqlreset()
518+
->select('t1.group_id')
519+
->from($db_config['prefix'] . '_' . $module_data . '_group_items t1')
520+
->join('INNER JOIN ' . $db_config['prefix'] . '_' . $module_data . '_group t2 ON t1.group_id = t2.groupid')
521+
->where('t1.pro_id=' . $pro_id)
522+
->order('t2.weight');
523+
$result = $db->query($db->sql());
518524
while ($row = $result->fetch()) {
519525
if ($group_by_parent) {
520526
$parentid = $global_array_group[$row['group_id']]['parentid'];
@@ -523,6 +529,14 @@ function GetGroupID($pro_id, $group_by_parent = 0)
523529
$data[] = $row['group_id'];
524530
}
525531
}
532+
// Sắp xếp lại thứ tự
533+
if (!empty($group_by_parent)) {
534+
uksort($data, function ($item1, $item2) {
535+
global $global_array_group;
536+
if ($global_array_group[$item1]['weight'] == $global_array_group[$item2]['weight']) return 0;
537+
return ($global_array_group[$item1]['weight'] < $global_array_group[$item2]['weight']) ? -1 : 1;
538+
});
539+
}
526540
return $data;
527541
}
528542

modules/shops/site.functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
$global_array_shops_cat = $nv_Cache->db($sql, 'catid', $module_name);
1818

1919
// Nhóm sản phẩm
20-
$sql = 'SELECT groupid, parentid, lev, ' . NV_LANG_DATA . '_title AS title, ' . NV_LANG_DATA . '_alias AS alias, viewgroup, numsubgroup, subgroupid, ' . NV_LANG_DATA . '_description AS description, inhome, indetail, in_order, ' . NV_LANG_DATA . '_keywords AS keywords, numpro, image, is_require FROM ' . $db_config['prefix'] . '_' . $module_data . '_group ORDER BY sort ASC';
20+
$sql = 'SELECT groupid, parentid, weight, lev, ' . NV_LANG_DATA . '_title AS title, ' . NV_LANG_DATA . '_alias AS alias, viewgroup, numsubgroup, subgroupid, ' . NV_LANG_DATA . '_description AS description, inhome, indetail, in_order, ' . NV_LANG_DATA . '_keywords AS keywords, numpro, image, is_require FROM ' . $db_config['prefix'] . '_' . $module_data . '_group ORDER BY sort ASC';
2121
$global_array_group = $nv_Cache->db($sql, 'groupid', $module_name);
2222

2323
// Lay ty gia ngoai te

modules/shops/theme.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,9 +1271,9 @@ function history_order($data_content)
12711271
* @param mixed $array_cat_search
12721272
* @return
12731273
*/
1274-
function search_theme($key, $check_num, $date_array, $array_cat_search)
1274+
function search_theme($key, $check_num, $date_array, $array_cat_search, $array_price, $typemoney)
12751275
{
1276-
global $module_name, $module_info, $module_file, $lang_module, $module_name;
1276+
global $module_name, $module_info, $module_file, $lang_module, $module_name, $nv_Cache, $db_config, $module_data;
12771277

12781278
$xtpl = new XTemplate("search.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file);
12791279

@@ -1282,9 +1282,21 @@ function search_theme($key, $check_num, $date_array, $array_cat_search)
12821282
$xtpl->assign('MODULE_NAME', $module_name);
12831283
$xtpl->assign('TO_DATE', $date_array['to_date']);
12841284
$xtpl->assign('FROM_DATE', $date_array['from_date']);
1285+
$xtpl->assign('price1', $array_price['price1']);
1286+
$xtpl->assign('price2', $array_price['price2']);
12851287
$xtpl->assign('KEY', $key);
12861288
$xtpl->assign('OP_NAME', 'search');
12871289

1290+
// Get money
1291+
$sql = 'SELECT code, currency FROM ' . $db_config['prefix'] . '_' . $module_data . '_money_' . NV_LANG_DATA;
1292+
$list = $nv_Cache->db($sql, '', $module_data);
1293+
1294+
foreach ($list as $row) {
1295+
$row['selected'] = ($typemoney == $row['code']) ? 'selected="selected"' : '';
1296+
$xtpl->assign('ROW', $row);
1297+
$xtpl->parse('main.typemoney');
1298+
}
1299+
12881300
foreach ($array_cat_search as $search_cat) {
12891301
$xtpl->assign('SEARCH_CAT', $search_cat);
12901302
$xtpl->parse('main.search_cat');
@@ -1946,7 +1958,7 @@ function nv_template_viewlist($array_data, $page)
19461958
* @param mixed $pages
19471959
* @return
19481960
*/
1949-
function nv_template_viewcat($data_content, $compare_id, $pages, $sort = 0, $viewtype = 'viewgrid')
1961+
function nv_template_viewcat($data_content, $compare_id, $pages, $sort = 0, $viewtype = 'viewgrid', $content_parent = '')
19501962
{
19511963
global $module_info, $lang_module, $module_file, $module_upload, $module_name, $pro_config, $array_displays, $array_wishlist_id, $op, $global_array_shops_cat, $global_array_group, $my_head, $page;
19521964

@@ -1958,6 +1970,15 @@ function nv_template_viewcat($data_content, $compare_id, $pages, $sort = 0, $vie
19581970
$xtpl->assign('CAT_NAME', $data_content['title']);
19591971
$xtpl->assign('COUNT', $data_content['count']);
19601972

1973+
if (!empty($content_parent)) {
1974+
$xtpl->assign('PARENT_HTML', $content_parent['html']);
1975+
$xtpl->parse('main.parent_html');
1976+
}
1977+
if (!empty($content_parent['page'] > 1)) {
1978+
$xtpl->parse('main');
1979+
return $xtpl->text('main');
1980+
}
1981+
19611982
// Hiển thị phần giới thiệu loại sản phẩm
19621983
if ($op != 'group') {
19631984
if (($global_array_shops_cat[$data_content['id']]['viewdescriptionhtml'] and $page == 1) or $global_array_shops_cat[$data_content['id']]['viewdescriptionhtml'] == 2) {

modules/shops/version.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
'modfuncs' => 'main,viewcat,detail,search,cart,order,payment,complete,history,group,search_result,compare,wishlist,tag,point,shippingajax,download, blockcat,ajax',
1717
'is_sysmod' => 0, // 1:0 => Co phai la module he thong hay khong
1818
'virtual' => 1, // 1:0 => Co cho phep ao hao module hay khong
19-
'version' => '4.5.02', // Module Shops 4 Release Candidate 1
20-
'date' => 'Saturday, September 24, 2022 15:00:00 GMT+07:00', // Ngay phat hanh phien ban
19+
'version' => '4.5.03', // Module Shops 4 Release Candidate 1
20+
'date' => 'Thursday, April 13, 2023 15:00:00 GMT+07:00', // Ngay phat hanh phien ban
2121
'author' => 'VINADES <[email protected]>', // Tac gia
2222
'note' => '', // Ghi chu
2323
'uploads_dir' => array(
@@ -29,4 +29,4 @@
2929
'files_dir' => array(
3030
$module_upload . '/files_tpl'
3131
)
32-
);
32+
);

themes/default/js/shops.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ function onsubmitsearch(module) {
187187
var typemoney = $('#typemoney').val();
188188
if (typemoney == null)
189189
typemoney = '';
190-
var cataid = $('#cata').val();
191-
if (keyword == '' && price1 == '' && price2 == '' && cataid == 0) {
190+
var catid = $('#cata').val();
191+
if (keyword == '' && price1 == '' && price2 == '' && catid == 0) {
192192
return false;
193193
} else {
194-
window.location.href = nv_base_siteurl + 'index.php?' + nv_lang_variable + '=' + nv_lang_data + '&' + nv_name_variable + '=' + module + '&' + nv_fc_variable + '=search_result&keyword=' + rawurlencode(keyword) + '&price1=' + price1 + '&price2=' + price2 + '&typemoney=' + typemoney + '&cata=' + cataid;
194+
window.location.href = nv_base_siteurl + 'index.php?' + nv_lang_variable + '=' + nv_lang_data + '&' + nv_name_variable + '=' + module + '&' + nv_fc_variable + '=search&q=' + rawurlencode(keyword) + '&price1=' + price1 + '&price2=' + price2 + '&typemoney=' + typemoney + '&catid=' + catid;
195195
}
196196
return false;
197197
}
@@ -337,9 +337,9 @@ function check_price(id_pro, pro_unit) {
337337

338338
if (data.length > 0) {
339339
$.ajax({
340-
method : "POST",
341-
url : nv_base_siteurl + 'index.php?' + nv_lang_variable + '=' + nv_lang_data + '&' + nv_name_variable + '=' + nv_module_name + '&' + nv_fc_variable + '=detail&nocache=' + new Date().getTime(),
342-
data : 'check_quantity=1&id_pro=' + id_pro + '&pro_unit=' + pro_unit + '&listid=' + data,
340+
method: "POST",
341+
url: nv_base_siteurl + 'index.php?' + nv_lang_variable + '=' + nv_lang_data + '&' + nv_name_variable + '=' + nv_module_name + '&' + nv_fc_variable + '=detail&nocache=' + new Date().getTime(),
342+
data: 'check_quantity=1&id_pro=' + id_pro + '&pro_unit=' + pro_unit + '&listid=' + data,
343343
success: function(res) {
344344
var s = res.split('_');
345345
if (s[0] == 'OK') {
@@ -357,7 +357,8 @@ function check_price(id_pro, pro_unit) {
357357
}
358358

359359
function fix_image_content() {
360-
var news = $('.tab-content'), newsW, w, h;
360+
var news = $('.tab-content'),
361+
newsW, w, h;
361362
var newsInner = $('.tab-content > .tab-pane');
362363
if (news.length && newsInner.length) {
363364
var newsW = newsInner.width();

themes/default/modules/shops/block.search.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<div class="form-group">
1414
<label>{LANG.price2}</label>
15-
<input id="price2" type="text" value="{price2}" name="price2" class="form-control input-sm" onkeyup="this.value=FormatNumber(this.value);">
15+
<input id="price2" type="text" value="{value_price2}" name="price2" class="form-control input-sm" onkeyup="this.value=FormatNumber(this.value);">
1616
</div>
1717

1818
<div class="form-group">
@@ -39,4 +39,4 @@
3939
<input type="button" name="submit" id="submit" value="{LANG.search}" onclick="onsubmitsearch('{MODULE_NAME}')" class="btn btn-primary">
4040
</div>
4141
</form>
42-
<!-- END: main -->
42+
<!-- END: main -->

themes/default/modules/shops/search.tpl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@
2121
</select>
2222
</div>
2323
</div>
24+
<div class="form-group">
25+
<label class="col-sm-4 control-label">{LANG.price1}</label>
26+
<div class="col-sm-20">
27+
<input id="price1" type="text" value="{price1}" name="price1" class="form-control input-sm" onkeyup="this.value=FormatNumber(this.value);">
28+
</div>
29+
</div>
30+
31+
<div class="form-group">
32+
<label class="col-sm-4 control-label">{LANG.price2}</label>
33+
<div class="col-sm-20">
34+
<input id="price2" type="text" value="{price2}" name="price2" class="form-control input-sm" onkeyup="this.value=FormatNumber(this.value);">
35+
</div>
36+
</div>
37+
<div class="form-group">
38+
<label class="col-sm-4 control-label">{LANG.moneyunit}</label>
39+
<div class="col-sm-20">
40+
<select name="typemoney" id="typemoney" class="form-control input-sm">
41+
<option value="0">{LANG.moneyunit}</option>
42+
<!-- BEGIN: typemoney -->
43+
<option {ROW.selected} value="{ROW.code}">{ROW.currency}</option>
44+
<!-- END: typemoney -->
45+
</select>
46+
</div>
47+
</div>
2448
<div class="form-group">
2549
<label class="col-sm-4 control-label">{LANG.from_date}</span></label>
2650
<div class="col-sm-20">

0 commit comments

Comments
 (0)