2012-12-04 143 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

相关问题