gpt4 book ai didi

Magento $_product->getName 为空

转载 作者:行者123 更新时间:2023-12-02 13:58:42 25 4
gpt4 key购买 nike

我想从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com