Index: openacs-4/packages/ecommerce/www/product-search.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/product-search.tcl,v diff -u -r1.6.4.2 -r1.6.4.3 --- openacs-4/packages/ecommerce/www/product-search.tcl 27 Jan 2005 11:20:10 -0000 1.6.4.2 +++ openacs-4/packages/ecommerce/www/product-search.tcl 22 Apr 2005 08:57:11 -0000 1.6.4.3 @@ -1,6 +1,11 @@ ad_page_contract { @param search_text @param combocategory_id:optional + @param category_id:optional + @param subcategory_id:optional + @param combocategory_id:optional + @param rows_per_page:optional How many products to display on the page + @param start_row:optional Where to begin from @param usca_p:optional This page searches for products either within a category (if specified) or @@ -11,12 +16,13 @@ @author ported by Jerry Asher (jerry@theashergroup.com) @author Bart Teeuwisse (bart.teeuwisse@thecodemill.biz) @revision-date April 2002 - } { search_text {combocategory_id ""} {category_id ""} {subcategory_id ""} + {rows_per_page:naturalnum {[ad_parameter -package_id [ec_id] ProductsToDisplayPerPage ecommerce]}} + {start_row:naturalnum "0"} usca_p:optional } @@ -49,7 +55,7 @@ # filter overflow attempts from really long search strings set search_text "[string range $search_text 0 100 ]" -ec_create_new_session_if_necessary [export_url_vars category_id search_text] cookies_are_not_required +ec_create_new_session_if_necessary [export_url_vars category_id subcategory_id subsubcategory_id rows_per_page start_row search_text] cookies_are_not_required if { [string compare $user_session_id "0"] != 0 } { db_dml insert_search_text_to_session_info "insert into ec_user_session_info (user_session_id, category_id, search_text) values (:user_session_id, :category_id, :search_text)" } @@ -92,8 +98,12 @@ set search_string "" set search_count 0 +set have_how_many_more_p "f" +set end_row_of_next_page [expr $start_row + (2 * $rows_per_page)] db_foreach get_product_listing_from_search $query_string { - incr search_count + + if { $search_count >= $start_row && [expr $search_count - $start_row] < $rows_per_page } { + append search_string " @@ -107,12 +117,44 @@
[ec_linked_thumbnail_if_it_exists $dirname "t" "t"]
" + set last_row_this_page [expr $search_count + 1] + } + incr search_count + if { $search_count > $end_row_of_next_page } { + # we know there are at least how_many more items to display next time + set have_how_many_more_p "t" + } } +if { $start_row >= $rows_per_page } { + set prev_link "Previous $rows_per_page" +} else { + set prev_link "" +} + +if { [string equal $have_how_many_more_p "t"] } { + set next_link "Next $rows_per_page" +} else { + set number_of_remaining_products [expr $search_count - $start_row - $rows_per_page] + if { $number_of_remaining_products > 0 } { + set next_link "Next $number_of_remaining_products" + } else { + set next_link "" + } +} + +if { [empty_string_p $next_link] || [empty_string_p $prev_link] } { + set separator "" +} else { + set separator " | " +} + if { $search_count == 0 } { set search_results "No products found." } else { - set search_results "

$search_count [ec_decode $search_count "1" "item found." "items found, most relevant first."]

$search_string" + set search_results "

$search_count [ec_decode $search_count "1" "item found." "items found, most relevant first."]

" + append search_results "

Showing items [expr $start_row + 1] to $last_row_this_page." + append search_results "${search_string}${prev_link}${separator}${next_link}" } set context_bar [template::adp_parse [acs_root_dir]/packages/[ad_conn package_key]/www/contextbar [list context_addition [list "[ec_system_name] search results"]]] set ec_system_owner [ec_system_owner]