getData不起作用,返回空

Mat*_*ijo 1 magento

我创建了自定义属性,但是当我用我的方法显示它时它不起作用!

看是做...创建我的属性..

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$config = array(
    'position' => 1,
    'required'=> 0,
    'label' => 'Height',
    'type' => 'int',
    'input' => 'text',
    'apply_to' => 'simple,bundle,grouped,configurable'
);

$setup->addAttribute('catalog_product', 'height' , $config);
Run Code Online (Sandbox Code Playgroud)

我收到结帐中的物品清单......

$items = Mage::getModel('checkout/cart')->getQuote()->getAllVisibleItems();

foreach($items as $item){

    echo $item->getSku() .'<br/>'; //just test... and all right!

    echo $item->getHeight() .'<br/>'; //return empty! or....
    echo $item->getData('height') .'<br/>';//return empty!
}
Run Code Online (Sandbox Code Playgroud)

我在后端设置此属性的fiels中的值.

谢谢你的帮助!

Nic*_*ick 6

默认情况下,您的属性可能未加载.如果不修复添加height到集合addAttributeToSelect()声明的根本问题,作弊就是再次加载产品模型:

$product = Mage::getModel('catalog/product')->load($item->getProduct()->getId());
echo $product->getHeight();
Run Code Online (Sandbox Code Playgroud)

但这并不能解决问题的根源,而是会触发其他数据库查询.

几个月前我问了一个类似的问题,关于加载包含更多信息的其他数据,尽管与单个模型相关的集合加载更多:从已经加载的Magento模型中检索其他数据.