X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Listing newest added product first (https://forum.x-cart.com/showthread.php?t=18788)

B00MER 12-21-2005 02:41 AM

Listing newest added product first
 
Add the ability to sort by add_date field along with listing default by this field. Edit include/search.php and locate the following code:

Code:

$sort_fields = array(
        "productcode"        => func_get_langvar_by_name("lbl_sku"),
        "title"                => func_get_langvar_by_name("lbl_product"),
    "price"                => func_get_langvar_by_name("lbl_price"),
        "orderby"                => func_get_langvar_by_name("lbl_default")
);


Change to:
Code:

$sort_fields = array(
        "add_date"                => func_get_langvar_by_name("lbl_date"),
        "productcode"        => func_get_langvar_by_name("lbl_sku"),
        "title"                => func_get_langvar_by_name("lbl_product"),
    "price"                => func_get_langvar_by_name("lbl_price"),
        "orderby"                => func_get_langvar_by_name("lbl_default")
);


Next locate:
Code:

#
# Perform search and display results
#
        $data = array();


After this above code add:

Code:

if(empty($sort)) $sort = "add_date";

Next locate:
Code:

                        case "productcode":
                                $sort_string = "$sql_tbl[products].productcode $direction";
                                break;


Above this line add:

Code:

                                case "add_date":
                                $sort_string = "$sql_tbl[products].add_date DESC";
                                break;


Thats it! Now all of your product listings by default will show newest products first. As well as Date field has been added to the sort options list under "Date".

:!: Keep in mind, X-Cart admin->General Settings->Apperance: "Select the order in which products should be displayed within a category:" will be ignored with this mod in place.

Impact_1 12-22-2005 07:07 AM

Thats a nice touch Boomer, thanks :)

Amy 12-25-2005 04:46 PM

thanks! bookmarked for review later! I have a few other mods to add on that I purchased but this looks great ;)

JWait 12-27-2005 03:13 AM

This is what I have been looking for. It puts the newest products first in the listings! Thanks! :D

anandat 12-27-2005 06:02 AM

This is nice little useful mode...thanks boomer :D

electronics4less 12-28-2005 09:45 AM

Thanks for the free mod B00MER,

Can this mod be editted so products can be sorted by Manufacturers?

B00MER 12-28-2005 11:28 AM

Quote:

Originally Posted by electronics4less
Can this mod be editted so products can be sorted by Manufacturers?

Since only mfr. id is stored in products table you may need to subselect or require more custom code for such. Unless you want to sort by the manufacturerid itself, instead of the name :)

Amy 01-23-2006 09:30 AM

one thing we have seen that has been a bit of a nuisance.... when products are updated via CVS and imported they noted as "new" when they really are not new.

Amy 03-17-2006 07:29 PM

Hmmmm - could I have some help - tried this tonight and works great "almost"!

My date doesn't change from ASC to DESC

http://scrapbookbytes.com/store/manufacturers.php?manufacturerid=22

youngvet1 03-17-2006 08:24 PM

What changes should be made if you dont want it sorted by default using newest date but you just want it as an option so if they click it it will sort and put newest first. Another wards i want to keep the default to sort alphabetical.

fractalspin 03-22-2006 04:40 PM

Quote:

Originally Posted by Amy


same here: http://www.fractalspin.com/x/home.php?cat=7

any thoughts?

bestdata 03-30-2006 02:45 PM

sort by pirce desc
 
any idea to get it to sort be price from high to low price

Thanks

shan 03-31-2006 04:20 AM

try change

DESC

for

$direction

fractalspin 03-31-2006 08:44 AM

It's still not working--yes, when you click it once you can get it to sort with the newest first, but it doesn't sort like the other ones do. I think there is a problem with the code. It doesn't sort ASC or DESC.

bestdata 03-31-2006 03:59 PM

sort by price
 
thanks shan
I tried it but did not work.
How about takaing out the mod and having to show products sorted first by price form highest to lowest price.

Any advise will be appreciated.

thanks

lachild 08-03-2006 08:04 AM

Works Perfectly in 4.1.2
 
Thanks for the mod I did have to change one line to get the sort by working correctly.

As noted by Shan in an earlier post I changed the following line:

Code:

            case "add_date":
            $sort_string = "$sql_tbl[products].add_date DESC";
            break;


