Jump to content

[SOLVED] How to programmatically set product stock in PS 1.5 Multistore?


tuvika

Recommended Posts

NOTE: PS 1.5.6.2

 

I'm going to try to sum up my spanish post version, because I'm not getting hints at all.

 

I'm writing a PS module to sync my PS store with an external product catalog using a webservice. It was originaly designed to work in the vanilla single store installation, but the project finally needs to turn in a multistore shop.

 

In the single store version the module just works fine using this class::function to manage stocks:

 

StockAvailable::setQuantity(Tools::getValue((int)$producto->id), '', Tools::getValue(10000));

 

But when I try to use the same script on a multistore PS, I get a PHP Fatal Error message, but no further description about what produced the fail (lines of module php code or whatever and I'm using a try - catch sentence with an error handler set that worked fine during the rest of development).

 

Looking in the PS source code for some kind of solution, I saw that the previous setQuantity function was accepting a fourth parameter which is used to identify the store that will receive the stock quantity update:

 

StockAvailable::setQuantity(Tools::getValue((int)$producto->id), '', Tools::getValue(10000), (int)Configuration::get('PS_SHOP_DEFAULT'));

 

But this solution neither works :(

 

I'm not sure if we're running out of possibilities to make it work properly in the PS way and I should use some SQL queries to insert/update the stock quantities, anyway I'm not sure what tables I should update in a multistore flavour PS to get it working.

 

Sorry for the "brick" :)

 

Regards!

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

  • 3 weeks later...

Finally I found a solution for this case, as We're working with a multistore PS >=1.5 I wasn't using the shop context in a proper way, and the code linea for modifying stock quantities wasn't correct.


 


Furthermore I needed a new selectbox on my module config to add the possibilite to add products and stocks quantities to a specific shop chosen by the user.


 


Before We can add products and stock quantities, We need to set up the correct shop context:


 


Shop::setContext(Shop::CONTEXT_SHOP, $this->tiendaps);


 


And the fix on the stock setquantity line, is like follows:


 


StockAvailable::setQuantity((int)$producto->id, null, 10000, (int)$this->tiendaps);


 


Regards!  :D


Link to comment
Share on other sites

  • 1 year later...

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