Creating a new product will not generate product->id that you are passing in updateStock Method so that is why updateStock is working only for existing products.
I would suggest to check
$product = Mage::getModel('catalog/product');
$product->load(18); //18 is my existing product id
echo '<pre>';
print_r($product->getData());
exit;
This will give you idea about data associated to product.
Recently, I have created a method that is used to create product. Please review it.
public function createProduct($categories = array(3),$productName,$sku,$price=0,$productDescription,$productShortDescription,$status,$visibility,$attributeSet,$taxClass,$qty,$stock,$websites = array(1),$productImage='',$productMetaTitle,$productMetaKeyword,$productMetaDescription) {
$product = new Mage_Catalog_Model_Product();
// Build the product
$prod = array();
$prod['sku'] = $sku;
$prod['attribute_set_id'] = $attributeSet;
$prod['type_id'] = 'simple';
$prod['category_ids'] = $categories;
$prod['website_ids'] = $websites;
$prod['name'] = $productName;
$prod['description'] = $productDescription;
$prod['short_description'] = $productShortDescription;
$prod['weight'] = '1';
$prod['status'] = $status;
$prod['url_key'] = Mage::getModel('catalog/product_url')->formatUrlKey($productName);
$prod['url_path'] = Mage::getModel('catalog/product_url')->formatUrlKey($productName); //TO-DO :: find correct method
$prod['visibility'] = $visibility;
$prod['price'] = $price;
$prod['tax_class_id'] = $taxClass;
$prod['meta_title'] = $productMetaTitle;
$prod['meta_keyword'] = $productMetaKeyword;
$prod['meta_description'] = $productMetaDescription;
$product->setData($prod);
$product->setStockData(array(
'is_in_stock' => $stock,
'qty' => $qty,
'manage_stock' => 1
));
if($productImage) {
Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
$product->setMediaGallery (array('images'=>array (), 'values'=>array ()));
$product->addImageToMediaGallery($productImage,array('image','small_image','thumbnail'),false,false);
}
try {
$product->save();
return $product->getId();
}
catch (Exception $e){
echo $e->getMessage();
}
}
Hope above method helps you.
Also if you set manage stock from System->Configuration->Catalog->Inventory->Product Stock Options to Yes, then you don't need to pass manage_stock in above method. Product will be automatically created with manage stock set to yes.
You can use catalog_product_collection_load_before
event.
And in the observer:
public function modifyProductCollection(Varien_Event_Observer $observer) {
//catalog_product_collection_load_before
$collection = $observer->getCollection();
$collection->getSelect()->joinLeft(
array('_inventory_table' => $collection->getTable('cataloginventory/stock_item')),
"_inventory_table.product_id = e.entity_id",
array('is_in_stock')
)
->order('is_in_stock DESC')
->order('created_at DESC');
}
Note: Tested on 1.7.0.2, I guess it will work on 1.8, too.
Best Answer
I think it should work if you set 'Backorders' to 'Allow qty below 0' in the System Configuration like you did and make sure on the individual products the 'Stock Availability' value is set to 'In Stock'.