Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Stock item for Product is not valid
 
WeaZeLb0y
Jr. Member
 
Total Posts:  2
Joined:  2008-08-02
 

I just created a bunch of products in Magento via the API. When I view the product everything is fine. When I click add to cart I get the following error “* Stock item for Product is not valid”.

Any idea what this means?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
clickcomkyle
Jr. Member
 
Total Posts:  28
Joined:  2008-08-07
 

I have the same problem.. Anyone know how to resolve this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
captainmish
Jr. Member
 
Total Posts:  6
Joined:  2008-09-25
 

Figured this one out smile Its because there is no default stock level on a newly api-created product. To fix, you need a list of all the SKUs or product_ids, then for each one call product_stock.update

So:
$proxy->call($sessionId, ‘product_stock.update’, array(’Sku’, array(’qty’=>0, ‘is_in_stock’=>1)));
or
mgproxy.call(mgsid, ‘product_stock.update’, [product_id, {’qty’:0, ‘is_in_stock’:1}]) for python

I have set the stock to 0 because I have set ‘Manage Stock’ = False in the admin gui, the script will need to fetch stock levels for each sku/product id if you manage stock with magento.

It would be great if the update method could accept an array of product ids instead of having to iterate through each one!

 
Magento Community Magento Community
Magento Community
Magento Community
 
orchdork10159
Jr. Member
 
Total Posts:  1
Joined:  2010-03-10
 

You can do multiple SKUs at a time.

$client = new SoapClient('http://magentohost/api/soap/?wsdl');
$sid $client->login('apiUser''apiKey');
 
print_r(
    
$client->call(
        
$sid,
        'product_stock.list',
        array(
            array( 
// Notice the nested array
                
'sku1',
                
'sku2',
                
'sku3',
                ...
                
'skuN'
            
)
        )
    )
);
 
Magento Community Magento Community
Magento Community
Magento Community
 
zschuessler
Jr. Member
 
Avatar
Total Posts:  4
Joined:  2011-03-16
Columbia, Missouri
 

Magento is looking for stock data that isn\’t there. Even if you have disabled handling stock.

If you want to update all of your products quickly, I have a script up on my blog that will do it for you using the Magento API:

Solve stock item for product is not valid

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rodcos
Jr. Member
 
Avatar
Total Posts:  7
Joined:  2009-12-19
 

I tryed to run this via Magento API, without sucess. Can someone tell me what’s wrong with the following code?

<?php
$mage_url 
'http://*****/api/?wsdl'
$mage_user '*****'
$mage_api_key '*****'

// Initialize the SOAP client 
$soap = new SoapClient$mage_url ); 

// Login to Magento 
$session_id $soap->login$mage_user$mage_api_key );

// Set store defaults for Magento
$storeId Mage::app()->getStore()->getId();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$pModel Mage::getModel('catalog/product');

$products $pModel->getCollection();

foreach (
$products as $product{
    $stockData 
$product->getStockData();

    if (!
$stockData{
        $product 
$product->load($product->getId());
        
$stockData = array(
            
'manage_stock' => 1,
            
'is_in_stock'  => 1,
            
'qty'          => 1
        
);
        
$product->setStockData($stockData);

        try 
{
            $product
->save();
        
catch (Exception $e{
            
echo $e->getMessage();
        
}
    }
}

?>

By the way I’m using version 1.6.2.0

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rodcos
Jr. Member
 
Avatar
Total Posts:  7
Joined:  2009-12-19
 

Another question: is it possible to solve this directly via phpMyAdmin?

 
Magento Community Magento Community
Magento Community
Magento Community
 
esolutions
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2009-02-12
California
 

One thing i ran into when loading a product by SKU and trying to add it to the cart is the “The stock item for Product is not valid” exception.  I found this solution over here.  It references the enterprise version but it still works.  Here is the quote:

One thing I just ran into on Enterprise v 1.9.0, if you do the following:

$newProd = Mage::getModel(‘catalog/product’)->loadByAttribute(‘sku’, $sku);
$cart->addProduct($newProd);

The category inventory observe throws the following exception:
Mage::throwException(Mage::helper(‘cataloginventory’)->__(‘The stock item for Product is not valid.’));

The stock item object it gets from the product object is a basic Varien Object.

When I do the following, it behaves nicely:
$newProd = Mage::getModel(‘catalog/product’);
$newProd->load($newProd->getIdBySku($sku));
$cart->addProduct($newProd);

Of course, I also check $newProd->isSalable() prior to adding to the cart. Not sure exactly why it’s not loading up the proper object, hopefully this helps someone else running into this!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rodcos
Jr. Member
 
Avatar
Total Posts:  7
Joined:  2009-12-19
 
esolutions - 30 January 2012 12:21 PM

One thing i ran into when loading a product by SKU and trying to add it to the cart is the “The stock item for Product is not valid” exception.  I found this solution over here.  It references the enterprise version but it still works.  Here is the quote:

One thing I just ran into on Enterprise v 1.9.0, if you do the following:

$newProd = Mage::getModel(‘catalog/product’)->loadByAttribute(‘sku’, $sku);
$cart->addProduct($newProd);

The category inventory observe throws the following exception:
Mage::throwException(Mage::helper(‘cataloginventory’)->__(‘The stock item for Product is not valid.’));

The stock item object it gets from the product object is a basic Varien Object.

When I do the following, it behaves nicely:
$newProd = Mage::getModel(‘catalog/product’);
$newProd->load($newProd->getIdBySku($sku));
$cart->addProduct($newProd);

Of course, I also check $newProd->isSalable() prior to adding to the cart. Not sure exactly why it’s not loading up the proper object, hopefully this helps someone else running into this!

Thanks for sharing, esolutions, but I’m not a professional developer. Can you please tell me exactly what should I do with this code?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top