X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Let Customer choose number of products displayed on page (https://forum.x-cart.com/showthread.php?t=38695)

wayfarer 03-29-2008 06:13 PM

Let Customer choose number of products displayed on page
 
I have had a long look through existing messages and haven't come across anyone who's done this before or asked about how to do it.

I was hoping to include a drop down menu, added to the 'Sort by' options across the top of a page of products, allowing the customer to select the number of products the page is showing. This is currently an admin setting.

How could I go about keeping the admin setting as the default, but allowing the user to choose to display a higher or lower number of products on the page, depending on the way they like to view products and the speed of their connection?

For example:

Products per page:
10
20
30
50
75
100
All

I guess the other consideration would be would how the option would work if the user is not logged in and how it would work for logged in users. For users not logged in, the preference lasts for the duration of the session. If they are logged in, perhaps that preference is retained... or maybe that would be too complicated...

Anyone with any ideas about what template changes to make to implement this?

Holub 03-30-2008 03:58 AM

Re: Let Customer choose number of products displayed on page
 
Yes, you can do it.

First of all you should create file in root dir called "change_ppp.php" with this code:

File "change_ppp.php":
Code:


<?php

if ( !defined('XCART_SESSION_START') && ($REQUEST_METHOD != "POST")) { header("Location: home.php");}

require_once "auth.php";

x_session_register("products_per_page");

if ($REQUEST_METHOD=="POST")
        if ($ppp) {
                $back = $_SERVER['HTTP_REFERER'];
                if (!$back)
                        $back = "/home.php";
                if ($ppp == "all")
                  $ppp = 32767;
          $products_per_page = $ppp;
          x_session_save("products_per_page");
          func_header_location($back);
        }

if ($products_per_page) {
        $config["Appearance"]["products_per_page"] = $products_per_page;
        $objects_per_page = $config["Appearance"]["products_per_page"];
}
$smarty -> assign("products_per_page",$config["Appearance"]["products_per_page"]);

?>


Next step:

include into "auth.php" before end of file (?>)

Code:

include "change_ppp.php";

Next step:

include into /skin1/customer/main/products.tpl

Code:

<form method="POST" action="/change_ppp.php" name="product_per_page_form">
Show products per page
<select name="ppp" onchange="javascript: document.product_per_page_form.submit();">
<option value="5" {if $products_per_page eq 5}selected{/if}>5</option>
<option value="10" {if $products_per_page eq 10}selected{/if}>10</option>
<option value="20" {if $products_per_page eq 20}selected{/if}>20</option>
<option value="30" {if $products_per_page eq 30}selected{/if}>30</option>
<option value="50" {if $products_per_page eq 50}selected{/if}>50</option>
<option value="75" {if $products_per_page eq 75}selected{/if}>75</option>
<option value="100" {if $products_per_page eq 100}selected{/if}>100</option>
<option value="all" {if $products_per_page eq 32767}selected{/if}>all</option>
</select>
</form>


after

Code:

{* $Id: products.tpl,v 1.72.2.3 2006/11/27 11:40:25 max Exp $ *}
{if $active_modules.Feature_Comparison ne '' && $products && $printable ne 'Y' && $products_has_fclasses}
{include file="modules/Feature_Comparison/compare_selected_button.tpl"}
{include file="modules/Feature_Comparison/products_check_js.tpl"}
{/if}


This modification allows customer to select products per page and selected value will stored in session variable.

You can change this code as you want. I've checked this code and sure he works correctly.

wayfarer 03-30-2008 04:05 AM

Re: Let Customer choose number of products displayed on page
 
Many thanks for the prompt reply Holub!... It's 1am here and I'm probably better to implement with a clear mind on a good night's sleep - looking forward to trying it first thing in the morning... thanks again.

Holub 03-30-2008 04:08 AM

Re: Let Customer choose number of products displayed on page
 
If you have any questions or problems then feel free to ask any questions or information. I'm glad to help you.

wayfarer 03-30-2008 04:11 AM

Re: Let Customer choose number of products displayed on page
 
Will do, thanks and goodnight :-)

