Jump to content

How can I add stock for the prestasho api?


Recommended Posts

I understand that you can not add or modify stock from the api since in reference to stock the ws put and post are deactivated only allows me to head and get and tried from the ws

<?php 
define('DEBUG', false);
  define('_PS_DEBUG_SQL_', true);
  define('PS_SHOP_PATH', 'http://prueba.com/');
  define('PS_WS_AUTH_KEY', 'PDXSMLLRR9R51MP7G3HIZT41UMJBM91V');
  require_once ('./PSWebServiceLibrary.php');
  require ('./vendor/autoload.php');
  $webService = new PrestaShopWebservice('http://pruebafinal41.com/', 'xxxxxxxxxxxxxxxxxxxxx', true);
 // $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
 $xml = $webService->get(array('url' => 'http://pruebafin.com/' . 'api/stock_availables?schema=blank'));
  $resources = $xml->children()->children();
 // $resources->id;
  $resources->id_product=256;
  $resources->id_product_attribute=1;
  $resources->id_shop=1;
  $resources->id_shop_group=1;
  $resources->quantity=54;
  $resources->depends_on_stock=1;
  $resources->out_of_stock=2;
  try {
    $opt = array('resource' => 'stock_availables');
    $opt['putXml'] = $xml->asXML();
    $xml_request = $webService->edit($opt);
   // $xml_request = $webService->edit($opt);
  }catch(Exception $e){
    echo "<pre>";
print_r($e);
echo "</pre>";
  }

he answers me with a

PrestaShopWebserviceException Object
(
    [message:protected] => Bad parameters given

on the other hand if I want to use the stock movement ws to make a move

<?php
  define('DEBUG', false);
  define('_PS_DEBUG_SQL_', true);
  define('PS_SHOP_PATH', 'http://prueba.com/');
  define('PS_WS_AUTH_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxx');
  require_once ('./PSWebServiceLibrary.php');
  require ('./vendor/autoload.php');
  $webService = new PrestaShopWebservice('http://prueba.com/', 'xxxxxxxxxxxxxxxxxxxxxxxx', true);
  $date = getdate();
  $xml = $webService->get(array('url' => 'http://prueba.com/'.'api/stock_movements?schema=blank'));
  $resources = $xml->children()->children();
  $resources->id;
  $resources->id_product;
  $resources->id_product_attribute;
  $resources->id_warehouse;
  $resources->id_currency;
  $resources->management_type;
  $resources->id_employee=1;
  $resources->id_stock=258;
  $resources->id_stock_mvt_reason=11;
  $resources->id_order;
  $resources->id_supply_order;
  $node = dom_import_simplexml($resources->product_name->language[0][0]);
  $no = $node->ownerDocument;
  $node->appendChild($no->createCDATASection("cdata product name"));
  $resources->product_name->language[0][0] = "product name";
  $resources->product_name->language[0][0]['id'] = 1;
  $resources->product_name->language[0][0]['xlink:href'] = 'http://prueba.com/api/languages/1';
  $resources->ean13;
  $resources->upc;
  $resources->reference;
  $resources->physical_quantity=65;
  $resources->sign=1;
  $resources->last_wa=0.0000;
  $resources->current_wa=0.0000;
  $resources->price_te=0.0000;
  $resources->date_add = $date['year'] . '-' . $date['mon'] . '-' . $date['mday'] . ' ' . $date['hours'] . ':' . $date['minutes'] . ':' . $date['seconds'];

   try {
    $opt = array('resource' => 'stock_movements'); 
    $opt['postXml'] = $xml->asXML();
    $xml_request = $webService->add($opt);
   } 
   catch(Exception $e){
     echo "<pre>";
print_r($e);
echo "</pre>";
   }

but of course post is not supported by this ws then I can not add a movement to register it in the database my question is formulated in which ws use or how can I add by means of the stock api to the products so that it is done in a way automatic

thanks for your help

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