Gramzivi Posted April 19, 2017 Share Posted April 19, 2017 In my Prestashop controller I have name of product, if that product exist, I need information's of that product. How to get information's about product if you only have product name ? Link to comment Share on other sites More sharing options...
hakeryk2 Posted April 19, 2017 Share Posted April 19, 2017 (edited) As far as I know there is no this kind of method in prestashop but You can use this function public function getProductIdByProductName($search, $id_shop = 1, $id_lang = 1) { return Db::getInstance()->getValue(' SELECT id_product FROM '._DB_PREFIX_.'product_lang WHERE name LIKE "%'.(string)$search.'%" AND id_shop = '.$id_shop.' AND id_lang = '.$id_lang.' '); } and after that in the same module or so use retrieved ID in example like this $product = new Product($this->getProductIdByProductName('Your product name')); Function is returning plain int with id of product that You can use to create new Product object. If You want to have strict match of name delete those % % in LIKE statement and If You using multilanguage and multishop You have to pass context values to get id of shop and language. Edited April 19, 2017 by hakeryk2 (see edit history) Link to comment Share on other sites More sharing options...
ventura Posted April 19, 2017 Share Posted April 19, 2017 Better check your controller´s logic. It´s no the better way to take product´s information, especially in a multilang environment Link to comment Share on other sites More sharing options...
hakeryk2 Posted April 19, 2017 Share Posted April 19, 2017 Agree with ventura: it is pretty much akward question from OP but there You go. Link to comment Share on other sites More sharing options...
changa Posted October 21, 2020 Share Posted October 21, 2020 how to retrieve the name of all product the sql query ? good morning Link to comment Share on other sites More sharing options...
rrataj Posted December 2, 2020 Share Posted December 2, 2020 Please try this one: SELECT name FROM ps_product_lang WHERE id_shop = 1 AND id_lang = 1; Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now