wayfarer 03-30-2008 01:46 PM

Re: Let Customer choose number of products displayed on page
 
It's a beautiful thing... :-) Many thanks Holub.

I ended up placing it in /main/search_sort_by.tpl as I just wanted it to apply alongside the other sort by features, rather than having it on the featured products on the home page as well. I applied a little bit of styling and it's perfect.

For anyone else wanting to do the same, here's my /main/search_sort_by.tpl:

Code:

{* $Id: search_sort_by.tpl,v 1.5.2.2 2007/03/01 10:42:12 max Exp $ *}
{if $url eq '' && $navigation_script ne ''}{assign var="url" value=$navigation_script|replace:"&":"&amp;"|cat:"&amp;"}{elseif $url ne ''}{assign var="url" value=$url|amp}{/if}
<table cellspacing="0" cellpadding="0">
<tr>
        <td class="SearchSortTitle">{$lng.lbl_sort_by}:</td>
{foreach from=$sort_fields key=name item=field}
{if $navigation_page > 1}
{assign var="cur_url" value=$url|cat:"page="|cat:$navigation_page|cat:"&amp;sort="|cat:$name|cat:"&amp;sort_direction="}
{else}
{assign var="cur_url" value=$url|cat:"sort="|cat:$name|cat:"&amp;sort_direction="}
{/if}
        {if $name eq $selected}
        <td><a class="SearchSortLink" href="{$cur_url}{if $direction eq 1}0{else}1{/if}" title="{$lng.lbl_sort_by|escape}: {$field}"><img src="{$ImagesDir}/{if $direction}darrow.gif{else}uarrow.gif{/if}" class="SearchSortImg" alt="{$lng.lbl_sort_direction|escape}" /></a></td>
        {/if}
        <td class="SearchSortCell"><a class="SearchSortLink" href="{$cur_url}{if $name eq $selected}{if $direction eq 1}0{else}1{/if}{else}{$direction}{/if}" title="{$lng.lbl_sort_by|escape}: {$field}">{if $name eq $selected}<b>{/if}{$field}{if $name eq $selected}</b>{/if}</a></td>
{/foreach}
<td>:&nbsp;&nbsp;&nbsp;&nbsp;</td><td class="DropDownTitle"><form method="POST" action="/myshopdirectory/change_ppp.php" name="product_per_page_form">
<b>Show:</b>
<select class="ShowDropDown" name="ppp" onchange="javascript: document.product_per_page_form.submit();">
<option value="10" {if $products_per_page eq 10}selected{/if}>10</option>
<option value="20" {if $products_per_page eq 20}selected{/if}>20</option>
<option value="30" {if $products_per_page eq 30}selected{/if}>30</option>
<option value="50" {if $products_per_page eq 50}selected{/if}>50</option>
<option value="75" {if $products_per_page eq 75}selected{/if}>75</option>
<option value="100" {if $products_per_page eq 100}selected{/if}>100</option>
<option value="all" {if $products_per_page eq 32767}selected{/if}>ALL</option>
</select>
</form></td></tr>
</table>


Oh and for others wanting to implement Holub's solution here, you may have to resolve the path that points to change_ppp.php if your shop is in a subdirectory of your main domain name, as I did...

For Example: action="/yourshopdirectory/change_ppp.php"

Jon 03-30-2008 09:32 PM

Re: Let Customer choose number of products displayed on page
 
To err on the side of caution in preventing sql injection, I would modify change_ppp.php and:

FIND:
Code:

