如何在类别页面上的 magento(使用帮助程序)中获取新安装的产品属性

How get new installed product attribute in magento (using helper) on category pages

我已经使用我的模块脚本安装了新的产品属性 - mysql4-install-1.0.0.php:

<?php
$installer = $this;
$installer->startSetup();
$setup = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');
//Setup Product Attribute
$setup->addAttribute('catalog_product', 'product_display_price', array(
'group'             => 'Prices',
'label'             => 'Webdevelop Extensions - Display Price',
'type'              => 'int',
'input'             => 'select',
'backend'           => '',
'frontend'          => '',
'source'            => 'eav/entity_attribute_source_boolean',
'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible'           => true,
'required'          => false,
'user_defined'      => false,
'searchable'        => false,
'filterable'        => false,
'comparable'        => false,
'visible_on_front'  => false,
'visible_in_advanced_search' => false,
'unique'            => false,
 ));
$installer->endSetup();

这个属性 ('product_display_price') 我可以在产品页面上使用(在我的重写块上使用 var_dump(getProductAttributeValueDisplayPrice())),但是当我在类别页面上使用它时,我得到 null。 我使用辅助文件 (Data.php):

public function getProductAttributeValueDisplayPrice()
{
    $currentProduct = Mage::registry('current_product');
    if ($currentProduct) {
        $product_id = $currentProduct->getId();
        $product = Mage::getModel('catalog/product')
            ->load($product_id);
        $attribute = $product->getData('product_display_price');
        return $attribute;
    }else null;
}

在我的帮助程序文件中 - Data.php 我添加了两个设置和获取产品的函数

protected $_currentProduct = '';

public function setCurrentProduct($label)
{
    $this->_currentProduct = $label;
    return $this;
}

public function getCurrentProduct()
{
    return $this->_currentProduct;
}

在我的块文件中我设置了产品

$helper->setCurrentProduct($this->getProduct());

然后我在我的辅助函数 getProductAttributeValueDisplayPrice() - $currentProduct = $this->getCurrentProduct();

public function getProductAttributeValueDisplayPrice()
{
    $currentProduct = $this->getCurrentProduct();
    if ($currentProduct) {
        $product_id = $currentProduct->getId();
        $product = Mage::getModel('catalog/product')
            ->load($product_id);
        $attribute = $product->getData('product_display_price');
        return $attribute;
    }else null;
}

一切正常。