How to add new sorting by discount percent!

Hi,

I did this for a client and i fill like sharing :D



The sorting is done by the percent of the discount and on my opinion i this it must be added by default in cs-cart because is a great sorting feature



You need to create or add to an existing addon:



#addons/[ADDON_NAME]/init.php



fn_register_hooks(

‘products_sorting’,

‘get_products’

);





#addons/[ADDON_NAME]/func.php



function fn_[ADDON_NAME]products_sorting($sorting, $simple_mode)

{

$sorting[‘discount’] = array(‘description’ => fn_get_lang_var(‘discount’), ‘default_order’ => ‘desc’);

}



function fn
[ADDONS_NAME]_get_products($params, $fields, $sortings, $condition, $join, $sorting, $group_by, $lang_code)

{

if($params[‘sort_by’] == ‘discount’){

$sortings[‘discount’] = ‘discount_percent’;

$fields[] = ‘CEIL(( products.list_price - price ) / products.list_price * 100) AS discount_percent’;

}

}



#language

sort_by_discount_asc=Sort by Discount: Low to High

sort_by_discount_desc=Sort by Discount: High to Low