Jump to content

How to update an external database when an order is done ?


Rulian

Recommended Posts

Hi,

 

I'm working for a record dealer who currently uses Prestashop 1.6.
The guy would like to sell records from its Prestashop website as usual, but also from Discogs (a records selling marketplace with a nice API).

My current concern is how to update the stock on the Discogs side, each time we sell something via PrestaShop.

At which point, when a PS order is considered as done, should I call the discogs API in order to decrease the discogs stock for the corresponding items ?
Does any of you encountered the same kind of situation ? (updating an external reference when something is sold on PS) ?

Any help appreciated,

Cheers
 

Link to comment
Share on other sites

For this you would likely want to create a module in Prestashop, and then implement hooks (aka events).  There are probably a few different ways to implement this using hooks

 

My first thought is to register for the "new order" hook, and then react based on the contents of the order.

However there are likely hooks that would trigger based on stock changing, and this may be the better approach, since it would deal with returns/refunds etc..

  • Like 1
Link to comment
Share on other sites

Hi..

you need use your custom module hook with "actionOrderStatusUpdate" like the below

 

 

public function install()
{
return parent::install() && $this->registerHook('actionOrderStatusUpdate');
}
public function hookActionOrderStatusUpdate($params)
{
$orderstates = $params['newOrderStatus'];
if($orderstates->id == "id"){
//your api call here
}
}

Thanks

  • Like 1
Link to comment
Share on other sites

Thank you guys, that's exactly what I was looking for !

My PS dev skills are a little bit rusty and I forgot about the hook/event thingy.

 

I was thinking about overriding a class/controller (but didn't know wich one to extend), but the module registering the right event looks way better.

Edited by Rulian (see edit history)
Link to comment
Share on other sites

Or directly overwrite the order controller with a new function which updates external database when needed.

Then you need eigther a remote host where you can connect to a database (preferred if possible) or you write some kind of XML or other formatted data into a certain folder and the third-party system fetches data from your prestashop server.

 

What I can say with my experience: It's not done within one or two hours.

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