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)
-   -   Add Extra options to Sort By in products list V4.x.x (https://forum.x-cart.com/showthread.php?t=12834)

shan 03-15-2005 04:37 PM

Add Extra options to Sort By in products list V4.x.x
 
This is done for V4.x.x

Been looking at adding extra sort fields to the options that sit at the top of the products list.

here in no particular order is where you need to change things. In this example I added the option to sort by date added.

admin/configuration.php

starts around line 138 (added line with add_date)

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"),
                "add_date"                => func_get_langvar_by_name("lbl_add_date")
        );



include/func.php

starts around line 1930, again added add_date section

Code:

        #
        # Generate ORDER BY rule
        #
        if (empty($orderby)) {
                $orderby = ($config["Appearance"]["products_order"] ? $config["Appearance"]["products_order"] : "orderby");
                if($orderby == 'title') {
                        $orderby = 'product';
                } elseif($orderby == 'quantity') {
                        $orderby = "$sql_tbl[products].avail";
                } elseif($orderby == "orderby") {
                        $orderby = "$sql_tbl[products_categories].orderby";
                } elseif($orderby == "quantity") {
                        $orderby = "$sql_tbl[products].avail";
                } elseif($orderby == "price") {
                        $orderby = "price";
                } elseif($orderby == "productcode") {
                        $orderby = "$sql_tbl[products].productcode";
                } elseif($orderby == "add_date") {
                        $orderby = "$sql_tbl[products].add_date";
                }
        }


include/search.php

starts around line 407, again add add_date section, alter the order of the "DESC" : "ASC" bit to alter default order

Code:

                $direction = ($data["sort_direction"] ? "DESC" : "ASC");
                switch ($data["sort_field"]) {
                        case "productcode":
                                $sort_string = "$sql_tbl[products].productcode $direction";
                                break;
                        case "add_date":
                                $sort_string = "$sql_tbl[products].add_date $direction";
                                break;
                        case "title":
                                $sort_string = "$sql_tbl[products].product $direction";
                                break;
                        case "orderby":
                                $sort_string = "$sql_tbl[products_categories].orderby $direction";
                                break;
                        case "quantity":
                                $sort_string = "$sql_tbl[products].avail $direction";
                                break;



include/search.php again, around line 47

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"),
        "add_date"                => func_get_langvar_by_name("lbl_add_date")
);


if you want to add the Added date to one of the templates you can do so with

Code:

{$products[product].add_date|date_format:"%d/%m/%y"}

or

Code:

{$product.add_date|date_format:"%d/%m/%y"}

pretty sure thats about it. you can swap the add_date bit for whatever field you wish to use from the products table or remove any fields you dont want to use. Once your done set the default order by in general settings / appearence / product order

digisoftuk 04-29-2005 04:49 AM

Sort
 
Hi

I want to add in a alphabetically search so for example A,B,C,D etc customer clicks on A it only returns products which start with a and so on can you advise if this mod you have done with work with this here is a link to a demo if your not sure what i'm on about http://www.play.com/play247.asp?pa=navmain&page=front&r=PS2

Hope you can help

Thanks

poil11 01-21-2008 12:29 PM

Re: Add Extra options to Sort By in products list V4.x.x
 
Hi, new to x-cart, I have made this possible to work with 4.1.9, but i don't know where to add it to the template file to make it show up in the sort options. Or how to add it to the default listing in the admin menus. Can anyone help a bit more with this?
includes/search.php, added add_date line:
PHP 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"),
    
"add_date"        => func_get_langvar_by_name("lbl_add_date")
); 


Added add_date stuff:

PHP Code:

$current_area == 'B') && $data["sort_field"] == 'productcode')
            
