Magento $ _product-> getName empty

I want to export my own XML stream from Magento, and this is the following code that I use:

<?php
header('Content-Type: text/xml'); // XML a handy dandy format

include '../app/Mage.php'; // Include the magento core

include 'ArrayXml.php';

Mage::app(); //And start up the Magento app

$_result = array(); // Make sure we have a result array to store our products
$_products = Mage::getModel('catalog/product')->getCollection();

foreach($_products as $_product) {
$_result['produs'][] = array(
'denumire' => $_product->getName(),
'descriere_scurta' => $_product->getShortDescription(), //product short description
'descriere_lunga' => $_product->getDescription(), // product long description
'pret_intreg' => $_product->getPrice(), //product regular Price
'pret_redus' => $_product->getSpecialPrice(), //product special Price
'url_produs' => $_product->getProductUrl(), //product url
'fotografie_produs' => $_product->getImageUrl() //product image url
);
}
$_converter = new ArrayXML();
echo $_converter->toXML($_result);

However, only the product URL and image URL give me the correct values. The rest are empty.

What gives?

+3
source share
1 answer

'name' and others are attributes, so you should call addAttributeToSelect:

$_products = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect(array(
        'name',
        'short_description',
        'description'
    ))
    ->addPriceData();
+11
source

All Articles