Magento Forum

Problem with fetching product price and image
 
sparrovv
Jr. Member
 
Total Posts:  5
Joined:  2008-07-24
 

Hi,

I’m writing custom module for magento and I’ve problem with fetching Product price and image.
My code:

public function indexAction()
    
{
        $this
->loadLayout(false);
        
$storeId Mage_Catalog_Model_Category::DEFAULT_STORE_ID;
        
$collection Mage::getModel('catalog/product')->getCollection()
            ->
setStoreId($storeId)
            ->
addAttributeToSelect('name');        
        
$result = array();

        foreach (
$collection as $product{
            
//Zend_Debug::dump($product);
            
$result[] = array( // Basic product data
                
'product_id' => $product->getId(),
                
'sku'        => $product->getSku(),
                
'name'       => $product->getName(),
                
'category_id'=> $product->getCategoryIds(),
                
'set'        => $product->getAttributeSetId(),
                
'type'       => $product->getTypeId(),
                
'price'        => $product->getPrice(),
                
'url'       => $product->getProductUrl(),
            
'image'        => (string)Mage::helper('catalog/image')->init($product'image')
            );
        
}    
        
foreach($result as $row){
            Zend_Debug
::dump($row);        
            
}
            
echo "<br />";
        
}
}
Output:, (only one row):

array(9) {
["product_id"] => string(2) “13”
["sku"] => string(10) “F3SG-AP202”
["name"] => string(55) “ASUS F3SG-AP202 T2390/15.4/250GB/2GB/GF9300M/BT/GRATISY”
["category_id"] => array(1) {
[0] => string(2) “14”
}
["set"] => string(2) “27”
["type"] => string(6) “simple”
["price"] => NULL
["url"] => string(90) “http://somedomain.com/asus-f3sg-ap202-t2390-15-4-250gb-2gb-gf9300m-bt-gratisy.html”
["image"] => string(143) “http://somedomain.com/media/catalog/product/cache/1/image/5e06319eda06f020e43594a9c230972d/images/catalog/product/placeholder/image.jpg”
}

The question is, Why the getPrice() method doesn’t work, and Mage::helper(’catalog/image’)->init($product, ‘image’) is fetching default magento image?

Thanks in advance!

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