2016-09-20 79 views
0

我已经安装了新的产品属性在Magento(使用帮助)新安装的产品属性 - mysql4安装-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())),但是当我将它放在类别页面上时,我会得到空值。 我使用的辅助文件(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; 
} 

回答

0

在我的帮助文件 - Data.php我添加了两个功能,设置和获取产品

protected $_currentProduct = ''; 

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

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

在我集产品

我的块文件
$helper->setCurrentProduct($this->getProduct()); 

而且我在帮助函数中使用了chenge 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; 
} 

一切工作正常。