$data["sort_field"] = 'orderby';

        switch (
$data["sort_field"]) {
            case 
"productcode":
                
$sort_string "$sql_tbl[products].productcode $direction";
                break:
case 
"add_date":
                
$sort_string "$sql_tbl[products].add_date $direction";
                break; 


includes/func/func.products.php


Added add_date stuff:

PHP Code:

if (is_null($orderby_rules)) {
        
$orderby_rules = array (
            
"title" => "product",
            
"quantity" => "$sql_tbl[products].avail",
            
"orderby" => "$sql_tbl[products_categories].orderby",
            
"quantity" => "$sql_tbl[products].avail",
            
"price" => "price",
            
"add_date" =>     "$sql_tbl[products].add_date",
            
"productcode" => "$sql_tbl[products].productcode");
    } 


Ahhhh i had to add the language file lbl_add_date, done...

pairodimes 05-23-2008 06:04 PM

Re: Add Extra options to Sort By in products list V4.x.x
 
I just applied this patch as well - it works great - but I am not sure how to add my new Sort Fied as an Option in the Admin Drop Down for:

" Select the order in which products should be displayed within a category:"

Any Ideas?

pairodimes 05-26-2008 11:27 AM

Re: Add Extra options to Sort By in products list V4.x.x
 
Ok - I read another thread and found the SQL table that contains the Admin Drop Down information for sorting products.

just add your new 'add_date' to the "xcart_config" table - sort by 'title' field - look for the row "product_order" -> look for the field 'varients' -> edit this content to include our new date field.

ex:
add_date:
adddate: lbl_add_date
productcode:lbl_sku
title:lbl_product
orderby: lbl_default
price:lbl_price

this should now show up in the Admin drop down.

whykie 10-08-2008 06:57 PM

Re: Add Extra options to Sort By in products list V4.x.x
 
I'm trying the same thing -- I have an extra field for date added (and I'll do the same after I get this working for date released). I have the drop down menu for sort but I can't get the functionality to work. In include/search.php I added this line

whykie 10-08-2008 07:15 PM

Re: Add Extra options to Sort By in products list V4.x.x
 
continued ... I added this line "produpdated" => func_get_langvar_by_name("lbl_prod_update_date"), and on line 603 I added this --- case "produpdated":
$sort_string = "$sql_tbl[products_extra_field_value].prod_update_date $direction";
break;

but I get this error message when I use the sort --- 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 'ASC, xcart_products.product ASC, xcart_products.productcode ASC, xcart_products.' at line 1
SQL QUERY FAILURE:SELECT COUNT(xcart_products.productid) FROM xcart_pricing, xcart_products LEFT JOIN xcart_quick_flags ON xcart_quick_flags.productid = xcart_products.productid LEFT JOIN xcart_product_memberships ON xcart_product_memberships.productid = xcart_products.productid INNER JOIN xcart_quick_prices ON xcart_quick_prices.productid = xcart_products.productid AND xcart_quick_prices.membershipid = '0' LEFT JOIN xcart_variants ON xcart_variants.productid = xcart_products.productid AND xcart_quick_prices.variantid = xcart_variants.variantid INNER JOIN xcart_products_categories ON xcart_products_categories.productid = xcart_products.productid INNER JOIN xcart_categories ON xcart_products_categories.categoryid = xcart_categories.categoryid LEFT JOIN xcart_category_memberships ON xcart_category_memberships.categoryid = xcart_categories.categoryid WHERE xcart_quick_prices.priceid = xcart_pricing.priceid AND xcart_products.product_type <> 'C' AND xcart_products.forsale <> 'B' AND xcart_category_memberships.membershipid IS NULL AND xcart_product_memberships.membershipid IS NULL AND xcart_categories.avail = 'Y' AND xcart_products_categories.categoryid='253' AND (xcart_products_categories.main='Y' OR xcart_products_categories.main!='Y') AND (xcart_products.forsale = 'Y' OR xcart_products.forsale = '') GROUP BY xcart_products.productid ORDER BY .prod_update_date ASC, xcart_products.product ASC, xcart_products.productcode ASC, xcart_products.productid ASC
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/unique/public_html/cart/include/func/func.db.php on line 157

whykie 10-08-2008 07:16 PM

Re: Add Extra options to Sort By in products list V4.x.x
 
So can someone direct me to the code that would work for an extra field value sort?

whykie 11-05-2008 03:11 PM

Re: Add Extra options to Sort By in products list V4.x.x
 
found this 29.95 mod that does it http://bcsengineering.com/store/catalog/Product_Sort_by_Pro_for_Xcart-p-275.html

ChristineP 01-15-2009 11:54 AM

Re: Add Extra options to Sort By in products list V4.x.x
 
I'm going to try this mod from Shan with the drop-down as you've indicated. If I want to change the Sort by: sequence (ie. Sort by: Price Product Date Added), do I change this in the include/search.php file or is there a .tpl that I need to change?

Christine


Quote:

Originally Posted by pairodimes
Ok - I read another thread and found the SQL table that contains the Admin Drop Down information for sorting products.

just add your new 'add_date' to the "xcart_config" table - sort by 'title' field - look for the row "product_order" -> look for the field 'varients' -> edit this content to include our new date field.

ex:
add_date:
adddate: lbl_add_date
productcode:lbl_sku
title:lbl_product
orderby: lbl_default
price:lbl_price

this should now show up in the Admin drop down.



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

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