我的自定义属性未显示在产品集合Magento中
嗨,我用setup.php创建了一个多选产品属性,它被创建了。我使用了以下代码:我的自定义属性未显示在产品集合Magento中,magento,Magento,嗨,我用setup.php创建了一个多选产品属性,它被创建了。我使用了以下代码: $installer = $this; $installer->startSetup(); $installer->addAttribute('catalog_product', 'author_name',array( 'label' => 'Name of The Author', 'type' => 'varchar', 'input' => 'multise
$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属性值
我编写了以下查询以获取属性值:
$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属性
我的问题有什么不对吗。
请帮助我尝试以下代码以显示自定义属性
<?php echo $_product->getResource()->getAttribute('author_name')->getFrontend()->getValue($_product); ?>
您好,下面的查询可能会对您有所帮助 获取产品id&使用此id获取产品作者名称
$reqProdid = Mage::registry('current_product')->getId();
$selected_auther =Mage::getModel('catalog/product')
->load($reqProdid)
->getData('author_name');
您好,当我再次加载集合中的每个产品时,它工作正常。我的swapna获取资源对象也适用于我的一些产品属性。谢谢