5

I am working on a connector module for a custom CMS system into Magento. I am using the following code to pull the products from a given category.

$category = Mage::getModel('catalog/category')->load($catID);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('name');
$collection->addAttributeToSelect('description');
$collection->addAttributeToSelect('image');
$products = $collection->getItems();

foreach ($products as $product) {...}

The problem is when I execute $product->getPrice() I get nothing back. Any help is appreciated.

1 Answer 1

6

you are selecting only these 3 attributes(name,description,image) then how do you expect price from the product collection. kindly add price attribute to your select.

    $collection->addAttributeToSelect('price'); 

and then use

     //returns price which is not a final one.
     $product->getPrice();
3
  • Duh, thanks. I suppose we can leave this for the next person who makes this same mistake. Commented Mar 28, 2013 at 3:03
  • @Nathan Bunney yes dude it would be helpful
    – Haijerome
    Commented Mar 28, 2013 at 3:09
  • 2
    If you need the final or minimal price, you can add those using addMinimalPrice and addFinalPrice on the collection, as is done by Mage_Catalog_Model_Layer::prepareProductCollection
    – davidalger
    Commented Mar 28, 2013 at 3:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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