fburn Posted November 3, 2008 Share Posted November 3, 2008 To facilitate making changes to products supplied by a particular manufacturer, i.e. prices I've added searchByManufacturer to the to the search functionality in the back-end. This easily allows all of a manufacturers products to be returned and then can then be worked on directly.Here's the code:In Product.php /** * Admin panel product search * * @param integer $id_lang Language id * @param string $query Search query * @return array Matching products */ static public function searchByManufacturer($id_lang, $query) { if (!Validate::isCatalogName($query)) die(Tools::displayError()); $result = Db::getInstance()->ExecuteS(' SELECT p.`id_product`, pl.`name`, pl.`link_rewrite`, p.`weight`, p.`active`, p.`ecotax`, i.`id_image`, p.`reference`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name 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` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = p.`id_tax` LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`) AND i.`cover` = 1 LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($id_lang).') WHERE m.`name` LIKE \'%'.pSQL($query).'%\' GROUP BY `id_product` ORDER BY pl.`name` ASC'); if (!$result) return false; $resultsArray = array(); foreach ($result AS $k => $row) { $row['price'] = Product::getPriceStatic($row['id_product'], true, NULL, 2); $row['quantity'] = Product::getQuantity($row['id_product']); $resultsArray[] = $row; } return $resultsArray; } In AdminSearch.php: /** * Search a specific string in the product's manufacturer * * @params string $query String to find in the catalog */ public function searchCatalogManufacturer($query) { global $cookie; $products = false; if (Validate::isCatalogName($query)) { $this->_list['products'] = Product::searchByManufacturer(intval($cookie->id_lang), $query); if (!empty($this->_list['products'])) for ($i = 0; $i < count($this->_list['products']); $i++) $this->_list['products'][$i]['nameh'] = str_ireplace($query, ''.$query.'', $this->_list['products'][$i]['name']); } if (Validate::isCatalogName($query)) $this->_list['categories'] = Category::searchByName(intval($cookie->id_lang), $query); } And again in AdminSearch.php: } /* Product research */ elseif (intval($_POST['bo_search_type']) == 4) { $this->fieldsDisplay = (array( 'id' => array('title' => $this->l('id')), 'manufacturer' => array('title' => $this->l('Manufacturer')), 'reference' => array('title' => $this->l('Reference')), 'name' => array('title' => $this->l('Name')), 'price' => array('title' => $this->l('Price')), 'tax' => array('title' => $this->l('Tax')), 'stock' => array('title' => $this->l('Stock')), 'weight' => array('title' => $this->l('Weight')), 'status' => array('title' => $this->l('Status')), 'action' => array('title' => $this->l('Actions')) )); $this->searchCatalogManufacturer(trim(strval($_POST['bo_query']))); } else Tools::displayError('please fill in search form first.'); in header.inc.php case 'en': default: $lheader = array( 'Administration panel' => 'Back Office', 'product, category...' => 'product, category...', 'customer id, name, e-mail...' => 'customer id, name, e-mail...', 'order id' => 'order id', 'in' => 'in', 'catalog' => 'catalog', 'customers' => 'customers', 'orders' => 'orders', 'Search' => 'Search', 'home' => 'home', 'user' => 'user', 'My Shop' => 'My Shop', 'Home' => 'Home', 'logout' => 'logout', 'Quick access' => 'Quick access', 'manufacturer' => 'manufacturer' ); And again in header.inc.php: $_POST['bo_search_type'] == 3)) ? ' selected="selected"' : '' ?>><?php echo $lheader['orders'] ?> $_POST['bo_search_type'] == 4)) ? ' selected="selected"' : '' ?>><?php echo $lheader['manufacturer'] ?> If anyone has questions, please feel free to email me. Link to comment Share on other sites More sharing options...
Maxmito Posted February 17, 2009 Share Posted February 17, 2009 Very interesting!It's possible to use this script to search by Features?I try to change the SQL query but maybe I must change also other...Thanks!Max Link to comment Share on other sites More sharing options...
vlinedesign Posted June 26, 2010 Share Posted June 26, 2010 Very nice work! Is it possible to change this to search for Customers by Product ID? Link to comment Share on other sites More sharing options...
Recommended Posts