3

I am using following code to get the stock detail I am getting product stock of productId 149428

$proxy = new SoapClient('http://yourstore.com/api/?wsdl');
$sessionId = $proxy->login('apiuser', 'apiKey');
$result = $proxy->call($sessionId, 'product_stock.list','149428');
var_dump($result);

Result:

array(1) { [0]=> array(4) { ["product_id"]=> string(6) "149428" ["sku"]=> string(13) "n12345" ["qty"]=> string(6) "1.0000" ["is_in_stock"]=> string(1) "1" } }

But I want to retrieve all products stock list instead of getting single product stock details.

I tried using the below method but I am not getting a result,

$result = $proxy->call($sessionId, 'product_stock.list');
var_dump($result);

Another:

$result = $client->call($session, 'cataloginventory_stock_item.list');
var_dump($result);

Thank you in advance.

  • What happens, if you try the other two? – Fabian Blechschmidt Oct 3 '16 at 6:33
  • it displays result as array(0) { } – Siraj M Oct 3 '16 at 6:50
  • @fabian is there any solutions for that please do help me – Siraj M Oct 3 '16 at 8:17
  • Reading the docs brings me to the assumption, that you have to implement your own API if you want "all", but you can pass an array with "all" ids, then you get all. You can read the code of the api response (don't ask me, what class handles that - no idea) and check, whether me/doc is wrong. – Fabian Blechschmidt Oct 3 '16 at 20:25
  • @Fabian I tried sending ids in array but it did not work. as its reading first id from array and skipping the rest all – Siraj M Oct 4 '16 at 3:45
0

You can use magento api version 2 for getting different product stocks in a single call. Try below code:

$proxy = new SoapClient('http://magento-local.com/api/v2_soap?wsdl'); //Means you are calling magento api V2
$sessionId = $proxy->login('test', 'test123'); // TODO : change login and pwd if necessary

//If you are passing product id
$stocks = $proxy->catalogInventoryStockItemList($sessionId, array (905, 880)); //905 and 880 are my simple product ids

//If you are passing product sku
$stocks = $proxy->catalogInventoryStockItemList($sessionId, array ('sku1', 'sku2'));

print_r($stocks);

$proxy->endSession($sessionId);

For more details refer: http://devdocs.magento.com/guides/m1x/api/soap/catalogInventory/cataloginventory_stock_item.list.html

0
 $products = $proxy->call($sessionId, 'product_stock.list', array(array("sku1","sku2","sku3"));

Yes, the nested arrays are necessary. In mine I also had to append a blank space at the end of each sku, so it is actually:

 $products = $proxy->call($sessionId, 'product_stock.list', array(array("sku1 ","sku2 ","sku3 "));

in my case. Not sure why, just thrilled when I got it to work.

I have about a thousand products, but it seems to overload the server to put them all in one call, so I'm "chunking" the sku array like so:

foreach (array_chunk($sku_array, 100) as $skuChunk) {

    try {
        $products = $proxy->call($sessionId, 'product_stock.list', array($skuChunk));
    }
    catch (SoapFault $e) {
            echo $e->getMessage();
    }    
}
0

You can use Below code for get all product stock list.

require_once('./app/Mage.php');
error_reporting(E_ALL);
ini_set('display_errors', 1);
umask(0);
Mage::app(); 
$productsCollection = Mage::getModel('catalog/product')->getCollection();
$skus = array();
foreach ($productsCollection as $product) {
    $skus[] = $product->getSku();

}              
$client = new SoapClient('http://yourhost.com/api/v2_soap/?wsdl=1');
$session = $client->login('apiUser', 'apiKey');
$result = $client->catalogInventoryStockItemList($session, $skus);
    echo "<pre>";
    print_r($result);
    echo "</pre>"; 
$client->endSession($session);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.