miaoumix Posted March 3, 2013 Share Posted March 3, 2013 (edited) Hi all, I'm relatively new to prestashop and tried to deal with webservices. At the moment, I can create categories, products and other stuff through webservices. But I'm stuck to setting product quantity. It seams I need to deal with the stock_availables webservice, but it always refuses to update the quantity I set. What I did till now was : Create product, and get the stock_availables id use a stock_availables resource, set quantity, and (try to) modify it through webservice. <= this doesn't work. Would someone know how to do this ? Thanks in advance, Jim Edited March 3, 2013 by miaoumix (see edit history) 1 Link to comment Share on other sites More sharing options...
omar.bobo Posted April 14, 2013 Share Posted April 14, 2013 I have the same problem, the product quantity is always set to 0. Link to comment Share on other sites More sharing options...
enovo Posted August 13, 2013 Share Posted August 13, 2013 (edited) To set the amount of the product must be done separately 1) Get the field id and attribute_id from prefix_stock_available table for the product and an id for each combination. 2) After get the attribute_id go and have to change their values I copy two functions for this task and called after creating the product After add product: getIdStockAvailableAndSet($xml->product->id); function set_product_quantity($ProductId, $StokId, $AttributeId){ global $webService; $xml = $webService -> get(array('url' => PS_SHOP_PATH . '/api/stock_availables?schema=blank')); $resources = $xml -> children() -> children(); $resources->id = $StokId; $resources->id_product = $ProductId; $resources->quantity = 10000000; $resources->id_shop = 1; $resources->out_of_stock=1; $resources->depends_on_stock = 0; $resources->id_product_attribute=$AttributeId; try { $opt = array('resource' => 'stock_availables'); $opt['putXml'] = $xml->asXML(); $opt['id'] = $StokId ; $xml = $webService->edit($opt); }catch (PrestaShopWebserviceException $ex) { echo "<b>Error al setear la cantidad ->Error : </b>".$ex->getMessage().'<br>'; } } function getIdStockAvailableAndSet($ProductId){ global $webService; $opt['resource'] = 'products'; $opt['id'] = $ProductId; $xml = $webService->get($opt); foreach ($xml->product->associations->stock_availables->stock_available as $item) { //echo "ID: ".$item->id."<br>"; //echo "Id Attribute: ".$item->id_product_attribute."<br>"; set_product_quantity($ProductId, $item->id, $item->id_product_attribute); } } Edited August 13, 2013 by enovo (see edit history) 3 Link to comment Share on other sites More sharing options...
ElMarley Posted April 15, 2014 Share Posted April 15, 2014 Hi thank you , for all what you did , but how can i do it , just after creation a product how can i get the ID product just created ?? Thank you . Link to comment Share on other sites More sharing options...
enovo Posted May 15, 2014 Share Posted May 15, 2014 $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); $opt = array('resource' => 'products'); $opt['postXml'] = $xml -> asXML(); $xml = $webService -> add($opt); $ProductId = $xml->product->id; 1 Link to comment Share on other sites More sharing options...
prstshp_joe Posted July 24, 2015 Share Posted July 24, 2015 Make sure that you set "depends_on_stock = 0", else you'll get error 500 (Unable to save resource). For some reason my mail alerts are not triggered when updating stock with WevService. Anyone has a clue why? Thank you! Link to comment Share on other sites More sharing options...
M.Gigliotti Posted July 28, 2015 Share Posted July 28, 2015 Hi all, i've tried to use the code above to set quantity of my product but without success.. What i've wrongly managed ? <?php define('DEBUG', true); define('_PS_DEBUG_SQL_', true); define('PS_SHOP_PATH', 'http://ZZZZZZZ.ZZZ'); // Root path of your PrestaShop store define('PS_WS_AUTH_KEY', 'ZZZZZZZZZZZZZZZZZZZZZZZZ'); // Auth key (Get it in your Back Office) require_once('./PSWebServiceLibrary.php'); getIdStockAvailableAndSet(1); function set_product_quantity($ProductId, $StokId, $AttributeId){ global $webService; $xml = $webService -> get(array('url' => PS_SHOP_PATH . '/api/stock_availables?schema=blank')); $resources = $xml -> children() -> children(); $resources->id = $StokId; $resources->id_product = $ProductId; $resources->quantity = 10000000; $resources->id_shop = 1; $resources->out_of_stock=1; $resources->depends_on_stock = 0; $resources->id_product_attribute=$AttributeId; try { $opt = array('resource' => 'stock_availables'); $opt['putXml'] = $xml->asXML(); $opt['id'] = $StokId ; $xml = $webService->edit($opt); }catch (PrestaShopWebserviceException $ex) { echo "<b>Error al setear la cantidad ->Error : </b>".$ex->getMessage().'<br>'; } } function getIdStockAvailableAndSet($ProductId){ global $webService; $opt['resource'] = 'products'; $opt['id'] = $ProductId; $xml = $webService->get($opt); foreach ($xml->product->associations->stock_availables->stock_available as $item) { //echo "ID: ".$item->id."<br>"; //echo "Id Attribute: ".$item->id_product_attribute."<br>"; set_product_quantity($ProductId, $item->id, $item->id_product_attribute); } } ?> 1 Link to comment Share on other sites More sharing options...
M.Gigliotti Posted July 28, 2015 Share Posted July 28, 2015 Errors: " Fatal error: Call to a member function get() on a non-object in /XXXXX/WS-Update-Quantity.php on line 35" Link to comment Share on other sites More sharing options...
Alfonso17 Posted April 14, 2016 Share Posted April 14, 2016 Errors: " Fatal error: Call to a member function get() on a non-object in /XXXXX/WS-Update-Quantity.php on line 35" Did you find solution? I cant update stock... Link to comment Share on other sites More sharing options...
tarek.fellah Posted July 2, 2016 Share Posted July 2, 2016 Did you find solution? I cant update stock... For anyone who met this problem you should declare the webservice variable $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); Link to comment Share on other sites More sharing options...
carolinalour Posted September 13, 2016 Share Posted September 13, 2016 Hi, Can you give me an example of the variable $xml such that the following line from your code can be executed?: $opt['putXml'] = $xml->asXML(); Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now