脚本宝典收集整理的这篇文章主要介绍了php – Magento:自定义产品属性,用于选择CMS页面,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
到目前为止我尝试了什么:
$installer = $this; $SETUP = new Mage_Eav_Model_Entity_Setup('core_setup'); $installer->startSetup(); $setup->addAttribute('cataLOG_PRoduct','test_report',array( 'label' => 'Test report','required' => false,'input' => 'select','source' => 'cmspageselect/entity_source','default' => 'none','position' => 1,'sort_order' => 3,)); $installer->endSetup();
cmspageselect / entity_source类的源代码:
class Mandarin_CMSPageSelect_Model_Source extends Mage_Eav_Model_Entity_Attribute_Source_Abstract { /** * Retrieve Full Option values array * * @param bool $withEmpty Add empty option to array * @return array */ public function getAllOptions($withEmpty = true) { $StoreId = $this->getAttribute()->getStoreid(); if (!is_array($this->_options)) { $this->_options = array(); } if (!isset($this->_options[$storeId])) { $collection = Mage::getResourceModel('cms/page_collection') ->setPositionOrder('asc') ->setStoreFilter($this->getAttribute()->getStoreId()) ->load(); $this->_options[$storeId] = $collection->toOptionIdArray(); } $options = $this->_options[$storeId]; if ($withEmpty) { array_unshift($options,array('label' => '','value' => '')); } return $options; } /** * Get a text for option value * * @param string|integer $value * @return string */ public function getOptionText($value) { $isMultiple = false; if (strpos($value,',')) { $isMultiple = true; $value = explode(',$value); } $options = $this->getAllOptions(false); if ($isMultiple) { $values = array(); foreach ($options as $item) { if (in_array($item['value'],$value)) { $values[] = $item['label']; } } return $values; } foreach ($options as $item) { if ($item['value'] == $value) { return $item['label']; } } return false; } }
正如我所说,Magento没有创建新属性“test_report”,而是破坏了eav_entity_type表.关于发生的事情,没有错误信息也没有日志条目.
我该如何创建这样的属性?
谢谢,
aeno
$installer = $this; $installer->startSetup(); $installer->addAttribute('catalog_product',)); $installer->endSetup();
除此之外,我认为您的源值不正确,从数组中的源元素判断,您应该命名您的模型Mandarin_CMSPageSelect_Model_Entity_Source.我假设您已添加适当的< models>元素到config.XMl,以告诉Magento从哪里加载你的模型.
以上是脚本宝典为你收集整理的php – Magento:自定义产品属性,用于选择CMS页面全部内容,希望文章能够帮你解决php – Magento:自定义产品属性,用于选择CMS页面所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。