Jump to content

Archived

This topic is now archived and is closed to further replies.

dfcdev

display number of items per page

Recommended Posts

I need to be able to be able to allow a user to display and "show a number of items per page" drop down menu for example:

 

Show: 10, 20, 30 and View ALL

 

it does not have to necessarily be 10, 20, 30 etc. it can be in increments of 5 (5, 10, 15 and so on) see the screenshot attached and let me know how I can add this module and/or modify any of the core files!

post-335687-0-15807600-1443378631_thumb.jpg

Share this post


Link to post
Share on other sites

@@dfcdev

 

Hi Michael

 

I don't know what version of osCommerce you are using so I will just show you the codes for both. One code is for the normal osC 2.3.4 and the other is only for osC 2.3.4 BS (Bootstrap)

One thing you should know is that the following requires you to amend core code which is not ideal but unfortunately sometimes still necessary like in this case. It is an older code that I used since osC 2.3.3.4 but it still works for the newer versions. If someone else has a newer, better code please come forth.

So let's start.

 

First add this new language definition to your english.php file. This is required for either version.

define('TEXT_ALL_ITEMS', 'All');

For normal osC 2.3.4

 

open catalog/includes/modules/product_listing.php

 

FIND:

$prod_list_contents = '<div class="ui-widget infoBoxContainer">' .

and ADD RIGHT ABOVE it this:

if (!tep_session_is_registered('max_products_per_page')) tep_session_register('max_products_per_page');
  if (!isset($max_products_per_page) || !is_integer($max_products_per_page) || ($max_products_per_page < 1)) $max_products_per_page = MAX_DISPLAY_SEARCH_RESULTS;
  if (isset($HTTP_GET_VARS['mppp']) && is_numeric($HTTP_GET_VARS['mppp']) && ($HTTP_GET_VARS['mppp'] > 0)) $max_products_per_page = intval($HTTP_GET_VARS['mppp']);
  $mppp_list = array();
  for ($i = 1; $i <= 5; $i += 1) { //change $i <= 5 to show more or less page options, default is 5 (Example: 12, 24, 36, 48, 60 (total: 5 options))
    $mppp = intval($i * 12); //change $i * 12 for products shown per page, default is 12
	$mppp_list[] = array('id' => $mppp, 'text' => $mppp);
	}
    $mppp_list[] = array('id' => 9999999, 'text' => TEXT_ALL_ITEMS);	
  $gvhf = '';
  $ignore = array('page', 'mppp');
  if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) {
    reset($HTTP_GET_VARS);
    while (list($key, $value) = each($HTTP_GET_VARS)) {
      if ( (strlen($value) > 0) && ($key != tep_session_name()) && (!in_array($key, $ignore)) ) {
        $gvhf .= tep_draw_hidden_field($key, $value);
      }
    }
  }
  $maxpppform = TEXT_SHOW . ' ' . tep_draw_form('prod_per_page', basename($PHP_SELF), 'get') . $gvhf . tep_draw_pull_down_menu('mppp', $mppp_list, $max_products_per_page, 'class="smallText" onchange="this.form.submit()"') . '</form>';
  $listing_split = new splitPageResults($listing_sql, $max_products_per_page, 'p.products_id');


	echo '<span style="float:right;margin-bottom:10px;">' . $maxpppform . '</span>';
	echo '<div style="clear:both;"></div>';

For osC 2.3.4 BS (Bootstrap version GOLD or EDGE)

 

open catalog/includes/modules/product_listing.php

 

FIND:

    <?php
    if (MODULE_HEADER_TAGS_GRID_LIST_VIEW_STATUS == 'True') {
      ?>

and ADD RIGHT ABOVE it this:

<?php
if (!tep_session_is_registered('max_products_per_page')) tep_session_register('max_products_per_page');
  if (!isset($max_products_per_page) || !is_integer($max_products_per_page) || ($max_products_per_page < 1)) $max_products_per_page = MAX_DISPLAY_SEARCH_RESULTS;
  if (isset($HTTP_GET_VARS['mppp']) && is_numeric($HTTP_GET_VARS['mppp']) && ($HTTP_GET_VARS['mppp'] > 0)) $max_products_per_page = intval($HTTP_GET_VARS['mppp']);
  $mppp_list = array();
  for ($i = 1; $i <= 5; $i += 1) { //change $i <= 5 to show more or less page options, default is 5 (Example: 12, 24, 36, 48, 60 (total: 5 options))
	$mppp = intval($i * 12); //change $i * 12 for products shown per page, default is 12
	$mppp_list[] = array('id' => $mppp, 'text' => $mppp);
	}
	$mppp_list[] = array('id' => 9999999, 'text' => TEXT_ALL_ITEMS);	
  $gvhf = '';
  $ignore = array('page', 'mppp');
  if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) {
	reset($HTTP_GET_VARS);
	while (list($key, $value) = each($HTTP_GET_VARS)) {
	  if ( (strlen($value) > 0) && ($key != tep_session_name()) && (!in_array($key, $ignore)) ) {
		$gvhf .= tep_draw_hidden_field($key, $value);
	  }
	}
  }
  $maxpppform = tep_draw_form('prod_per_page', basename($PHP_SELF), 'get') . $gvhf . tep_draw_pull_down_menu('mppp', $mppp_list, $max_products_per_page, 'class="form-control input-sm" style="width:70px;" onchange="this.form.submit()"') . '</form>';
 $listing_split = new splitPageResults($listing_sql, $max_products_per_page, 'p.products_id');
