嗨,我創建了一個多選產品屬性與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