Jump to content

Update stock from external database on request


Recommended Posts

I managed to connect Prestashop to an external MSSQL database in order to update stock quantity.

 

The stocks are being updated regularly via cronjobs, while I would like to update the stock on fly when a user views a specific product, when its added to cart and when its about to be purchased.

 

I can not find my way in hook documentation and currently no idea where to look at. I need some hook points, where I can do this manual request.

 

If there is a hook, that is run when a single product is viewied?

A hook that is just before the product has been added?

And a hook that is just before payment.

 

Thank you in advance.

Link to comment
Share on other sites

You don't say what version of Prestashop, so I am assuming PS v1.6.1.6

 

These hooks are executed by the ProductController, which is the controller that is executed when you visit a Product page

'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'),
'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'),
'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)),
'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)),
'HOOK_PRODUCT_TAB' =>  Hook::exec('displayProductTab', array('product' => $this->product)),
'HOOK_PRODUCT_TAB_CONTENT' =>  Hook::exec('displayProductTabContent', array('product' => $this->product)),
'HOOK_PRODUCT_CONTENT' =>  Hook::exec('displayProductContent', array('product' => $this->product)),
'HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category))

The CartController handles Adding products to the cart.  I'm not seeing any hooks that are executed for add/update, only for delete.  So you might have to create your own custom hook, or just override the function processChangeProductInCart in that controller.

 

As for the payment, you will need to be more specific.  Payment modules process payments, so you want a hook before the payment module is selected?


 

 

Link to comment
Share on other sites

Indeed its latest version.

 

So if I want to show latest stock information I need to be able to update the product (in case there is a change) while displaying the page. So I probably need to access it as earlly as possible (ideally right after the product is queried from database). I will probably need an override for that too?

 

Concerning payment, it should be done just before user confirms order. So its not connected with payment, my bad :)

 

Thank you.

Link to comment
Share on other sites

The CartController handles Adding products to the cart.  I'm not seeing any hooks that are executed for add/update, only for delete.  So you might have to create your own custom hook, or just override the function processChangeProductInCart in that controller.

There is a hook actionBeforeCartUpdateQty which triggers before a product is added or updated in cart.

Hook::exec('actionBeforeCartUpdateQty', array(
            'cart' => $this,
            'product' => $product,
            'id_product_attribute' => $id_product_attribute,
            'id_customization' => $id_customization,
            'quantity' => $quantity,
            'operator' => $operator,
            'id_address_delivery' => $id_address_delivery,
            'shop' => $shop,
            'auto_add_cart_rule' => $auto_add_cart_rule,
        ));
Edited by TheDrotX (see edit history)
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...