IeM Posted July 7, 2015 Share Posted July 7, 2015 Prestashop 1.6 Multi-Store with Advanced Stock Management Hi, Most through making a bridging app to update warehouse stock quantities to the shopping cart. ERP is not the answer in this situation as it is a 3rd parties stock that only makes up part of the cart stock. I have been able to do a number of integrations using the Prestashop 1.6 API, however, I can not work out how to increase physical stock levels, and have these new levels show up in the backend of the site. I have been able to increase the quantity level in the "stock_available" table but this does not show in the back end. I have not been able to work out how to chance the quantity in the product table because it is write protected so that is an issue to overcome somehow though beyond me. It also seems that there must be other values that need to be changed because if you change these two quantities directly in the DB they still do not show up in the back end. Also I would think that it would be a good idea to add the change in the advanced stock management as a warehouse as a stock movement. Now even though I have nearly 100 items, I only have 1 in the "stock" table. Whey would that be as it has "physical_quantity" and that may be another one that needs updating? 1/ What needs to be updated to increase a products stock level so that it will be recognised and show up in the back end? 2/ And how do you update the "products" "quantity" when it is write protected? Thanks Link to comment Share on other sites More sharing options...
mogarick Posted July 9, 2015 Share Posted July 9, 2015 Hi @IeM, I'm having the same problem plus one more: When I get the product XML data via <mypsshop.com>/api/products/<productID> I always get 0 for the quantity field even though in the BO I can see another value but zero. Have you find a solution for your problem or do you know why can my problem variant can be ocurring? Link to comment Share on other sites More sharing options...
IeM Posted July 9, 2015 Author Share Posted July 9, 2015 Hi Mogarick, Try the following and see if it helps: $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); $opt = array('resource' => 'stock_availables'); $opt['id'] = $id; $xml = $webService->get($opt); $resources = $xml->children()->children(); It is very hard to get information in regards to updating the stock via the API. 1 Link to comment Share on other sites More sharing options...
mogarick Posted July 9, 2015 Share Posted July 9, 2015 (edited) Thank you @IeM. I'm gonna try it out! In regard to de WS API, I've already suffered a previous disappointing when I tried to use it for Cart Rules. It only works for simple ones but if you want to create something more complex such as creating a discount for a category it is not supported via WS. I posted an issue in the PS issue tracker but never got any answer. I also complained about the heterogeneous way of enabling the different clases for WS but also got a mute response. So it appears WS API is definitely some kind of after though for PS dev team and those who dare to walk that path are on their own. That's pretty sad I think. Edited July 9, 2015 by mogarick (see edit history) Link to comment Share on other sites More sharing options...
IeM Posted July 13, 2015 Author Share Posted July 13, 2015 Hi Mogarick, Have you made any more progress? Link to comment Share on other sites More sharing options...
mogarick Posted July 13, 2015 Share Posted July 13, 2015 Hi IeM, I could solve my need with te help of your tip and using filter and display params. In my case I only needed to get the current stock quantity available. I didn't need to update it. The awkward thing is the fact that calling the products end point always have a 0 value for the quantity attribute but calling the stock_availables end point returns the correct quantity. This just enforces my last message, PS dev team implemented WS as an afterthough and they don't support it at the same level as the other components and features of PS and that's pretty sad. Link to comment Share on other sites More sharing options...
IeM Posted July 14, 2015 Author Share Posted July 14, 2015 Hi Mokarick, Glad you made advances. It seems strange to me how they have set it up but as I only have a superficial understanding of it, I can't really make a comment other than it is causing challenges in updating product quantities. Link to comment Share on other sites More sharing options...
M.Gigliotti Posted August 2, 2015 Share Posted August 2, 2015 Hi, someone have finally found proper way to update stock? Could you share final code ? tnx m. Link to comment Share on other sites More sharing options...
IeM Posted August 3, 2015 Author Share Posted August 3, 2015 No, still waiting. I have moved on to other more pressing projects ATM but will return to complete this. Stack Overflow would be worth trying as they are a lot more responsive there, even for Prestashop. If you get an answer, could you please post it here. Thanks Link to comment Share on other sites More sharing options...
Jonadabe Posted October 16, 2015 Share Posted October 16, 2015 Hi there, I'm very interested in this topic so I searched a litle bit deeper and found this: http://forge.prestashop.com/browse/PSCSX-5988 So please vote for this!!! Link to comment Share on other sites More sharing options...
Jonadabe Posted October 16, 2015 Share Posted October 16, 2015 (edited) Sorry, my mistake! Edited October 16, 2015 by Jonadabe (see edit history) Link to comment Share on other sites More sharing options...
Julein7201 Posted December 23, 2015 Share Posted December 23, 2015 UP please ! this is critical for us too. Link to comment Share on other sites More sharing options...
tplmika Posted February 20, 2016 Share Posted February 20, 2016 Greeting all, Im here to find this solutions too. I follow this thread development. Link to comment Share on other sites More sharing options...
Julein7201 Posted March 15, 2016 Share Posted March 15, 2016 UP PLEASE ! NEEED ! Link to comment Share on other sites More sharing options...
bcarron Posted December 12, 2016 Share Posted December 12, 2016 Still impossible to update quantities from the web service?? Link to comment Share on other sites More sharing options...
Tito Posted January 16, 2017 Share Posted January 16, 2017 I need this too... Still can't believe it's disabled Link to comment Share on other sites More sharing options...
anreig Posted June 12, 2017 Share Posted June 12, 2017 Any solution? Link to comment Share on other sites More sharing options...
veldepatrick Posted July 6, 2018 Share Posted July 6, 2018 Still nothing? Link to comment Share on other sites More sharing options...
fredericomarinho.com Posted July 25, 2018 Share Posted July 25, 2018 I could update the quantity available of the product. My Prestashop version is 1.6.1.17. First, you need to GET "stock_available" of the products. To find out the "stock_available" id: GET -> api/products/<product_id> My return as an example: == <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <product> <id><![CDATA[27]]></id> <id_manufacturer><![CDATA[0]]></id_manufacturer> <id_supplier><![CDATA[0]]></id_supplier> <id_category_default><![CDATA[0]]></id_category_default> <new></new> <cache_default_attribute><![CDATA[0]]></cache_default_attribute> <id_default_image notFilterable="true"></id_default_image> <id_default_combination notFilterable="true"></id_default_combination> <id_tax_rules_group><![CDATA[0]]></id_tax_rules_group> <position_in_category notFilterable="true"></position_in_category> <manufacturer_name notFilterable="true"></manufacturer_name> <quantity notFilterable="true"><![CDATA[0]]></quantity> <type notFilterable="true"><![CDATA[simple]]></type> <id_shop_default><![CDATA[1]]></id_shop_default> <reference><![CDATA[422]]></reference> <supplier_reference></supplier_reference> <location></location> <width><![CDATA[1010.000000]]></width> <height><![CDATA[2020.000000]]></height> <depth><![CDATA[3030.000000]]></depth> <weight><![CDATA[11.000000]]></weight> <quantity_discount><![CDATA[0]]></quantity_discount> <ean13></ean13> <upc></upc> <cache_is_pack><![CDATA[0]]></cache_is_pack> <cache_has_attachments><![CDATA[0]]></cache_has_attachments> <is_virtual><![CDATA[0]]></is_virtual> <on_sale><![CDATA[0]]></on_sale> <online_only><![CDATA[0]]></online_only> <ecotax><![CDATA[0.000000]]></ecotax> <minimal_quantity><![CDATA[0]]></minimal_quantity> <price><![CDATA[69.900000]]></price> <wholesale_price><![CDATA[0.000000]]></wholesale_price> <unity></unity> <unit_price_ratio><![CDATA[0.000000]]></unit_price_ratio> <additional_shipping_cost><![CDATA[0.00]]></additional_shipping_cost> <customizable><![CDATA[0]]></customizable> <text_fields><![CDATA[0]]></text_fields> <uploadable_files><![CDATA[0]]></uploadable_files> <active><![CDATA[1]]></active> <redirect_type></redirect_type> <id_product_redirected><![CDATA[0]]></id_product_redirected> <available_for_order><![CDATA[0]]></available_for_order> <available_date><![CDATA[0000-00-00]]></available_date> <condition><![CDATA[new]]></condition> <show_price><![CDATA[0]]></show_price> <indexed><![CDATA[1]]></indexed> <visibility><![CDATA[both]]></visibility> <advanced_stock_management><![CDATA[0]]></advanced_stock_management> <date_add><![CDATA[2018-07-25 16:26:34]]></date_add> <date_upd><![CDATA[2018-07-25 16:26:34]]></date_upd> <pack_stock_type><![CDATA[0]]></pack_stock_type> <meta_description><language id="1" xlink:href="http://localhost/presta-dunkshoes/api/languages/1"><![CDATA[]]></language></meta_description> <meta_keywords><language id="1" xlink:href="http://localhost/presta-dunkshoes/api/languages/1"><![CDATA[]]></language></meta_keywords> <meta_title><language id="1" xlink:href="http://localhost/presta-dunkshoes/api/languages/1"><![CDATA[]]></language></meta_title> <link_rewrite><language id="1" xlink:href="http://localhost/presta-dunkshoes/api/languages/1"><![CDATA[tenis-de-teste-api-rest2]]></language></link_rewrite> <name><language id="1" xlink:href="http://localhost/presta-dunkshoes/api/languages/1"><![CDATA[Tenis de Teste API Rest2]]></language></name> <description><language id="1" xlink:href="http://localhost/presta-dunkshoes/api/languages/1"><![CDATA[]]></language></description> <description_short><language id="1" xlink:href="http://localhost/presta-dunkshoes/api/languages/1"><![CDATA[Tenis de Teste Descrição Curta]]></language></description_short> <available_now><language id="1" xlink:href="http://localhost/presta-dunkshoes/api/languages/1"><![CDATA[]]></language></available_now> <available_later><language id="1" xlink:href="http://localhost/presta-dunkshoes/api/languages/1"><![CDATA[]]></language></available_later> <associations> <categories nodeType="category" api="categories"> <category xlink:href="http://localhost/presta-dunkshoes/api/categories/2"> <id><![CDATA[2]]></id> </category> <category xlink:href="http://localhost/presta-dunkshoes/api/categories/13"> <id><![CDATA[13]]></id> </category> </categories> <images nodeType="image" api="images"/> <combinations nodeType="combination" api="combinations"/> <product_option_values nodeType="product_option_value" api="product_option_values"/> <product_features nodeType="product_feature" api="product_features"/> <tags nodeType="tag" api="tags"/> <stock_availables nodeType="stock_available" api="stock_availables"> <stock_available xlink:href="http://localhost/presta-dunkshoes/api/stock_availables/285"> <id><![CDATA[285]]></id> <id_product_attribute><![CDATA[0]]></id_product_attribute> </stock_available> </stock_availables> <accessories nodeType="product" api="products"/> <product_bundle nodeType="product" api="products"/> </associations> </product> </prestashop> == The "stock_aavailables" id to this product is 285. Than, use GET in the url "api/stock_availables/285". Below my result as an example: == <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <stock_available> <id>285</id> <id_product>27</id_product> <id_product_attribute>0</id_product_attribute> <id_shop>1</id_shop> <id_shop_group>0</id_shop_group> <quantity>17</quantity> <depends_on_stock>0</depends_on_stock> <out_of_stock>2</out_of_stock> </stock_available> </prestashop> == Copy this result and change the value in <quantity> branch. Then use this same code in PUT method. For me worked well! I hope it can be useful. 1 Link to comment Share on other sites More sharing options...
peskywinnets Posted December 11, 2018 Share Posted December 11, 2018 On 7/25/2018 at 8:38 PM, divera said: Copy this result and change the value in <quantity> branch. Then use this same code in PUT method. Could you please post your code for the PUT method? Link to comment Share on other sites More sharing options...
becici Posted July 6, 2019 Share Posted July 6, 2019 This is mine, it works PUT ...../api/stock_availables/ <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <stock_available> <id>64</id> <id_product>25</id_product> <id_product_attribute>0</id_product_attribute> <id_shop>1</id_shop> <id_shop_group>0</id_shop_group> <quantity>2400</quantity> <depends_on_stock>0</depends_on_stock> <out_of_stock>2</out_of_stock> <location></location> </stock_available> </prestashop> Link to comment Share on other sites More sharing options...
Anonymous No.2 Posted July 7, 2019 Share Posted July 7, 2019 (edited) It looks like I cannot create a new record in the stock_availables via API when it does not exist, I am getting an error <error> <code><![CDATA[101]]></code> <message><![CDATA[Method POST is not allowed for the resource stock_availables]]></message> </error> when my product looks like this <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <product> <id><![CDATA[79]]></id> ... <stock_availables nodeType="stock_available" api="stock_availables"/> <accessories nodeType="product" api="products"/> <product_bundle nodeType="product" api="products"/> </associations> </product> </prestashop> I believe associations between product and stock_availables dissapeared after I added this line while updating products $clientXml->children()[0]->associations->categories->category[0]->id=$idCategory; because products without associated categories did not appear in the shop. Now products do appear in the shop, but I cannot update the qty in stock anymore . I noticed I also have 59 orphan records in the ps_stock_available table for not existing products. SQL I used to find orphans: SELECT pa.* FROM `ps_stock_available` pa WHERE not exists (select p.id_product from ps_product p where p.id_product=pa.id_product) Any ideas how to fix it? PS version 1.7.5.2 Well, my problem was id_shop_group was set to 1 in my code, not specifying the category. Sorry. Edited July 7, 2019 by Anonymous No.2 problem solved (see edit history) Link to comment Share on other sites More sharing options...
t-prod Posted March 30, 2020 Share Posted March 30, 2020 Hi, Do you have an idea to update stocks for combinations too ? In stock availables I have only id_product_attribute = 0. However products have a lot of combinations Maybe someone has a idea ? I've tried to update 'resource' => 'combinations' quantity but it doesn't work at all. Prestashop version is 1.7.4.2 Thanks Link to comment Share on other sites More sharing options...
t-prod Posted March 30, 2020 Share Posted March 30, 2020 Any ideas ? Link to comment Share on other sites More sharing options...
AndreRodrigues Posted February 4, 2021 Share Posted February 4, 2021 On 3/30/2020 at 3:34 PM, t-prod said: Any ideas ? You got it? If not, the "id_product_attribute" is the relation with the combination ID. If you have a product with 2 combinations, you will have 2 entrys in stock_availables, each combination with the stock_available_id. 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