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