magento :如何在后台的form中添加内容可变的select filed

2023-05-16

如下图:在product form中添加了一个attribute “spot_spotter”,这个attribute可以选择某个已注册的用户。



注意了,由于这个attribute 的内容是动态变化的,所以这个product attribute 的type是select,但却不能通过常规的方法指定option值。


最后研究出以下的解决方案:

(1)在setup文件中 给attribute添加新的属性 “frontend_input_renderer“, 指定render的block


$eav = new Mage_Eav_Model_Entity_Setup('sales_setup');

$eav->updateAttribute('catalog_product', 'spot_spotter', 'frontend_input_renderer', 'spot/adminhtml_catalog_spot_htmlselect');


(2) 然后在mdoule spot中创建 block “Xxx_Spot_Block_Adminhtml_Catalog_Spot_Htmlselect” ,内容如下:


<?php

class Xxx_Spot_Block_Adminhtml_Catalog_Spot_Htmlselect extends Varien_Data_Form_Element_Select
{
    public function getValues()
    {
        return $this->toCustomerOptionArray();
    }
    
    public function toCustomerOptionArray(){
    	$customerSelect=array();
    	
    	//add empty value
    	$customerSelect[]=array('label'=>"","value"=>"" );
    	
    	$collection=Mage::getModel('customer/customer')->getCollection()
    	           ->addAttributeToSelect("firstname")
    	           ->addAttributeToSelect("lastname");
    	           
    	foreach( $collection as $key=>$customer ){
    		$id=(int)$customer->getId();
    		$name=$customer->getData("firstname")." ".$customer->getData("lastname");
    		$customerSelect[]=array('label'=>$name,"value"=>$id);
    	}
    	
    	return $customerSelect;
    }
 
}

ok。搞定。


  

  

  

  
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

magento :如何在后台的form中添加内容可变的select filed 的相关文章

随机推荐

  • HP大中华区总裁孙振耀退休感言

    一 关于工作与生活 我有个有趣的观察 xff0c 外企公司多的是25 35岁的白领 xff0c 40岁以上的员工很少 xff0c 二三十岁的外企员工是意气风发的 xff0c 但外企公司40岁附近的经理人是很尴尬的 我见过的40岁附近的外企经
  • Linux 和 window 双启动 恢复的一种方法

    出处 xff1a http blog chinaunix net space php uid 61 7459305 amp do 61 blog amp id 61 2051833 声明 xff1a 下面的内容主要思想摘自 http www
  • Linux Windows 双启动 Grub 修复

    出处 xff1a http hotthing blog 163 com blog static 29670309200971974412760 Linux Windows 双启动 Grub 修复 重新安装 windows 后 linux的启
  • ubuntu11.04使用U盘启动或安装的方法

    出处 xff1a http blessht iteye com blog 1077674 今天在ubuntu官网下载最新版的iso xff0c 并且按照提示下载了名为 Universal USB Installer exe 的文件将iso写
  • Ubuntu11.04安装完全指南

    出处 xff1a http apps hi baidu com share detail 46047864 Ubuntu11 04安装完全指南 李顺亮 2011年5月3日00 44 09 现在的世界变化快 xff0c 早已不再年少的我们 x
  • Ubuntu 11.04更改分辨率

    出处 xff1a http www linuxidc com Linux 2011 08 41465 htm 刚从Ubuntu 10 10升级到11 04 xff0c 一切很顺利 xff0c 只是有部分软件要重新装下 xff0c 这倒没什么
  • 开机自动启动 Ubuntu iBus 输入法

    http apps hi baidu com share detail 5399322 buntu 的默认输入法是 ibus xff0c 但是发现系统启动时它不会自动启动 Google 的说法是 xff1a Ubuntu 系统安装后虽然自带
  • ubuntu 下更改窗口的默认颜色

    白色实在太刺眼 xff0c 在ubuntu 下同样也更改窗口颜色保护眼睛 更改边框的颜色 xff1a 在桌面上右键 xff0d 更改桌面背景 xff0d 主题 xff0d 自定义 xff0d 颜色 xff0d 输入框 xff0d 背景 R
  • Linux操作系统挂载U盘和硬盘光驱的问题

    http root 5d6d com thread 726 1 1 html 一 Linux挂载U盘 1 插入u盘到计算机 xff0c 如果目前只插入了一个u盘而且你的硬盘不是scsi的硬盘接口的话 xff0c 那它的硬件名称为 sda1
  • STM32:从菜鸟到牛人就是如此简单!

    为了学习单片机而去学习单片机的思路是不对的 你问 如何系统地入门学习stm32 xff1f 本身就是一个错误的问题 假如你会使用8051 会写C语言 那么STM32本身并不需要刻意的学习 你要考虑的是 我可以用STM32实现什么 xff1f
  • 如何在Ubuntu下制作ISO镜像

    http cursed iteye com blog 472512 在Windows下有很多大型破解软件可以完成 xff0c 但是在linux下就轻便多了 而且不用承受非法使用软件带来的不安 xff08 如果你感觉不安的话 xff09 步骤
  • Ubuntu中配置双显示器方法

    http hankgong iteye com blog 667022 现在很多人为了提高工作效率 xff0c 都用双显示器了 xff0c 我用了快有3年了 windows中配置双显示器是比较简单的 xff0c 只要显卡装好了 xff0c
  • pdf阅读器xpdf的安装与中文乱码问题

    http apps hi baidu com share detail 17962100 1 安装xpdf xff1a sudo apt get install xpdf 2 解决xpdf打开中文时的乱码问题 xff1a sudo apt
  • wamp 中apache没法启动的问题

    最近重装了window xff0c 所有的软件都需要重装 xff0c 但装了wamp后发现apache 总是没法启动 后来发现退出skype后apache就能启动 xff0c 哦 xff0c 想到apache启动后需要用80端 xff0c
  • ubuntu 用root登录后没法使用chromium 的问题

    用root登录后启动chromium会出现错误 xff1a Google Chrome can not be run as root Please start Google Chrome as a normal user To run as
  • Linux下的XAMPP基本配置技巧(设置虚拟主机、添加FTP账户等)

    http www cnblogs com luoine archive 2011 03 09 1978096 html xampp安装好之后就只有一个默认站点及一个默认nobody的ftp账户 xff0c 这显然不符合我们平时的需求了 xf
  • 揭秘SQL优化技巧 改善数据库性能

    http www php100 com html webkaifa database Mysql 2011 1206 9438 html 这篇文章是以 MySQL 为背景 xff0c 很多内容同时适用于其他关系型数据库 xff0c 需要有一
  • mysql 5.0存储过程学习总结

    http www ccvita com 100 html mysql存储过程的创建 xff0c 删除 xff0c 调用及其他常用命令 mysql 5 0存储过程学习总结 一 创建存储过程 1 基本语法 xff1a create proced
  • SVN常用命令

    http sunjun041640 blog 163 com blog static 2562683220111154567740 1 将文件checkout到本地目录 svn checkout path xff08 path是服务器上的目
  • magento :如何在后台的form中添加内容可变的select filed

    如下图 xff1a 在product form中添加了一个attribute spot spotter xff0c 这个attribute可以选择某个已注册的用户 注意了 xff0c 由于这个attribute 的内容是动态变化的 xff0