Ecommerce software home
Shopping Cart Software Forum for Ecommerce Templates
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?



Find us on Facebook

Follow us on Twitter

View our YouTube channel


 All Forums
 Technical
 Advanced Tips and Tricks - NO QUESTIONS PLEASE
 Force a resort when using product filters
 New Topic  Reply to Topic
 Printer Friendly
Author  Topic   

dbdave
ECT Moderator

USA
8205 Posts

Posted - 09/27/2017 :  08:04:39  
:::EDITED 8/18/2018::: Now tested to work with .php - check down in the thread for latest post and new notes.

This has been tested with .asp but not .php
Although it should work for both.

Some users like to create a page where new products are automatically shown.
This can be done by creating a static page and inserting the orsortby parameter just before the include line that calls up your products.
New products automatically show up on this page and they are automatically shown in the order of newest first, regardless of the sort setting you have established in your admin.
It's good for your customers and good "spider" food for the search engines.

Basically in the content area of your page (.asp version example here) you would have this.
<%orsortby=9%>
<!--#include file="vsadmin/inc/incproducts.asp"-->

It works really well.
That is until you decide to use the product filters.
Namely the sort filter where customers can resort the products to any order that you have allowed in your admin main setting where the filter is setup.
Then the <%orsortby=9%>is ignored and the page is sorted by whatever your customer has changed that filter to.

Have no fear, Javascript (and jquery) are here to fix that for you.



<!-- Begin Re-sort -->
<script type="text/javascript">
var sortvalue = $("div.ectpfsort select.prodfilter").val();
if (sortvalue != "9") {
jQuery(document).ready(function($){
$('div.ectpfsort select.prodfilter').val(9).change();
});
}
</script>
<!-- End Re-sort -->


This above code, needs to be added to the bottom of the static page you created just before the closing </body> tag.
WARNING - If you do not place this at the bottom of the page, and you put it at the top, the page will get caught in an endless refresh loop because the "sort" has not been established until the page loads.

You do need to be calling jquery on the page. Check the top of your page because you may already have some jquery on your site and if you are already loading the jquery library, then you do not want it twice. That can cause issues.
If you are not, just add the line below in the <head> </head> section of the page.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

Happy Selling.


David
ECT Power User

Edited by - dbdave on 08/18/2018 11:20:42

dbdave
ECT Moderator

USA
8205 Posts

Posted - 09/27/2017 :  08:14:17  
If for some reason you have a static page that you need forced to another sort, you can change the "9" there.
Below is a list is sort value numbers.
But you only need to do this if you are using the "sort" product filter, and only on a static page.
You wouldn't want to use it on your products.asp/.php page.

Basically the code says "if it isn't sorted by "9" then resort it by "9" "


<!-- Begin Re-sort -->
<script type="text/javascript">
var sortvalue = $("div.ectpfsort select.prodfilter").val();
if (sortvalue != "9") {
jQuery(document).ready(function($){
$('div.ectpfsort select.prodfilter').val(9).change();
});
}
</script>
<!-- End Re-sort -->




quote:

Note
The sortBy parameters were moved to the admin main settings page in Version 6 but if you still need to set the product listing through the includes file you can use the orsortby parameter. This is handy if you want to use them on static pages with a different listing. So if you want to sort the product listing alphabetically use orsortby=1 Please note this setting also overrides the listing choices in the new product filter bar.

1 = sorting the products alphabetically
2 = sorting the products by id
3 = sorting the products by price (cheapest first)
4 = sorting the products by price (most expensive first)

So for example if you wanted to list your products alphabetically you would choose this option:
orsortby = 1 or by product id like this orsortby = 2

orsortby=5
This will sort the products by the order the products are within the database. This is particularly useful where the sort order is not important and will result in the fastest way of displaying products.

orsortby=6
This will sort the products in ascending order depending on the value added to the "Product Order" box in the product admin page.

orsortby=7
This will sort the products in descending order depending on the value added to the "Product Order" box in the product admin page.

orsortby=8
This will sort the products in ascending order depending on the date added.

orsortby=9
This will sort the products in descending order depending on the date added.

orsortby=13
This will sort the products randomly (Version 6.6 required).

orsortby=14
This will sort the products in ascending order depending on the sku (Version 6.7 required)

orsortby=15
This will sort the products in descending order depending on the sku (Version 6.7 required)




David
ECT Power User

Edited by - dbdave on 09/27/2017 08:17:03

Paradise
Ecommerce Template Guru

USA
1598 Posts

