Jump to content

Searching Products By Tag


Amiral D.

Recommended Posts

Hello everyone,

 

I try to dev a solution for Prestashop, but i can't figure how to search by tag with the DbQuery object.

 

I wrote this but it's false, can anyone help me ?

 

 

 

 

 

$sql = new DbQuery();

$sql->select('*');

$sql->from('products', 'c');

$sql->innerJoin('product_tag', 'l', 'c.id_product = l.id_product');

$sql->innerJoin('tag', 'm', 'l.id_tag = m.id_tag');

$sql->where('m.name = apple');

$sql->orderBy('product_tag');

$res = Db::getInstance()->executeS($sql);

print_r($res);

 

 

 

-> Error 500

 

S.O.S.

 

M.

Link to comment
Share on other sites

Hi,

 

for debug sql-query use:

$sql = new DbQuery();
$sql->select('*');
$sql->from('products', 'c');
$sql->innerJoin('product_tag', 'l', 'c.id_product = l.id_product');
$sql->innerJoin('tag', 'm', 'l.id_tag = m.id_tag');
$sql->where('m.name = apple');
$sql->orderBy('product_tag');
print_r((string)$sql); die;
//or $sql->build()
$res = Db::getInstance()->executeS($sql);
print_r($res);

 

Regards

Link to comment
Share on other sites

Thanks for your response, i've solved a part of it, just check what i've done :

 

$sql = new DbQuery();
 $sql->select('*');
 $sql->from('product', 'p');
 $sql->innerJoin('product_tag', 'l', 'p.id_product = l.id_product');
 $sql->innerJoin('tag', 't', 'l.id_tag = t.id_tag');
 $sql->where('t.name = "apple"');
 $sql->orderBy('t.name');
 $res = Db::getInstance()->executeS($sql);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...