2016-09-20 80 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; 
} 

一切工作正常。