?>
 <form class="form-inline pull-right">
	<label class="control-label"><?php echo TEXT_SHOW; ?></label>
	<?php echo $maxpppform; ?>
 </form>

I think that's it. You might have to add that code to other files like products_new.php if you want to have the same feature there.

You also might have to adjust my above code to match your shop. The default setting is 5 steps in 12 products per page. (12, 24, 36, 48, 60)

 

Good luck!

Share this post


Link to post
Share on other sites

BRILLIANT! this worked like a charm! for the record I am using "normal osC 2.3.4" "Tsimi" you are a genious!

Share this post


Link to post
Share on other sites

This would be a good feature to include anywhere split_page_results.php is used: give the shopper a choice of how many items to display per page (fixed set of choices and/or user-entry), or at least, allow "View All on One Page". Maybe the last item count selected could be saved with the customer account, so they don't have to keep making the selection. Just be careful about trying to use a single count with items that vary greatly in screen real estate used (shoppers might find it annoying), and how this interacts with a grid display and responsive.

Share this post


Link to post
Share on other sites

Hi. Verry good Job. But I have a question, wher I need to insert this code for products_new.php while I can not find there this code "$prod_list_contents ="

Thank you

Share this post


Link to post
Share on other sites

@@Joahim2509

 

That is because you are using the "normal" osC 2.3.4 and there the products_new.php and specials.php don't use the product_listing.php file.

As you can see their page layout is also different and don't give you any sorting possibilities.

Burt did some work long, long time ago and converted those two files (products_new.php and specials.php) to utilize the product_listing.php file.

 

My question to you is, how far have you already modified your shop? If you are still at the beginning why not install osC BS (responsive Bootstrap version) instead?

There these changes have been applied already and it gives you lot more features then the stock osC version.

If you decide to have a look at it download the GOLD version or if you are well with coding then go for the EDGE version. Search the forum for EDGE or GOLD and you should find more info about it.

 

If you decide to continue on your current path with current version I could dig out those old files that burt created for the normal osC version.

Share this post


Link to post
Share on other sites

Thak you for your help. I know that I need a new post to create but maybe you can help me with this thing. I find an Add-on "Sepa Banktranfer" on osCommerce community. I made all steps that  have there described but I get some warnings and after that when user try to make an order in the field "Land der Bank:" or "Country of Bank:" the dropdown list is empty only text "Bitte wählen" or "Please Select" is shown. I can not find where is the error.

 

P.S. When I try to activate this plugin from admin area I get the error: 

Warning: mysql_list_fields() [function.mysql-list-fields]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /srv/disk12/1131496/www/sitename/includes/modules/payment/sepabanktransfer.php on line 450

Warning: mysql_list_fields() [function.mysql-list-fields]: A link to the server could not be established in /srv/disk12/1131496/www/sitename/modules/payment/sepabanktransfer.php on line 450

Warning: mysql_num_fields() expects parameter 1 to be resource, boolean given in /srv/disk12/1131496/www/sitename/includes/modules/payment/sepabanktransfer.php on line 451

Warning: Cannot modify header information - headers already sent by (output started at /srv/disk12/1131496/www/sitename/includes/modules/payment/sepabanktransfer.php:1) in /srv/disk12/1131496/www/opall.famelymoments.ro/admin/includes/functions/general.php on line 36

Share this post


Link to post
Share on other sites

@@Joahim2509

 

Sorry but I can't help you. That module seems to be very old and hasn't been updated for a while.

 

Es tut mir Leid aber ich kann dir da nicht weiter helfen. Das Modul ist alt und wurde lange nicht mehr aktualisiert.

Irgendwie das Modul keine Verbindung mit der Datenbank herstellen.

 

Hast du dieses Topic mal durchgelesen?

http://forums.oscommerce.de/topic/82321-sepa-banktransfer-f%C3%BCr-v22/?page=1

Share this post


Link to post
Share on other sites

@@dfcdev

 

Hi Michael

 

I don't know what version of osCommerce you are using so I will just show you the codes for both. One code is for the normal osC 2.3.4 and the other is only for osC 2.3.4 BS (Bootstrap)

One thing you should know is that the following requires you to amend core code which is not ideal but unfortunately sometimes still necessary like in this case. It is an older code that I used since osC 2.3.3.4 but it still works for the newer versions. If someone else has a newer, better code please come forth.

So let's start.

 

First add this new language definition to your english.php file. This is required for either version.

