Changing Product Default Sort Order using an add-in

I have added the following code to my add in page:


function fn_ws_products_sorting($sorting)
{
$sorting = array(
'timestamp' => array(description => fn_get_lang_var('timestamp'), 'default_order' => 'desc'),
'position' => array('description' => fn_get_lang_var('position'), 'default_order' => 'asc'),
'product' => array('description' => fn_get_lang_var('name'), 'default_order' => 'asc'),
'price' => array('description' => fn_get_lang_var('price'), 'default_order' => 'asc'),
'popularity' => array('description' => fn_get_lang_var('popularity'), 'default_order' => 'desc')
);
}
This code fires after the the code in fn.catalog.php



function fn_get_products_sorting($simple_mode = true)
{
$sorting = array(
'position' => array('description' => fn_get_lang_var('default'), 'default_order' => 'asc'),
'product' => array('description' => fn_get_lang_var('name'), 'default_order' => 'asc'),
'price' => array('description' => fn_get_lang_var('price'), 'default_order' => 'asc'),
'popularity' => array('description' => fn_get_lang_var('popularity'), 'default_order' => 'desc')
);

fn_set_hook('products_sorting', $sorting);

if ($simple_mode) {
foreach ($sorting as &$sort_item) {
$sort_item = $sort_item['description'];
}
}

return $sorting;
}
Which allows you to add in your own sorting for products.



To change the default you must go into admin and click design…appearance settings…(and under customer settings), choose your added method.



I just a few things i don’t understand. Any method I add seems to have an _ added in front of it. This looks tacky on the page for the customer.



Also, I can only add time stamp, but not avail_since, and they are set differently on my site, so I would prefer the avail_since.



Any help greatly appreciated.

[quote name=‘scottemick’]I have added the following code to my add in page:


function fn_ws_products_sorting($sorting)
{
$sorting = array(
'timestamp' => array(description => fn_get_lang_var('timestamp'), 'default_order' => 'desc'),
'position' => array('description' => fn_get_lang_var('position'), 'default_order' => 'asc'),
'product' => array('description' => fn_get_lang_var('name'), 'default_order' => 'asc'),
'price' => array('description' => fn_get_lang_var('price'), 'default_order' => 'asc'),
'popularity' => array('description' => fn_get_lang_var('popularity'), 'default_order' => 'desc')
);
}
This code fires after the the code in fn.catalog.php



function fn_get_products_sorting($simple_mode = true)
{
$sorting = array(
'position' => array('description' => fn_get_lang_var('default'), 'default_order' => 'asc'),
'product' => array('description' => fn_get_lang_var('name'), 'default_order' => 'asc'),
'price' => array('description' => fn_get_lang_var('price'), 'default_order' => 'asc'),
'popularity' => array('description' => fn_get_lang_var('popularity'), 'default_order' => 'desc')
);

fn_set_hook('products_sorting', $sorting);

if ($simple_mode) {
foreach ($sorting as &$sort_item) {
$sort_item = $sort_item['description'];
}
}

return $sorting;
}
Which allows you to add in your own sorting for products.



To change the default you must go into admin and click design…appearance settings…(and under customer settings), choose your added method.



I just a few things i don’t understand. Any method I add seems to have an _ added in front of it. This looks tacky on the page for the customer.



Also, I can only add time stamp, but not avail_since, and they are set differently on my site, so I would prefer the avail_since.



Any help greatly appreciated.[/QUOTE]



Create appropriate language variable and they will go!!!

Ahh, thanks, I should have thought of that since I’m passing them through the fn_get_lang_var function.

[quote name=‘scottemick’]Ahh, thanks, I should have thought of that since I’m passing them through the fn_get_lang_var function.[/QUOTE]



:rolleyes: LOL

I still don’t know why the avail_since doesn’t work, but I will just keep looking.

[quote name=‘scottemick’]I still don’t know why the avail_since doesn’t work, but I will just keep looking.[/QUOTE]



Avail_since may already be used by CS. Try using available_since

Why add a new function and not to the original code? [url]http://forum.cs-cart.com/showthread.php?t=14820[/url]

I’m trying to keep all my mods in my addon so the upgrades go easier, I just thought that was a better way to do things (in theory at least).



So avail_since, available_since don’t work, I guess you cannot add those, but I can settle for timestamp.



what happens with avail_since is you end up with a query that has



order by desc at the end of it…