嗨,我创建了一个多选产品属性与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属性。
在我的查询中是否有任何错误。 请帮我
嗨其工作正常时,我再次加载收集每个产品 – user1179752