// order_by improved
This commit is contained in:
+18
-3
@@ -905,6 +905,12 @@ class ProductCore extends ObjectModel
|
||||
else if ($order_by == 'position')
|
||||
$order_by_prefix = 'c';
|
||||
|
||||
if (strpos($order_by, '.') > 0)
|
||||
{
|
||||
$order_by = explode('.', $order_by);
|
||||
$order_by_prefix = $order_by[0];
|
||||
$order_by = $order_by[1];
|
||||
}
|
||||
$sql = 'SELECT p.*, pl.* , t.`rate` AS tax_rate, m.`name` AS manufacturer_name, s.`name` AS supplier_name
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.$context->shop->addSqlAssociation('product', 'p').'
|
||||
@@ -1750,7 +1756,12 @@ class ProductCore extends ObjectModel
|
||||
|
||||
$groups = FrontController::getCurrentCustomerGroups();
|
||||
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
|
||||
|
||||
if (strpos($order_by, '.') > 0)
|
||||
{
|
||||
$order_by = explode('.', $order_by);
|
||||
$order_by_prefix = $order_by[0];
|
||||
$order_by = $order_by[1];
|
||||
}
|
||||
if ($count)
|
||||
{
|
||||
$sql = 'SELECT COUNT(p.`id_product`) AS nb
|
||||
@@ -1971,7 +1982,11 @@ class ProductCore extends ObjectModel
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||
return (int)$result['nb'];
|
||||
}
|
||||
|
||||
if (strpos($order_by, '.') > 0)
|
||||
{
|
||||
$order_by = explode('.', $order_by);
|
||||
$order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`';
|
||||
}
|
||||
$sql = 'SELECT p.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`,
|
||||
pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`,
|
||||
pl.`name`, i.`id_image`, il.`legend`, t.`rate`, m.`name` AS manufacturer_name,
|
||||
@@ -2005,7 +2020,7 @@ class ProductCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
||||
WHERE cg.`id_group` '.$sql_groups.'
|
||||
)
|
||||
ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').'`'.pSQL($order_by).'`'.' '.pSQL($order_way).'
|
||||
ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').pSQL($order_by).' '.pSQL($order_way).'
|
||||
LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products;
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
|
||||
Reference in New Issue
Block a user