Jump to content

webservice stock field


Recommended Posts

Hi all,

 

i'm trying to post a new product with webservice but i don't know the reason every product i load has 0 stock. I tryed with fields: minimal_quantiy, and stock_availables without luck.

 

Could anyone tell me which is the field to indicate the stock of a product ?

 

Thank you in advance

 

Link to comment
Share on other sites

Hello ! I'm actually doing a websevice also, you're lucky, I found this problem  ^^

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) {
       set_product_quantity($ProductId, $item->id, $item->id_product_attribute);
    }
}

function set_product_quantity($ProductId, $StokId, $AttributeId){
    global $webService;
    $xml = $webService -> get(array('url' => 'http://YOUR_URL/api/stock_availables?schema=blank'));
    $resources = $xml -> children() -> children();
    $resources->id = $StokId;
    $resources->id_product  = $ProductId;
    $resources->quantity = 100;
    $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>';
    }
}

and juste in the end of your webservice, after adding the product :

getIdStockAvailableAndSet($ProductId);

:)

 

 

Actually i'm trying to add features, it's not an easy task too ;)

  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...