I have products loaded in Magento that I am trying to bulk update the inventory qty on. I created all the products using Mage_Catalog_Model_Product and set the qty on them using setStockData like:
$product = new Mage_Catalog_Model_Product();
$product->setTypeId('simple');
$product->setStatus(1);
$product->setSku($sku);
$product->setStockData(array(
'is_in_stock' => 1,
'qty' => $record['stockstatus'],
'manage_stock' => 0,
));
...
So I've seen setStockData work ... 13,000+ times.
Now, as I said, I'm trying to update the inventory on the products I created using a variation on what I did to create the products ... a variation that I see here and virtually identically elsewhere on the web.
My problem is that I can use a variation of the code at the link above and get a valid product object, but when I call getStockData on the object, it returns NULL:
$product = Mage::getModel('catalog/product')
->loadByAttribute('product_code', '678910');
var_dump($product->getName()); // returns 'Hello My Name is Product'
var_dump($product->getProductCode()); // returns '678910'
var_dump($product->getSku()); // returns 'SKU1234'
var_dump($product->getStockData()); // returns NULL (and there is a qty of 52 set)
(I've also tried getting the product with no variations on the code at the link above and have had the same results as I expected.)
$product_id = Mage::getModel('catalog/product')->getIdBySku('SKU1234');
$product = Mage::getModel('catalog/product');
$product->load($product_id);
$stockData = $product->getStockData();
var_dump($product->getName()); // returns 'Hello My Name is Product'
var_dump($product->getProductCode()); // returns '678910'
var_dump($product->getSku()); // returns 'SKU1234'
var_dump($product->getStockData()); // returns NULL (and there is a qty of 52 set)
So, if I can't get the stock data with getStockData, I can't set the stock data like:
$product = Mage::getModel('catalog/product')
->loadByAttribute('product_code', $record['productcode']);
$stockData = $product->getStockData();
$stockData['qty'] = $record['stockstatus'];
$stockData['is_in_stock'] = ($record['stockstatus'] > 0) ? 1 : 0;
$product->setStockData($stockData);
$product->save();
Is there something I'm missing? I don't understand why getStockData is returning NULL. Can someone help me understand what I may be doing wrong?