if ($ppp) {

CHANGE TO:
Code:

if ((int)$ppp > 0) {

FIND:
Code:

if ((int)$products_per_page > 0) {

Holub 03-31-2008 12:56 AM

Re: Let Customer choose number of products displayed on page
 
In version 4.1.9 (as minimum) the auth.php file included in change_ppp.php will protect any POST variables from sql injection. However, God helps those who help themselves :)

Use for pleasure!

wayfarer 03-31-2008 01:26 AM

Re: Let Customer choose number of products displayed on page
 
Thanks to you both - I've implemented Jon's suggestion anyway and done some reading up on SQL injection.

Jon 03-31-2008 07:42 AM

Re: Let Customer choose number of products displayed on page
 
EDIT: $products_per_page however could possibly be specified from an external post.

I didn't go through the x-cart code to see if the query checks this variable prior to use or assumes it is safe because it usually comes from the config, but I figure better safe than sorry :)

wayfarer 03-31-2008 02:39 PM

Re: Let Customer choose number of products displayed on page
 
Quote:

Originally Posted by Jon
$products_per_page however could be specified from the url string with registered globals enabled. i.e. change_ppp.php?products_per_page=X


Right, Jon, you've lost me now...

(By the way, after I implemented your suggestions, I noticed that if I clicked on the ALL option, I simply received a blank page in my browser (change_ppp.php). Clicking on the other options worked fine.)

Viejo 03-31-2008 03:07 PM

Re: Let Customer choose number of products displayed on page
 
Pretty slick! I've been thinking about adding "Products Per Page" to the category modify template so the cart can be configured at the category level for page length. Don't suppose anybody's already done that?

Jon 03-31-2008 08:09 PM

Re: Let Customer choose number of products displayed on page
 
I don't want to hijack this thread as it's a good mod... and not my mod... but I've had to assist several store owners who have had the misfortune of having their sites hacked due to varying exploits, so please excuse my paranoia and hesitation to rely on x-cart's data sanitizing :)

Here's the code I would use in change_ppp.php:

Code:

<?php
if ( !defined('XCART_SESSION_START') && ($_SERVER['REQUEST_METHOD'] != "POST")) { header("Location: home.php");}
require_once "auth.php";
x_session_register("products_per_page");
if ($_SERVER['REQUEST_METHOD'] == "POST") {
 if ($ppp) {
  $back = $_SERVER['HTTP_REFERER'];
  if (!$back)
  $back = "/home.php";
  if ($ppp == "all") {
  $ppp = 32767;
  } else {
  $products_per_page = (int)$ppp;
  }
  x_session_save("products_per_page");
  func_header_location($back);
 }
}
if ((int)$products_per_page > 0) {
 $config["Appearance"]["products_per_page"] = $products_per_page;
 $objects_per_page = $config["Appearance"]["products_per_page"];
}
$smarty -> assign("products_per_page",$config["Appearance"]["products_per_page"]);
?>


wayfarer 03-31-2008 08:32 PM

Re: Let Customer choose number of products displayed on page
 
I appreciate that thanks Jon that code seems to work fine, including the show ALL...

Holub 04-01-2008 01:05 AM

Re: Let Customer choose number of products displayed on page
 
Thank you, Jon, for this corrections. Of course, somebody could read this thread and use opened code to find a security hole. Anyway thanks Jon.

masculinefires 04-22-2008 04:35 AM

Re: Let Customer choose number of products displayed on page
 
Has anyone encountered problems with this working in HTML Catalog mode? Can't seem to make it work there, only in dynamic mode

pdubya1632 06-09-2008 07:28 PM

Re: Let Customer choose number of products displayed on page
 
Excellent post and exactly something I needed...except for one thing -> the onchange in the form provided in post #2 gave this error: "document.product_per_page_form has no properties"

So instead of
onchange="javascript: document.product_per_page_form.submit();"
I used
onchange="this.form.submit()"
which fixes the problem

I then stripped out the unnecessary name attribute in the form tag and the all option (since that would have been overkill for me), and added an id so I could apply styles:

Code:

<form method="POST" action="/change_ppp.php" id="pppForm">
    Show products per page
    <select name="ppp" onchange="this.form.submit()">
    <option value="12" {if $products_per_page eq 10}selected{/if}>12</option>
    <option value="20" {if $products_per_page eq 20}selected{/if}>20</option>
    <option value="30" {if $products_per_page eq 30}selected{/if}>30</option>
    <option value="50" {if $products_per_page eq 50}selected{/if}>50</option>
    <option value="75" {if $products_per_page eq 75}selected{/if}>75</option>
    <option value="100" {if $products_per_page eq 100}selected{/if}>100</option>
    </select>
</form>


I successfully tested it in PC Firefox & IE7, Mac Firefox & Safari. You can see it in action here: http://www.shopbettylin.com/home.php?cat=249

Holub 06-10-2008 12:12 AM

Re: Let Customer choose number of products displayed on page
 
Yes, you right about this modification.

Thedae2k 06-12-2008 03:38 PM

Re: Let Customer choose number of products displayed on page
 
Works great...thanks for the great contribution Antony and I appreciate the concern for security Jon.

Jerrad 11-12-2008 03:39 PM

Re: Let Customer choose number of products displayed on page
 
Very useful mod, but I guess it's only for 4.1.x and not for 4.0.x?
Because changing the number of products brings me straight away to home.php...

Anybody a idea what to change so it will also work with 4.0.x?
I really could use this mod in our store...

Thanks! :-):-):-)

