order in search product

This commit is contained in:
Marion Muszynski 2016-04-14 13:06:06 +02:00
parent 6c6b3472e5
commit d4722a7e81
2 changed files with 40 additions and 1 deletions

View File

@ -50,7 +50,7 @@ class AdminSearch extends AdminTab
{
global $cookie;
$this->_list['products'] = Product::searchByName((int)$cookie->id_lang, $query);
$this->_list['products'] = Product::searchByName((int)$cookie->id_lang, $query, 'id_product', 'DESC');
if (!empty($this->_list['products']))
for ($i = 0; $i < count($this->_list['products']); $i++)
$this->_list['products'][$i]['nameh'] = str_ireplace($query, '<span class="highlight">'.Tools::htmlentitiesUTF8($query).'</span>', $this->_list['products'][$i]['name']);
@ -134,6 +134,7 @@ class AdminSearch extends AdminTab
'manufacturer' => array('title' => $this->l('Manufacturer')),
'reference' => array('title' => $this->l('Reference')),
'name' => array('title' => $this->l('Name')),
'main_category_id' => array('title' => $this->l('Category')),
'price' => array('title' => $this->l('Price')),
'stock' => array('title' => $this->l('Stock')),
'status' => array('title' => $this->l('Status')),
@ -245,6 +246,7 @@ class AdminSearch extends AdminTab
<td align="center">'.($product['manufacturer_name'] != NULL ? stripslashes($product['manufacturer_name']) : '--').'</td>
<td>'.$product['reference'].'</td>
<td><a href="'.$currentIndex.'?tab=AdminCatalog&id_product='.$product['id_product'].'&addproduct&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee)).'">'.stripslashes($product['nameh']).'</a></td>
<td><a href="'.$currentIndex.'?tab=AdminCatalog&id_category='.$product['main_category_id'].'viewcategory&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee)).'">'.stripslashes($product['main_category_id']).'</a></td>
<td>'.Tools::displayPrice($product['price'], $currency).'</td>
<td align="center">'.$product['quantity'].'</td>
<td align="center"><a href="'.$currentIndex.'?tab=AdminCatalog&id_product='.$product['id_product'].'&status&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee)).'">

View File

@ -1,6 +1,43 @@
<?php
class Product extends ProductCore
{
/**
* @Override
* Admin panel product search
*
* @param integer $id_lang Language id
* @param string $query Search query
* @return array Matching products
*/
public static function searchByName($id_lang, $query, $orderBy = 'name', $order = 'ASC')
{
$result = Db::getInstance()->ExecuteS('
SELECT p.`id_product`, pl.`name`, p.`active`, p.`reference`, m.`name` AS manufacturer_name,
MIN(cp.`id_category`) AS `main_category_id`
-- (SELECT name FROM ps_category_lang WHERE `id_category` = MIN(cp.`id_category`) AND `id_lang` = 1) AS `main_category`
FROM `'._DB_PREFIX_.'category_product` cp
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)($id_lang).')
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON pa.`id_product` = p.`id_product`
WHERE pl.`name` LIKE \'%'.pSQL($query).'%\' OR p.`reference` LIKE \'%'.pSQL($query).'%\' OR p.`supplier_reference` LIKE \'%'.pSQL($query).'%\' OR pa.`reference` LIKE \'%'.pSQL($query).'%\'
GROUP BY `id_product`
ORDER BY pl.`'.$orderBy.'` '.$order);
if (!$result)
return false;
$resultsArray = array();
foreach ($result AS $row)
{
$row['price'] = Product::getPriceStatic($row['id_product'], true, NULL, 2);
$row['quantity'] = Product::getQuantity($row['id_product']);
$resultsArray[] = $row;
}
return $resultsArray;
}
public static function getProductsProperties($id_lang, $query_result, $cached = true)
{
$resultsArray = array();