Kekeno Posted April 10, 2015 Share Posted April 10, 2015 Hey guys, I'm currently developing a module for prestashop and i need to get the price of all my products for a cron task. I'm doing it with some simple sql queries, but i can't get the correct price (with reduction..) without doing a lots of stuff ! I heard about the Product::getProductProperties($id_lang, $row), that can may help me, but i don't know how to use it. How can i get the id_lang ? and what is the $row ? and will it help me to get the correct "final selling" price ? Thanks Link to comment Share on other sites More sharing options...
sandipchandela Posted April 13, 2015 Share Posted April 13, 2015 get the language by this id - $this->context->language->id; http://doc.prestashop.com/display/PS15/Using+the+Context+Object Try with this calling - funtion getProductsProperties() Thanks Link to comment Share on other sites More sharing options...
Kekeno Posted April 13, 2015 Author Share Posted April 13, 2015 Hey, thanks for your answer ! I'm trying this to test, but getting a "fatal error" $sql = 'SELECT * FROM '._DB_PREFIX_.'product WHERE id_product = 1'; $row = Db::getInstance()->getRow($sql); $prop = Product::getProductProperties($this->context->language->id, $row); Am i doing something wrong ? Link to comment Share on other sites More sharing options...
sandipchandela Posted April 13, 2015 Share Posted April 13, 2015 $sql = 'SELECT * FROM '._DB_PREFIX_.'product WHERE id_product = 1'; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $prop = Product::getProductsProperties( $this->context->language->id, $result); Link to comment Share on other sites More sharing options...
Kekeno Posted April 13, 2015 Author Share Posted April 13, 2015 (edited) $sql = 'SELECT * FROM '._DB_PREFIX_.'product WHERE id_product = 1'; $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $prop = Product::getProductProperties($this->context->language->id, $row); var_dump($prop); I'm getting "bool(false)" with the var_dump.. At least, I have a product with id = 1... $row isn't empty [edit] I had to use $row[0] instead of $row.. or getProductsProperties [/edit] Edited April 13, 2015 by Kekeno (see edit history) Link to comment Share on other sites More sharing options...
sandipchandela Posted April 13, 2015 Share Posted April 13, 2015 dear exact copy my code and pasted it. It works. I have tested and get the results. Thanks Link to comment Share on other sites More sharing options...
Kekeno Posted April 13, 2015 Author Share Posted April 13, 2015 I get this error : Notice: Undefined index: link_rewrite in /home/www/.../classes/Product.php on line 3874 Is it the right way to get the real selling price of a product ? Link to comment Share on other sites More sharing options...
sandipchandela Posted April 13, 2015 Share Posted April 13, 2015 I get this error : Notice: Undefined index: link_rewrite in /home/www/.../classes/Product.php on line 3874 Is it the right way to get the real selling price of a product ? Mean while you can get the product info like this. link_write is just warning, you can ignore this. Link to comment Share on other sites More sharing options...
Kekeno Posted April 13, 2015 Author Share Posted April 13, 2015 But this is warning that prints me "fatal error" and cannot load the rest of my page whenever i put debug mode at false... How do i get the product price so ? Link to comment Share on other sites More sharing options...
sandipchandela Posted April 13, 2015 Share Posted April 13, 2015 I think this won't give error. $sql = 'SELECT * FROM '._DB_PREFIX_.'product WHERE id_product = 1'; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); var_dump( $result ); Link to comment Share on other sites More sharing options...
Kekeno Posted April 13, 2015 Author Share Posted April 13, 2015 Yes but i need the price of my product with all reductions applied. I need to get the price written in the FO product page... Link to comment Share on other sites More sharing options...
sandipchandela Posted April 13, 2015 Share Posted April 13, 2015 This query only returns the basic product info. If you want to get some more info then you have to look into Classes that are associating with Product Class. SpecificPrice Class will help you out. $result = SpecificPrice::getByProductId( 1 ); //1 is your product id This will work like charm. 1 Link to comment Share on other sites More sharing options...
Kekeno Posted April 13, 2015 Author Share Posted April 13, 2015 (edited) Ok this is nearly perfect, now i just have to do the convertion by hand ! Thank you very much for helping me ! If someone knows an other way to do it, i'm here to take the solution (something like "Product::getPrice($idProduct)" that will give me directly the final price with reductions) [EDIT] after few tests, getByProductId(1) just give me a select * where productid = 1. The 'from' and 'to' fields are not taken in consideration, so past reduction will be taken :/. I'll have a look with getSpecificPrice(...) [/EDIT] Edited April 13, 2015 by Kekeno (see edit history) Link to comment Share on other sites More sharing options...
sandipchandela Posted April 14, 2015 Share Posted April 14, 2015 Ok this is nearly perfect, now i just have to do the convertion by hand ! Thank you very much for helping me ! If someone knows an other way to do it, i'm here to take the solution (something like "Product::getPrice($idProduct)" that will give me directly the final price with reductions) [EDIT] after few tests, getByProductId(1) just give me a select * where productid = 1. The 'from' and 'to' fields are not taken in consideration, so past reduction will be taken :/. I'll have a look with getSpecificPrice(...) [/EDIT] If you want to get some different product row data from table, you have to go through sql joins that will help you. Link to comment Share on other sites More sharing options...
Kekeno Posted April 14, 2015 Author Share Posted April 14, 2015 I solved my problem ! You can get the prices of products thqt you want by "playing" with the arguments of the function Product::getPriceStatic() I just put '1' for the $id_cart argument ! Thanks for your help sandipchandela ! 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