2012-12-04 142 views
0

嗨,我創建了一個多選產品屬性與setup.php並創建。我用下面的代碼:我的自定義屬性不顯示在產品集合Magento

$installer = $this; 
$installer->startSetup(); 
$installer->addAttribute('catalog_product', 'author_name',array( 
'label' => 'Name of The Author', 
'type' => 'varchar', 
'input' => 'multiselect', 
'backend' => 'eav/entity_attribute_backend_array', 
'frontend' => '', 
'source' => '', 
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 
'visible' => true, 
'required' => false, 
'user_defined' => false, 
'searchable' => false, 
'filterable' => false, 
'comparable' => false, 
'option' => array ('value' => array('optionone' => array('Carolyne Aarsen'), 
            'optiontwo' => array('Jennie Lucas'), 
            'optionthree' => array('Anna Adams'), 
            'optionfour' => array('Kathryn Albright'), 
            'optionfive' => array('Trisha Alexander'), 
            'optionsix' => array('Vincent Alexandria'), 
            'optionseven' => array('Louise Allen'), 
            'optioneight' => array('Abby Green'), 
            'optionnine' => array('Laura Abbot'), 
            'optionten' => array('Caroline Anderson'), 
            'optioneleven' => array('Victoria Aldridge'), 
            'optiontwelve' => array('Harper Allen'), 
            ) 
       ), 
'visible_on_front' => false, 
'visible_in_advanced_search' => false, 
'unique' => false, 
'group' => 'General' 
)); 
$installer->endSetup(); 

然後我想要得到的AUTHOR_NAME屬性值對每個種類的產品,包括在網站 的naigation菜單我寫了下面的查詢來獲得屬性值:

$categories = Mage::getModel('catalog/category')->getCollection() 
    ->addAttributeToSelect('*') 
    ->addAttributeToFilter('include_in_menu', '1'); 
    foreach ($categories as $_category): 
    if ($_category->getName() != 'Root Catalog'): 
    $category = Mage::getModel('catalog/category')->load($_category->getId()); 
    $products = $category->getProductCollection() 
         ->addCategoryFilter($category) 
         ->addAttributeToSelect('author_name') 
         ->setPageSize(9); 
     $author_names = array(); 
     foreach ($products as $_product):        
     $author_names[] = $_product->getAttributeText('author_name'); 
     endforeach; 
     print_r($author_names); 
    endif; 
    endforeach; 

陣列不打印任何東西。 當我調試這個我沒有得到集合中的author_name屬性。

在我的查詢中是否有任何錯誤。 請幫我

回答

0

您好檢查下面的查詢,可以幫助你

獲取產品ID &

$ reqProdid = Mage :: registry('current_product') - > getId();

$ selected_auther = Mage :: getModel('catalog/product') - > load($ reqProdid) - > getData('author_name');

+0

嗨其工作正常時,我再次加載收集每個產品 – user1179752

0

嘗試下面的代碼顯示使用該ID獲得產品auther名稱自定義屬性

<?php echo $_product->getResource()->getAttribute('author_name')->getFrontend()->getValue($_product); ?> 
+0

嗨swapna我試過這段代碼,但它不工作。 – user1179752

+0

嗨swapna獲取資源對象也在爲我的一些產品屬性工作謝謝 – user1179752

相關問題