Holub 11-13-2008 12:23 AM

Re: Let Customer choose number of products displayed on page
 
There are such many changes was done with X-Cart after 4.0.12 that I even can't imagine. I have not this version so I even can't try to install mod. So please excuse me but I can't help you.

Jerrad 11-13-2008 02:10 AM

Re: Let Customer choose number of products displayed on page
 
Thanks for your reply, Holub.
It's a pity, because I really would like to use this mod.

Nobody with version 4.0.x who has got this mod working?

Thanks again!

xcel 12-10-2008 02:54 PM

Re: Let Customer choose number of products displayed on page
 
=D>

works great in 4.1.9

however, it made my

http://forum.x-cart.com/showthread.php?t=20040&highlight=slideshow(conveyor belt slideshow)

go away after implementing.

neither of the codes for this mod or the slideshow mod are in the same place.

any idea as to what may cause this?

xcel 01-15-2009 09:11 AM

Re: Let Customer choose number of products displayed on page
 
1 Attachment(s)
hey guys... how goes it.

i am having issues with this mod. when i choose any of the options for number of items per page, i receive the following error in the attachment.

any idea as to what would cause this? from what i remember, the mod worked fine from the initial install. but now i can't get anything to work besides the default 10 items per page.

i'd love to keep this mod active as i feel it's a great option to provide our customers.

thanks in advance.

EDIT: now it just got even stranger... the error only seems to be happening with 1 of our catagories. this catagory only has 66 items in it. our other catagory which has no issues thus far has 37.

Holub 01-16-2009 12:17 AM

Re: Let Customer choose number of products displayed on page
 
There is one place in X-Cart where this error can appeared - func.db.php

Code:

        foreach ($tbl as $t) {
                if (isset($sql_tbl[$t]))
                        $t = $sql_tbl[$t];

                if (!isset($storage[$t])) {
                        $storage[$t] = func_query_column("SHOW FIELDS FROM ".$t);
                        if (empty($storage[$t]))
                                func_header_location("error_message.php?access_denied&id=78");
                }


Seems like there are some kind of troubles with your database.

xcel 01-16-2009 12:42 PM

Re: Let Customer choose number of products displayed on page
 
Quote:

Originally Posted by Holub
Seems like there are some kind of troubles with your database.


no matter how many times i read that... it never sounds like a good thing. i guess i'll have to track down that php page and see what's going on. if all else fails, i guess i can simply remove the code for this mod.

thanks for the input holub.

clik 04-23-2009 07:29 AM

Re: Let Customer choose number of products displayed on page
 
Quote:

Originally Posted by Jon
I don't want to hijack this thread as it's a good mod... and not my mod... but I've had to assist several store owners who have had the misfortune of having their sites hacked due to varying exploits, so please excuse my paranoia and hesitation to rely on x-cart's data sanitizing :)

Here's the code I would use in change_ppp.php:

Code:

