![]() |
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? |
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:
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"> after Code:
{* $Id: products.tpl,v 1.72.2.3 2006/11/27 11:40:25 max Exp $ *} 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. |
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.
|
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.
|
Re: Let Customer choose number of products displayed on page
Will do, thanks and goodnight :-)
|
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 $ *} 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" |
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) { |
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! |
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.
|
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 :) |
Re: Let Customer choose number of products displayed on page
Quote:
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.) |
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?
|
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 |
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...
|
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.
|
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
|
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"> 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 |
Re: Let Customer choose number of products displayed on page
Yes, you right about this modification.
|
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.
|
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! :-):-):-) |
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.
|
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! |
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? |
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. |
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) { Seems like there are some kind of troubles with your database. |
Re: Let Customer choose number of products displayed on page
Quote:
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. |
Re: Let Customer choose number of products displayed on page
Quote:
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! |
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! |
Re: Let Customer choose number of products displayed on page
It's not working! Anyone have a better working code?
|
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! |
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 |
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:
|
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?
|
Re: Let Customer choose number of products displayed on page
Has any one tried this on 4.3.x?
|
Re: Let Customer choose number of products displayed on page
How can I get this to work in the manufacturers area as well?
|
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. |
Re: Let Customer choose number of products displayed on page
works for 4.2.1? thank you
|
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. |
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. |
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:
New file skin1/customer/change_ppp.tpl: PHP Code:
Add the following to home.php just below the auth.php line: PHP Code:
Add the following to the very end of skin1/customer/main/navigation.tpl: PHP Code:
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.