Magento $ _product-> getName为空 [英] Magento $_product->getName empty

查看:32
本文介绍了Magento $ _product-> getName为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Magento导出自定义XML提要,这是我使用的以下代码:

I want to export a custom XML feed from Magento, and this is the following code I use:

<?php
header('Content-Type: text/xml'); // XML's 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's short description
'descriere_lunga' => $_product->getDescription(), // product's long description
'pret_intreg' => $_product->getPrice(), //product's regular Price
'pret_redus' => $_product->getSpecialPrice(), //product's special Price
'url_produs' => $_product->getProductUrl(), //product url
'fotografie_produs' => $_product->getImageUrl() //product's image url
);
}
$_converter = new ArrayXML();
echo $_converter->toXML($_result);

但是,只有产品URL和图像URL给我正确的值.其余都是空的.

However, only the Product URL and the Image URL are giving me correct values. The rest are empty.

有什么作用?

推荐答案

'name'和其他属性,因此应调用 addAttributeToSelect :

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

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

这篇关于Magento $ _product-&gt; getName为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