Magento – Difference betweet Mage::getModel(‘catalog/product’)->load(1) and $collection->getFirstItem();

magento-1.8

I have to load some products… The (my) traditional way to load a product is:

Mage::getModel('catalog/product')->load($id);

Now I have the problem, that some products can be loaded by this way – but some not.

I'm sure, there is no difference between those products… Simple, enabled, Catalag/Search, on Stock…

So – this doesn't work:

    $productId = '133110';
    $product = Mage::getModel('catalog/product')
        ->load($productId);
    $price = $product->getPrice();

But this works:

    $productId = '133110';
    $product = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToFilter('entity_id', $productId)
        ->addAttributeToSelect('price')
        ->getFirstItem();
    $price = $product->getPrice(); 

Why???

Best Answer

Your question contains answer. In table catalog_product_entity there is no field with price for a product. So, you can't use method get price. When you get a collection, you link catalog_product_entity with catalog_product_entity_decimal, from where it takes attribute for price. By the way, this collection will take only price for the first store, so you should add store to filter (by addStoreFilter()) if you use multiple stores. The other way - you can make your first code work, if you use flat tables for products. In this case you will use catalog_product_flat table, there field price is already included.