Merge pull request #9534 from wdammak/patch-16
Add the ability to sort products by category
This commit is contained in:
commit
9bb3382002
@ -2037,9 +2037,20 @@ class Form
|
|||||||
|
|
||||||
$selectFields = " p.rowid, p.label, p.ref, p.description, p.barcode, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.duration, p.fk_price_expression";
|
$selectFields = " p.rowid, p.label, p.ref, p.description, p.barcode, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.duration, p.fk_price_expression";
|
||||||
(count($warehouseStatusArray)) ? $selectFieldsGrouped = ", sum(ps.reel) as stock" : $selectFieldsGrouped = ", p.stock";
|
(count($warehouseStatusArray)) ? $selectFieldsGrouped = ", sum(ps.reel) as stock" : $selectFieldsGrouped = ", p.stock";
|
||||||
|
|
||||||
$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,9 +2155,21 @@ class Form
|
|||||||
{
|
{
|
||||||
$sql.= ' GROUP BY'.$selectFields;
|
$sql.= ' GROUP BY'.$selectFields;
|
||||||
}
|
}
|
||||||
$sql.= $db->order("p.ref");
|
|
||||||
$sql.= $db->plimit($limit, 0);
|
//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);
|
||||||
|
|
||||||
// Build output string
|
// Build output string
|
||||||
dol_syslog(get_class($this)."::select_produits_list search product", LOG_DEBUG);
|
dol_syslog(get_class($this)."::select_produits_list search product", LOG_DEBUG);
|
||||||
$result=$this->db->query($sql);
|
$result=$this->db->query($sql);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user