Jump to content

How to update price using the prestashop 1.5.2 API?


Claudiu Nesa

Recommended Posts

Hi,

 

Does anyone know how to update a certain product price from a custom module.

 

I try to make something like this: after 10 days I want to update the price of the product with +/-2% depending on some variables that I'm creating inside my module.

 

I searched all over the internet and also in prestashop classes in order to find a method that simply updates the price of a product but with no luck so far.

 

I even thought to update it manually by executing an insert directly from my module but I noticed that it won't be a good approach.

 

Thank you in advance,

C.

Link to comment
Share on other sites

Hi Claudiu,

 

With the new_price and the id_product of the product you want to udpate :

 $product = new Product($id_product);
 $product->price = $new_price;
 $product->update();

 

You will perhaps have to deal with wholesale_price.

 

Regards

 

Is there something else that I should do after $product->update(); 'cause it does not change the price in the database for that product.

Thank you!

Link to comment
Share on other sites

Hi Claudiu,

 

Do you have specific prices ?

If you make a test on one product (id_product 22) and look in mysql the price is still the same ?

 

Try also this code.

$product = new Product((int)$id_product);
 $product->price = (float)$new_price;
 $product->update();

 

Tell me if it does not work.

 

Regards

Link to comment
Share on other sites

  • 4 months later...

Hi ondapc

 

Before asking for explanation you can :

- write 'Hello' because even computer have 'handshake' or 'session start'....

- check the way you make weird foreach php loop

- choose words : 'mysql' has nothing to do here it is hidden

- thanks in advance for free support

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