to this
Code:

            case "add_date":
            $sort_string = "$sql_tbl[products].add_date $direction";
            break;


Works great! Thanks again

Update:

Mod did not by default change to dispay by date. I found that I had to update the products_order feild in the Config table within the datebase.

Use the following SQL command to get the new Date module as an option in the admin section.

Code:

UPDATE `xcart_config` SET `variants` = 'productcode:lbl_sku title:lbl_product orderby:lbl_default price:lbl_price add_date:lbl_date ' WHERE `name` = 'products_order' LIMIT 1 ;

fractalspin 08-06-2006 11:35 AM

Quote:

Thanks for the mod I did have to change one line to get the sort by working correctly.

As noted by Shan in an earlier post I changed the following line:

Code:

case "add_date":
$sort_string = "$sql_tbl[products].add_date DESC";
break;



to this
Code:

case "add_date":
$sort_string = "$sql_tbl[products].add_date $direction";
break;




When I made that change I got this DB Error:

Code:

INVALID SQL: 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1 xcart_featured_products, xcart_products_categories, xcart_categories LEFT JOI' at line 1
SQL QUERY FAILURE: SELECT COUNT(xcart_products.productid), MIN(xcart_pricing.price) as price , xcart_products_lng.product as product_lng, xcart_products_lng.descr as descr_lng, xcart_products_lng.full_descr as fulldescr_lng, IF(xcart_variants.variantid IS NOT NULL,'Y','') as is_variant, IF(xcart_classes.classid IS NOT NULL,'Y','') as is_product_options, MIN(v_pricing.price) as v_price, xcart_products_lng.product as product_lng, xcart_products_lng.descr as descr_lng, xcart_products_lng.full_descr as fulldescr_lng, IF(xcart_variants.variantid IS NOT NULL,'Y','') as is_variant, IF(xcart_classes.classid IS NOT NULL,'Y','') as is_product_options, MIN(v_pricing.price) as v_price FROM xcart_products, xcart_pricing 1 xcart_featured_products, xcart_products_categories, xcart_categories LEFT JOIN xcart_products_lng ON xcart_products_lng.productid = xcart_products.productid AND xcart_products_lng.code = 'US' LEFT JOIN xcart_classes ON xcart_classes.productid = xcart_products.productid LEFT JOIN xcart_variants ON xcart_variants.productid = xcart_products.productid LEFT JOIN xcart_pricing as v_pricing ON v_pricing.variantid = xcart_variants.variantid AND v_pricing.quantity = 1 AND v_pricing.membership IN ('','') WHERE xcart_products.productid=xcart_featured_products.productid AND xcart_featured_products.avail='Y' AND xcart_featured_products.categoryid='2' AND xcart_pricing.productid=xcart_products.productid AND xcart_pricing.quantity=1 AND xcart_pricing.membership IN ('','') AND xcart_products.product_type <> 'C' AND xcart_products.product_type <> 'B' AND xcart_pricing.variantid = 0 AND xcart_products_categories.productid=xcart_products.productid AND xcart_products_categories.categoryid = xcart_categories.categoryid AND xcart_categories.membership IN ('','') AND xcart_products.forsale='Y'xcart_pricing.productid=xcart_products.productid AND xcart_pricing.quantity=1 AND xcart_pricing.membership IN ('','') AND xcart_products.product_type <> 'C' AND xcart_products.product_type <> 'B' AND xcart_pricing.variantid = 0 AND xcart_products_categories.productid=xcart_products.productid AND xcart_products_categories.categoryid = xcart_categories.categoryid AND xcart_categories.membership IN ('','') AND xcart_products_categories.categoryid='2' AND (xcart_products_categories.main='Y' OR xcart_products_categories.main!='Y') AND xcart_products.forsale='Y' GROUP BY xcart_products.productid

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/fracta5/public_html/x/include/func.php on line 102


weird, right?[/quote]

admintds 08-08-2006 06:52 AM

Great and easy mod...I'm all about easy! Works like a charm! Thank you !!!

lachild 08-09-2006 12:59 PM

Incorrect Answer... Deleted.

lachild 08-09-2006 01:11 PM

fractalspin,

Your problem is right here...

Code:

xcart_pricing 1 xcart_featured_products,