<?php
if ( !defined('XCART_SESSION_START') && ($_SERVER['REQUEST_METHOD'] != "POST")) { header("Location: home.php");}
require_once "auth.php";
x_session_register("products_per_page");
if ($_SERVER['REQUEST_METHOD'] == "POST") {
 if ($ppp) {
  $back = $_SERVER['HTTP_REFERER'];
  if (!$back)
  $back = "/home.php";
  if ($ppp == "all") {
  $ppp = 32767;
  } else {
  $products_per_page = (int)$ppp;
  }
  x_session_save("products_per_page");
  func_header_location($back);
 }
}
if ((int)$products_per_page > 0) {
 $config["Appearance"]["products_per_page"] = $products_per_page;
 $objects_per_page = $config["Appearance"]["products_per_page"];
}
$smarty -> assign("products_per_page",$config["Appearance"]["products_per_page"]);
?>



Thanks guys for this very handy mod :D/
It works in x-cart 4.2 as well but I have a little problem with <option value="all">. It wouldn't make it "selected". It keeps the previous selected value (5/10/20... etc).

Any idea where the problem could be?

I used the code above for the change_ppp.php file.

Thank you!

royng 07-03-2009 03:07 PM

Re: Let Customer choose number of products displayed on page
 
I am a newbie. And I am using 4.1.11. Where is the file "auth.php" located? I looked all over, I only see auth.tpl, is that the same? Second, where so I upload the file change_ppp.php? same location at auth.tpl?

And I can't found
{* $Id: products.tpl,v 1.72.2.3 2006/11/27 11:40:25 max Exp $ *}
{if $active_modules.Feature_Comparison ne '' && $products && $printable ne 'Y' && $products_has_fclasses}
{include file="modules/Feature_Comparison/compare_selected_button.tpl"}
{include file="modules/Feature_Comparison/products_check_js.tpl"}

{/if}
skin1/customer/main/products.tpl

Am i missing anything? or Am I looking at different verison?

I am not a programmer.
Please help, Thanks!

royng 07-07-2009 11:50 AM

Re: Let Customer choose number of products displayed on page
 
It's not working! Anyone have a better working code?

royng 07-09-2009 03:41 PM

Re: Let Customer choose number of products displayed on page
 
I have the same problem too, the "All" can not be select.

Maybe this is the way how is it go.

we just have to live with it!

royng 07-09-2009 03:55 PM

Re: Let Customer choose number of products displayed on page
 
I got it. it's simple!

Just use
<form method="POST" action="/store/change_ppp.php" id="pppForm">
Show products per page
<select name="ppp" onchange="this.form.submit()">
<option value="9" {if $products_per_page eq 9}selected{/if}>9</option>
<option value="12" {if $products_per_page eq 12}selected{/if}>12</option>
<option value="15" {if $products_per_page eq 15}selected{/if}>15</option>
<option value="18" {if $products_per_page eq 18}selected{/if}>18</option>
<option value="21" {if $products_per_page eq 21}selected{/if}>21</option>
<option value="24" {if $products_per_page eq 24}selected{/if}>24</option>
<option value="99" {if $products_per_page eq 99}selected{/if}>all</option>
</select>

</form>

in products.tpl

presson83 11-10-2009 10:02 AM

Re: Let Customer choose number of products displayed on page
 
Hi All,

