Merge pull request #9534 from wdammak/patch-16

Add the ability to sort products by category
This commit is contained in:
Laurent Destailleur 2018-12-14 10:02:08 +01:00 committed by GitHub
commit 9bb3382002
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2040,6 +2040,17 @@ class Form
$sql = "SELECT "; $sql = "SELECT ";
$sql.= $selectFields . $selectFieldsGrouped; $sql.= $selectFields . $selectFieldsGrouped;
if (! empty($conf->global->PRODUCT_SORT_BY_CATEGORY))
{
//Product category
$sql.= ", (SELECT ".MAIN_DB_PREFIX."categorie_product.fk_categorie
FROM ".MAIN_DB_PREFIX."categorie_product
WHERE ".MAIN_DB_PREFIX."categorie_product.fk_product=p.rowid
LIMIT 1
) AS categorie_product_id ";
}
//Price by customer //Price by customer
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid))
{ {
@ -2144,7 +2155,19 @@ class Form
{ {
$sql.= ' GROUP BY'.$selectFields; $sql.= ' GROUP BY'.$selectFields;
} }
$sql.= $db->order("p.ref");
//Sort by category
if(! empty($conf->global->PRODUCT_SORT_BY_CATEGORY))
{
$sql .= " ORDER BY categorie_product_id ";
//ASC OR DESC order
($conf->global->PRODUCT_SORT_BY_CATEGORY == 1) ? $sql .="ASC" : $sql .="DESC";
}
else
{
$sql.= $db->order("p.ref");
}
$sql.= $db->plimit($limit, 0); $sql.= $db->plimit($limit, 0);
// Build output string // Build output string