您好我使用setup.php创建了一个多选产品属性,并且已创建。我使用了以下代码:
$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();
然后我想获取网站naigation菜单中包含的每个类别中每个产品的author_name属性值 我编写了以下查询来获取属性值:
$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 :(得分:0)
尝试使用以下代码显示自定义属性
<?php echo $_product->getResource()->getAttribute('author_name')->getFrontend()->getValue($_product); ?>
答案 1 :(得分:0)
您好检查以下查询可能会对您有所帮助
获取产品ID&amp;使用此id获取产品名称
$reqProdid = Mage::registry('current_product')->getId();
$selected_auther =Mage::getModel('catalog/product')
->load($reqProdid)
->getData('author_name');