Magento $_product->getName 为空

标签 magento product

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

<?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 给了我正确的值。其余的都是空的。

什么给出了?

最佳答案

'name' 和其他都是属性,因此您应该调用 addAttributeToSelect:

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

关于Magento $_product->getName 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10588616/

相关文章:

php - 在 Magento 中为产品设置特价日期

php - 以干净的方式正确覆盖 WooCommerce 函数 WC_Price()

rest - Magento 2 REST API 获取所有产品

magento - 获取产品的父类别,即使它是直接访问的

redirect - OnePage Checkout 上的 Magento 奇怪的重定向行为

php - 禁用 Magento "manage products"区域中产品 &lt;input&gt; 字段的编辑?

php - 从 Woocommerce 中的产品页面库存显示中删除 "can be backordered"

php - 无法在自定义模块的 layout.xml 中添加 css

image - Magento 未在某些商店的缓存中生成图像

php - 也获取适用于 Woocommerce 产品变体的 is_purchasable Hook