Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

How to add new sorting by discount percent! Rate Topic   - - - - -

 
  • Hungryweb
  • Senior Member
  • Authorized Reseller
  • Join Date: 10-Feb 12
  • 1271 posts

Posted 12 October 2012 - 06:12 AM #1

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