Jump to content

Products prices


Recommended Posts

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

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

$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 by Kekeno (see edit history)
Link to comment
Share on other sites

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

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. 

  • Like 1
Link to comment
Share on other sites

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 by Kekeno (see edit history)
Link to comment
Share on other sites

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

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

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...