This is a great mod and came in super handy. I modified it slightly to have a "view all" button outside of the drop-down menu. When you click it it will show the "all" option in the drop-down (for clarity's sake), otherwise it's not there. Here's the code and thanks Holub!

HTML Code:


<form method="POST" action="change_ppp.php" class="productsPerPage">
        Show products per page
        <select name="ppp" onchange="javascript: this.form.submit();">
        <option value="5" {if $products_per_page eq 5}selected{/if}>5</option>
        <option value="10" {if $products_per_page eq 10}selected{/if}>10</option>
        <option value="20" {if $products_per_page eq 20}selected{/if}>20</option>
        <option value="30" {if $products_per_page eq 30}selected{/if}>30</option>
        <option value="50" {if $products_per_page eq 50}selected{/if}>50</option>
        {if $products_per_page eq 100}<option value="100" {if $products_per_page eq 100}selected{/if}>all</option>{/if}
        </select>
    </form>
   
    <form method="POST" action="change_ppp.php" class="viewAll">
        <input type="hidden" name="ppp" value="100" />
        <input type="submit" value="view all" onclick="javascript: this.form.submit();"/>
    </form>


kidroush 01-05-2010 11:32 AM

Re: Let Customer choose number of products displayed on page
 
I have this search sort by feature on my site. However, the options to sort by are Product, Price or Default. This is fine but I want to change the word product to movies even though I want it to sort by the product still. The only thing I want to change is the label, not the function. Anyone know how?

Pyro 03-28-2010 11:51 AM

Re: Let Customer choose number of products displayed on page
 
Has any one tried this on 4.3.x?

mrerotic 04-06-2010 11:51 PM

Re: Let Customer choose number of products displayed on page
 
How can I get this to work in the manufacturers area as well?

FTI 04-28-2010 02:42 AM

Re: Let Customer choose number of products displayed on page
 
Hello Sir,
Looking through the X-cart forum I came across this topic.

I need the same thing but for manufacturers. I need a drop down menu with the manufacturers, that stands next to the search box on my website. So when the user chooses to search "mascara" for example, he can search only for mascara, maunfactured by Lancome. I badly need some help, and I will appreciate it.

Thanks in advance.

Christofer 05-02-2010 03:26 PM

Re: Let Customer choose number of products displayed on page
 
works for 4.2.1? thank you

jlrentertainment 06-07-2010 12:31 PM

Re: Let Customer choose number of products displayed on page
 
I have something similar but not in dropdown format over here:

http://forum.x-cart.com/showthread.php?t=23796&page=6

It's working on 4.3.2.

minfinger 06-13-2010 06:46 AM

Re: Let Customer choose number of products displayed on page
 
I would love this option in 4.3.x

I did see the thread you posted above and Show All won't really work for my customer.

cherie 08-18-2012 05:16 PM

Re: Let Customer choose number of products displayed on page
 
I've completed this for 4.3. I couldn't find this mentioned elsewhere so hopefully this isn't redundant.

New file change_ppp.php:

PHP Code:

<?php
if (!defined('XCART_SESSION_START') && $_SERVER['REQUEST_METHOD'] != 'POST') {
    
header('Location: home.php');
    die(
'Access denied');
}

require 
'./auth.php';
x_session_register('products_per_page');

if (
$_SERVER['REQUEST_METHOD'] == 'POST' && $ppp) {

    
$back $_SERVER['HTTP_REFERER'];
    if (!
$back)
        
$back '/home.php';

    if (
$ppp == 'all')
        
$ppp 32767;

    
$products_per_page = (int)$ppp;
    
x_session_save('products_per_page');

    
func_header_location($back);
}

if ((int)
$products_per_page 0)
    
$objects_per_page $config['Appearance']['products_per_page'] = $products_per_page;

$smarty->assign('products_per_page'$config['Appearance']['products_per_page']);

$pppList = array(
    
6,12,24,48,72,120,32767
);
$smarty->assign('pppList'$pppList)
?>


New file skin1/customer/change_ppp.tpl:

PHP Code:

<form method="post" action="{$xcart_web_dir}/change_ppp.php" style="float:right">
    
Show products per page
    
<select name="ppp" onchange="this.form.submit()">
        {foreach 
from=$pppList item=pli name=pli}
            <
option value="{if $smarty.foreach.pli.last}all{else}{$pli}{/if}"{if $products_per_page eq $pliselected{/if}>{if $smarty.foreach.pli.last}all{else}{$pli}{/if}</option>
        {/foreach}
    </
select>
</
form>
<
div class="clearing"></div


Add the following to home.php just below the auth.php line:

PHP Code:

if (!empty($cat))
    include 
$xcart_dir.'/change_ppp.php'


Add the following to the very end of skin1/customer/main/navigation.tpl:

PHP Code:

{include file="customer/change_ppp.tpl"


Add the following to .nav-pages in skin1/main.css:

Code:

  float: left;


All times are GMT -8. The time now is 08:08 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.