define('TEXT_ALL_ITEMS', 'All');

For normal osC 2.3.4

 

open catalog/includes/modules/product_listing.php

 

FIND:

$prod_list_contents = '<div class="ui-widget infoBoxContainer">' .

and ADD RIGHT ABOVE it this:

if (!tep_session_is_registered('max_products_per_page')) tep_session_register('max_products_per_page');
  if (!isset($max_products_per_page) || !is_integer($max_products_per_page) || ($max_products_per_page < 1)) $max_products_per_page = MAX_DISPLAY_SEARCH_RESULTS;
  if (isset($HTTP_GET_VARS['mppp']) && is_numeric($HTTP_GET_VARS['mppp']) && ($HTTP_GET_VARS['mppp'] > 0)) $max_products_per_page = intval($HTTP_GET_VARS['mppp']);
  $mppp_list = array();
  for ($i = 1; $i <= 5; $i += 1) { //change $i <= 5 to show more or less page options, default is 5 (Example: 12, 24, 36, 48, 60 (total: 5 options))
    $mppp = intval($i * 12); //change $i * 12 for products shown per page, default is 12
	$mppp_list[] = array('id' => $mppp, 'text' => $mppp);
	}
    $mppp_list[] = array('id' => 9999999, 'text' => TEXT_ALL_ITEMS);	
  $gvhf = '';
  $ignore = array('page', 'mppp');
  if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) {
    reset($HTTP_GET_VARS);
    while (list($key, $value) = each($HTTP_GET_VARS)) {
      if ( (strlen($value) > 0) && ($key != tep_session_name()) && (!in_array($key, $ignore)) ) {
        $gvhf .= tep_draw_hidden_field($key, $value);
      }
    }
  }
  $maxpppform = TEXT_SHOW . ' ' . tep_draw_form('prod_per_page', basename($PHP_SELF), 'get') . $gvhf . tep_draw_pull_down_menu('mppp', $mppp_list, $max_products_per_page, 'class="smallText" onchange="this.form.submit()"') . '</form>';
  $listing_split = new splitPageResults($listing_sql, $max_products_per_page, 'p.products_id');


	echo '<span style="float:right;margin-bottom:10px;">' . $maxpppform . '</span>';
	echo '<div style="clear:both;"></div>';

For osC 2.3.4 BS (Bootstrap version GOLD or EDGE)

 

open catalog/includes/modules/product_listing.php

 

FIND:

    <?php
    if (MODULE_HEADER_TAGS_GRID_LIST_VIEW_STATUS == 'True') {
      ?>

and ADD RIGHT ABOVE it this:

<?php
if (!tep_session_is_registered('max_products_per_page')) tep_session_register('max_products_per_page');
  if (!isset($max_products_per_page) || !is_integer($max_products_per_page) || ($max_products_per_page < 1)) $max_products_per_page = MAX_DISPLAY_SEARCH_RESULTS;
  if (isset($HTTP_GET_VARS['mppp']) && is_numeric($HTTP_GET_VARS['mppp']) && ($HTTP_GET_VARS['mppp'] > 0)) $max_products_per_page = intval($HTTP_GET_VARS['mppp']);
  $mppp_list = array();
  for ($i = 1; $i <= 5; $i += 1) { //change $i <= 5 to show more or less page options, default is 5 (Example: 12, 24, 36, 48, 60 (total: 5 options))
	$mppp = intval($i * 12); //change $i * 12 for products shown per page, default is 12
	$mppp_list[] = array('id' => $mppp, 'text' => $mppp);
	}
	$mppp_list[] = array('id' => 9999999, 'text' => TEXT_ALL_ITEMS);	
  $gvhf = '';
  $ignore = array('page', 'mppp');
  if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) {
	reset($HTTP_GET_VARS);
	while (list($key, $value) = each($HTTP_GET_VARS)) {
	  if ( (strlen($value) > 0) && ($key != tep_session_name()) && (!in_array($key, $ignore)) ) {
		$gvhf .= tep_draw_hidden_field($key, $value);
	  }
	}
  }
  $maxpppform = tep_draw_form('prod_per_page', basename($PHP_SELF), 'get') . $gvhf . tep_draw_pull_down_menu('mppp', $mppp_list, $max_products_per_page, 'class="form-control input-sm" style="width:70px;" onchange="this.form.submit()"') . '</form>';
 $listing_split = new splitPageResults($listing_sql, $max_products_per_page, 'p.products_id');
?>
 <form class="form-inline pull-right">
	<label class="control-label"><?php echo TEXT_SHOW; ?></label>
	<?php echo $maxpppform; ?>
 </form>

I think that's it. You might have to add that code to other files like products_new.php if you want to have the same feature there.

You also might have to adjust my above code to match your shop. The default setting is 5 steps in 12 products per page. (12, 24, 36, 48, 60)

 

Good luck!

Hallo. I want to ask, how can I sort products by date adedd after display number per page? Where is that in your code?

Share this post


Link to post
Share on other sites

×