Posted - 09/27/2017 :  09:29:01  
Should it be Force a Reset/Refresh? :)

Responsive Design Deals Ecomm Plus - ASP 6.8
www.paradiseclothingco.com

Edited by - Paradise on 09/27/2017 09:29:29

dbdave
ECT Moderator

USA
8205 Posts

Posted - 09/27/2017 :  10:05:05  
I can see that, but the function there is to resort back the way you want when the customer has defined their sort choice.
That does call for the page to be refreshed, but that's done by the ect code because when you change the product filters, that causes the refresh.

So my code there never (directly) causes a page refresh, it just causes the same action as the user changing the the filter. ECT code takes over from there.

The "change" in this line
$('div.ectpfsort select.prodfilter').val(9).change();

Is saying "do whatever happens when a human changes the value manually.
Without that little gem, the line changes on the screen, but no action occurs.

It's the same as the ship station change I shared with you Mike.
The timestamp was not getting updated because a human was not actually clicking the button.
Sometimes when you click a button, several things happen.

David
ECT Power User

Edited by - dbdave on 09/27/2017 10:05:50

dbdave
ECT Moderator

USA
8205 Posts

Posted - 04/29/2018 :  16:49:31  
Confirmed, works on .php
https://www.ecommercetemplates.com/support/topic.asp?TOPIC_ID=109855

Positivek9
Ecommerce Template Guru

USA
4051 Posts

Posted - 06/11/2018 :  09:42:49  
Thanks for this little gem David!

I'm using it on my home page for the recommended products (cool site in profile). For some reason, it was ignoring the random order as set in the crosssell & displaying them in A-Z as set in the Main Settings Sort Order. Now they show randomly...or at least when I test I see different items instead of the same 4. :)

Julie
Owned & loved by 7 German Shepherds

dbdave
ECT Moderator

USA
8205 Posts

Posted - 06/11/2018 :  10:48:12  
Glad it works for you Julie.

dbdave
ECT Moderator

USA
8205 Posts

Posted - 08/16/2018 :  21:06:11  
:::EDIT::: I thought this was not working on my dev site after testing version 6.9.4, but I was wrong, I just didn't have the filters active due to other testing. It works just fine.

Edited by - dbdave on 08/18/2018 10:01:26

Positivek9
Ecommerce Template Guru

USA
4051 Posts

Posted - 08/16/2018 :  21:11:58  
No worries David. We figured out what was wrong, but your tip helped in a pinch there.
Keep up the good work! :)

Julie
Owned & loved by 7 German Shepherds

dbdave
ECT Moderator

USA
8205 Posts

Posted - 08/18/2018 :  10:10:54  
This has been tested on the .php version and I have a demo setup.
One thing, the dates my test site for .php are set to a different format. If you have your date added to products set like 2018-07-01 rather than 07-01-2018 then you need the sort set by 8 instead of 9.

So if your dates are like this 07-01-2018 then you want the following code
(code must be placed at the bottom of the page)
<!-- Begin Re-sort -->
<script type="text/javascript">
var sortvalue = $("div.ectpfsort select.prodfilter").val();
if (sortvalue != "9") {
jQuery(document).ready(function($){
$('div.ectpfsort select.prodfilter').val(9).change();
});
}
</script>
<!-- End Re-sort -->


If your dates are set like so 2018-07-01, then you want the following code
(code must be placed at the bottom of the page)
<!-- Begin Re-sort -->
<script type="text/javascript">
var sortvalue = $("div.ectpfsort select.prodfilter").val();
if (sortvalue != "8") {
jQuery(document).ready(function($){
$('div.ectpfsort select.prodfilter').val(8).change();
});
}
</script>
<!-- End Re-sort -->


Note, this requires the top filter bar being active and having the sort by set where the customer can change it, and date asc and desc being active.
If you use the side filter, and do not want to use the top filter, you still need the top filter active, you can just hide it with some css.

Lastly, remember to be sure you have jquery on the page. If not, just add this to the head of the page - <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

Here is the .php demo (first we load a page showing all products and sort them by popularity) www.floridasurpluswarehouse.com/dev/products.php?sortby=19
then you go to the latest product (link there in the bottom of the page, or use this link - http://www.floridasurpluswarehouse.com/dev/latest-products.php
You can see the sort has changed there.

Edited by - dbdave on 08/18/2018 10:13:51
   Topic   
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Shopping Cart Software Forum for Ecommerce Templates © 2002-2019 ecommercetemplates.com
This page was generated in 0.03 seconds. Snitz Forums 2000