This means while the $direction is working its not being translated...

Might try something like this..
Code:

case "add_date":

if ($direction == '1'){
    $direction_var = 'DESC';
}

if ($direction == '0') {
    $direction_var = 'ASC';
}
$sort_string = "$sql_tbl[products].add_date $direction_var";
break;


Ten 11-03-2006 02:37 PM

Re: Listing newest added product first
 
It's not working on 4.0.17.

What should be the value for $sort_string ?

I'm getting this: "xcart_products_categories.orderby ASC"

I think it's not valid. I followed all steps.

Thx.

Ten 11-04-2006 04:06 AM

Re: Listing newest added product first
 
Finally It's working on 4.0.17.

That's what I had to do:

- It wasn't working with the first indications, and I could not change in the database what lachild said, because my version hasn't a field 'variants' in xcart_config.

So, in /admin/configuration.php:

Around line 143:
Code:

    $products_orderby = array(
        "productcode"    => func_get_langvar_by_name("lbl_sku"),
        "title"        => func_get_langvar_by_name("lbl_product"),
        "orderby"        => func_get_langvar_by_name("lbl_default"),
        "price"        => func_get_langvar_by_name("lbl_price")


Before "productcode", add

Code:

"add_date"    => func_get_langvar_by_name("lbl_date"),

And it's working very well, and I can change the order from the admin/General Settings/Appearance/ Select the order...

Hope this help!

Jerrad 11-05-2006 07:14 AM

Re: Listing newest added product first
 
Thanks for this great mod!
Newest products are indeed shown first, but unfortunately the ASC or DESC sort doesn't work for me either...

Any body got this fixed for version 4.x?
Thanks!

ShishaPipeUK 11-07-2006 03:14 PM

Re: Listing newest added product first
 
I want to be able to sort my products by quantity in stock, so my customer views the most products in stock first.
Now at the moment in the admin section we have in X-Cart admin->General Settings->Apperance: "Select the order in which products should be displayed within a category:"
SKU
PRODUCT
PRICE
DEFAULT
I want to add to this QUANTITY so all my low quantity items and out of stock items will be displayed last when a customer is viewing the products.

Anyone got any ideas ?

LoveHurts 03-18-2007 02:58 AM

Re: Listing newest added product first
 
Worx fine !!!! Thx guys !!!!

I couldnt not set sort by date as default.
everytime i klick on category, it's sort by name.

how can i set this is the 'default' sort?

mike@eternitywebdev.com 03-21-2007 09:30 AM

Re: Listing newest added product first
 
Is there a way to make this mod do the following:

1. AUTO show newest added products
2. But ALSO be able to use the Manual ORDER to move specific products around?

X-Cart Gold 4.0.19

JWait 03-28-2007 06:12 PM

Re: Listing newest added product first
 
Quote:

Originally Posted by LoveHurts
Worx fine !!!! Thx guys !!!!

I couldnt not set sort by date as default.
everytime i klick on category, it's sort by name.

how can i set this is the 'default' sort?


Thats what I'm looking for, sort by add_date = newest by default in x-cart 4.1.6. It works fine as is for x-cart 4.0.19.

whirledplanet 04-04-2007 06:36 PM

Re: Listing newest added product first
 
Just wondering what I'm doing wrong. I've made all the changes Boomer outlined (thanks Boomer), and the date option appears, but it doesn't default to date. In other words, if I choose SKUchoose as the default in general settings--> appearance, it still sets SKU to be the default. There is no way to set date as the default. A customer can choose to order by date, but I want date to be automatically chosen so they see newest items first by default.

Any help?

JWait 04-04-2007 07:48 PM

Re: Listing newest added product first
 
You are not doing anything wrong. This modification does not work correctly in 4.1.x.

JWait 07-24-2007 09:24 AM

Re: Listing newest added product first
 
Any update on this to work with the current version of xcart (4.1.8)?

OpheliaPayne 11-20-2007 06:45 AM

Re: Listing newest added product first
 
I would love to get this working in 4.1.8 as well.

minhta 08-18-2008 02:52 AM

Re: Listing newest added product first
 
Hello

Just want to see if anyone has any update on displaying the newest products first? I am managing x-cart version 4.1.10.

Thanks in advance


All times are GMT -8. The time now is 07:07 PM.

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