`
kirenenko04
  • 浏览: 151040 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

Add Category Position Field In Adminhtml Edit Form

 
阅读更多

We just need extends 'Mage_Adminhtml_Block_Catalog_Category_Tab_Attributes'

and Rewrite function _prepareForm();

add These code into function :

		if ($this->getAddHiddenFields()) {
			$fieldset->addField('position', 'text', array(
					'label'=>'Position',
					'name'  => 'position',
					'value' => $this->getCategory()->getPosition(),
			));
		}

 and do not forget change last code to :

return Mage_Adminhtml_Block_Catalog_Form::_prepareForm();

not return Parent::_prepareForm();

 

Now I will told you how to rewrite this block .

1. Define the block in our config xml file

<?xml version="1.0"?>
<config>
  <modules>
    <Bysoft_Myadminhtml>
      <version>0.1.0</version>
    </Bysoft_Myadminhtml>
  </modules>
  <global>
    <helpers>
      <myadminhtml>
        <class>Bysoft_Myadminhtml_Helper</class>
      </myadminhtml>
    </helpers>
	<blocks>
			<adminhtml>
				<rewrite>
					<catalog_category_tab_attributes>Bysoft_Myadminhtml_Block_Catalog_Category_Tab_Attributes</catalog_category_tab_attributes>
				</rewrite>
			</adminhtml>
	</blocks>
  </global>
</config> 

 2. create local block file . extends core block file:

<?php
class Bysoft_Myadminhtml_Block_Catalog_Category_Tab_Attributes extends Mage_Adminhtml_Block_Catalog_Category_Tab_Attributes
{
	/**
	 * Prepare form before rendering HTML
	 *
	 * @return Mage_Adminhtml_Block_Catalog_Category_Tab_Attributes
	 */
	protected function _prepareForm() {
		$group      = $this->getGroup();
		$attributes = $this->getAttributes();
	
		$form = new Varien_Data_Form();
		$form->setHtmlIdPrefix('group_' . $group->getId());
		$form->setDataObject($this->getCategory());
	
		$fieldset = $form->addFieldset('fieldset_group_' . $group->getId(), array(
				'legend'    => Mage::helper('catalog')->__($group->getAttributeGroupName()),
				'class'     => 'fieldset-wide',
		));
		if ($this->getAddHiddenFields()) {
			if (!$this->getCategory()->getId()) {
				// path
				if ($this->getRequest()->getParam('parent')) {
					$fieldset->addField('path', 'hidden', array(
							'name'  => 'path',
							'value' => $this->getRequest()->getParam('parent')
					));
				}
				else {
					$fieldset->addField('path', 'hidden', array(
							'name'  => 'path',
							'value' => 1
					));
				}
			}
			else {
				$fieldset->addField('id', 'hidden', array(
						'name'  => 'id',
						'value' => $this->getCategory()->getId()
				));
				$fieldset->addField('path', 'hidden', array(
						'name'  => 'path',
						'value' => $this->getCategory()->getPath()
				));
			}
		}
		$this->_setFieldset($attributes, $fieldset);
		foreach ($attributes as $attribute) {
			$rootId = Mage_Catalog_Model_Category::TREE_ROOT_ID;
			/* @var $attribute Mage_Eav_Model_Entity_Attribute */
			if ($attribute->getAttributeCode() == 'url_key') {
				if (
						(!$this->getCategory()->getId() && $this->getRequest()->getParam('parent', $rootId) == $rootId)
						|| ($this->getCategory()->getParentId() == $rootId)
				) {
					$fieldset->removeField('url_key');
				} else {
					$form->getElement('url_key')->setRenderer(
							$this->getLayout()->createBlock('adminhtml/catalog_form_renderer_attribute_urlkey')
					);
				}
			}
		}
		if ($this->getAddHiddenFields()) {
			$fieldset->addField('position', 'text', array(
					'label'=>'Position',
					'name'  => 'position',
					'value' => $this->getCategory()->getPosition(),
			));
		}
	
		if ($this->getCategory()->getLevel() == 1) {
			$fieldset->removeField('custom_use_parent_settings');
		} else {
			if ($this->getCategory()->getCustomUseParentSettings()) {
				foreach ($this->getCategory()->getDesignAttributes() as $attribute) {
					if ($element = $form->getElement($attribute->getAttributeCode())) {
						$element->setDisabled(true);
					}
				}
			}
			if ($element = $form->getElement('custom_use_parent_settings')) {
				$element->setData('onchange', 'onCustomUseParentChanged(this)');
			}
		}
	
		if ($this->getCategory()->hasLockedAttributes()) {
			foreach ($this->getCategory()->getLockedAttributes() as $attribute) {
				if ($element = $form->getElement($attribute)) {
					$element->setReadonly(true, true);
				}
			}
		}
	
		if (!$this->getCategory()->getId()){
			$this->getCategory()->setIncludeInMenu(1);
		}
	
		$form->addValues($this->getCategory()->getData());
	
		Mage::dispatchEvent('adminhtml_catalog_category_edit_prepare_form', array('form'=>$form));
	
		$form->setFieldNameSuffix('general');
		$this->setForm($form);
	
		return Mage_Adminhtml_Block_Catalog_Form::_prepareForm();
	}
}
			

 

分享到:
评论

相关推荐

    源码解析之rc-field-form解读与实现

    yarn add rc-field-form ``` - **引入**: 在你的React组件中导入`Form`和`useForm`。 ```jsx import { Form, useForm } from 'rc-field-form'; ``` - **创建表单**: 使用`&lt;Form&gt;`组件包裹表单元素,并使用`...

    ArcGIS 10.1 for Desktop Add-in开发

    《ArcGIS 10.1 for Desktop Add-in开发》 ArcGIS是由Esri公司推出的全球领先的地理信息系统(GIS)软件,广泛应用于地图制作、空间数据分析、地理信息管理等多个领域。在ArcGIS 10.1版本中,开发者可以通过创建...

    EPM Add-in_NET40

    office 2013 EPM插件,EPM add-in for Microsoft Office 是在由SAP Business...EPM系统插件add-in安装 - EPM 系统插件 Add-in 安装 说明: Add-in 为依附在 excel 上的一个直接访问 EPM 系统 essbase 数据库的小插件。

    Microsoft Excel Add-In

    【Microsoft Excel Add-In】是一种用于扩展Excel功能的插件或加载项,它允许用户自定义工作簿、工作表和图表,提升数据处理和分析能力。这些Add-Ins通常由开发者编写,采用VBA(Visual Basic for Applications)或...

    Add-in Express Version 8.1 Release (build 1432) - 10.2 Tokyo

    基于Microsoft Office的开发,Add-in Express提供了一组用于创建Microsoft Office插件的组件。与所有Microsoft Office程序交互的所有必需技术包:Microsoft Outlook,Excel,Word,Visio,Microsoft Project,...

    ArcGIS-Add-In开发文档样例资料

    ArcGIS Add-In开发是Esri公司的ArcGIS平台中的一项重要技术,它允许开发者通过扩展功能来定制和增强ArcGIS Desktop或ArcGIS Pro等应用程序。这个压缩包“ArcGIS-Add-In开发文档样例资料”提供了丰富的资源,帮助你...

    ArcGIS Python Add-In教程

    在ArcGIS环境中,Python Add-In是一种强大的工具,它允许用户扩展ArcGIS Desktop的功能,通过编写Python脚本来创建自定义的用户界面元素,如工具条、按钮、菜单等。本教程将深入探讨如何利用Python Add-In Wizard来...

    Add-in Express.7.7.源代码.rar

    标题 "Add-in Express.7.7.源代码.rar" 暗示了这是一个关于Add-in Express 7.7版本的源代码包,主要用于开发Office插件。Add-in Express是一款强大的工具,它允许开发者使用.NET Framework、VCL或MFC来构建高效、可...

    An add-in to automatically increment the PrivateBuild field

    An add-in to automatically increment the PrivateBuild field in your applications resource file.(34KB)

    Add-in Express Version 8.1 Release (build 1432)

    **Add-in Express Version 8.1 Release (build 1432) 概述** Add-in Express 是一款专为开发人员设计的工具,用于构建基于 Delphi 的 Office 插件。这个版本(8.1 build 1432)提供了一个强大的框架,使开发者能够...

    Add_in_ExpressforVCL_v901.rar

    《Add_in_Express for VCL_v901:Delphi中的插件开发框架解析》 在软件开发领域,Delphi是一种流行的面向对象的编程环境,以其高效、强大的编译器和直观的集成开发环境(IDE)著称。而Add_in_Express for VCL_v901...

    tdm_excel_add-in_2012

    TD插件,用于excel打开tdms文件,经测试office2013可用,请放心下载

    Access 2003 Add-in: Source Code Control

    When you get or check out one of these objects, the Access Source Code Control add-in copies the text file from the Visual SourceSafe project to a working folder on your machine. Microsoft Access ...

    SQL Pretty Printer Add-In for SSMS V3.2.0安装文件和注册码

    SQL Pretty Printer Add-In for SSMS V3.2.0是一款专为SQL Server Management Studio (SSMS) 2008及以下版本设计的插件工具,它的主要功能是对SQL代码进行美化和格式化,帮助开发者更好地组织和阅读SQL脚本。...

    c#下post multipart/form-data和JSON

    content.Add(new StringContent("value"), "fieldName"); // 添加文件 var fileStream = new FileStream("pathToYourFile", FileMode.Open); content.Add(new StreamContent(fileStream), "fileName", ...

    Replacing "RICHEDIT" control with "RichEdit20A"

    While writing a dev notes Visual Studio plug in, I wanted the rich edit control in a dialog to understand URL's so developers could add links to sites and email addresses. After talking to "Long John...

    MegaStat Add-In for Excel 2007 (v10.1)

    《MegaStat Add-In for Excel 2007:提升统计分析能力的利器》 MegaStat是一款专为Microsoft Excel 2007设计的强大统计分析插件,其标题"MegaStat Add-In for Excel 2007 (v10.1)"揭示了它的主要功能和版本信息。这...

    QTP82 .NET add-in

    Quick Test Professional 插件 QTP82 .NET add-in

    QTP关于JAVA ADD IN的破解

    提供免费的QTP JAVA ADD IN的破解

    ArcGIS Python Add-In入门源码和教程

    **ArcGIS Python Add-In 入门源码与教程详解** ArcGIS Python Add-In是一种强大的工具,它允许开发者利用Python语言扩展ArcGIS Desktop的功能,提供自定义的用户界面和工作流程。这一技术对于地理信息系统(GIS)的...

Global site tag (gtag.js) - Google Analytics