Jump to content

como puedo agregar stock por la api de prestasho ?


fred1roca

Recommended Posts

tengo entendido que no se puede agregar o modificar stock desde las api ya que en referente a stock los ws put y post están desactivados  solo me permite head  y get   e intentado desde el 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>";
  }

me responde con un 

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

 

por otro lado si quiero usar el   ws de stock movements para hacer un movimiento 

<?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>";
   }

pero claro que post no esta soportado  por este ws entonces no puedo agregar un movimiento para registrarlo en la base de datos  mi pregunta se formula en que ws uso o como puedo agregar por medio de la api stock a los productos para que se  haga de manera automática 

gracias por su ayuda

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