I'm building an online bookstore with Prestashop 1.6.1.6. Since the field "author" is not on the database, I've created this custom product field, but I am unable to perform searches by author's name.
Following this blog I have written this piece of code in "Search.php" but blog directions are for an older version and I have the least clue to re-write the class.
public static function getAuthors ($db, $id_product)
{
$authors ='';
$authorsArray = $db->executeS('
SELECT a.name FROM '._DB_PREFIX_. 'author sp
LEFT JOIN '._DB_PREFIX_. 'author a ON (a.id_product = sp.id_product)
WHERE sp.id_product = '. (int)$id_product. '
GROUP BY a.id_product'
);
foreach ($authorsArray as $author){
$authors. = $authors['name'] .'';
}
return $authors;
}
/ Every fields are weighted according to the configuration in the backend
$weight_array = array(
'pname' => Configuration::get('PS_SEARCH_WEIGHT_PNAME'),
//Add author to index search
'author' => Configuration::get('PS_SEARCH_WEIGHT_PNAME'),
'reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
'pa_reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
'supplier_reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
'pa_supplier_reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
'ean13' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
'pa_ean13' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
'upc' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
'pa_upc' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
'description_short' => Configuration::get('PS_SEARCH_WEIGHT_SHORTDESC'),
'description' => Configuration::get('PS_SEARCH_WEIGHT_DESC'),
'cname' => Configuration::get('PS_SEARCH_WEIGHT_CNAME'),
'mname' => Configuration::get('PS_SEARCH_WEIGHT_MNAME'),
'tags' => Configuration::get('PS_SEARCH_WEIGHT_TAG'),
'attributes' => Configuration::get('PS_SEARCH_WEIGHT_ATTRIBUTE'),
'features' => Configuration::get('PS_SEARCH_WEIGHT_FEATURE')
);
Thanks for reading.