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

add attribute group and create new attribute to this group

 
阅读更多

//for example:

// I will add a attribute group named 'Vendor' to 'Default' attribute set

function addAttributeGroup($group_name, $attrSetName,$sort_order) {
	$modelGroup = Mage::getModel('eav/entity_attribute_group');
	$attributeSetId = Mage::getModel('eav/entity_attribute_set')
	->load($attrSetName, 'attribute_set_name')
	->getAttributeSetId();
	$modelGroup->setAttributeGroupName($group_name) //change group name
	//link to the current set
	->setAttributeSetId($attributeSetId)
	//set the order in the set
	->setSortOrder($sort_order);
	//save the new group
	$modelGroup->save();
}

addAttributeGroup('Vendor', 'Default',100);

 //Then Create a Select drop down attribute and add it to the group

function createSelectAttribute($code, $label, $group_name )
{
	$_attribute_data = array(
			'type'       => 'int',
			'input'      => 'select',
			'label'      => $label,
			'sort_order' => 1000,
			'required'   => false,
			'global'     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
			'backend'    => 'eav/entity_attribute_backend_array',
			'option'     => array (
					'values' => array(
					)
			),
			'group' => $group_name,
			'visible' => true,
			'visible_on_front'=>true,
			'unique' => false,
			'is_configurable' => false,
			'used_for_promo_rules' => true,
	);
	
	$objCatalogEavSetup = Mage::getResourceModel('catalog/eav_mysql4_setup', 'core_setup');
	$attrIdTest = $objCatalogEavSetup->getAttributeId(Mage_Catalog_Model_Product::ENTITY, $code);
	if ($attrIdTest === false) {
		$objCatalogEavSetup->addAttribute(Mage_Catalog_Model_Product::ENTITY, $code, $_attribute_data);
	}
}

//add vendor name
createSelectAttribute('vendor_name','Vendor Name','Vendor');
//add vendor no
createSelectAttribute('vendor_no','Vendor Number','Vendor');

 //at Last i write a text format attribute function

function createTextAttribute($code, $label, $group_name )
{
	$_attribute_data = array(
			'type'       => 'varchar',
			'input'      => 'text',
			'label'      => $label,
			'required'   => false,
			'global'     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
			'backend'    => '',
			'group' => $group_name,
			'visible' => true,
			'visible_on_front'=>true,
			'unique' => false,
			'is_configurable' => false,
			'used_for_promo_rules' => true
	);
	$objCatalogEavSetup = Mage::getResourceModel('catalog/eav_mysql4_setup', 'core_setup');
	$attrIdTest = $objCatalogEavSetup->getAttributeId(Mage_Catalog_Model_Product::ENTITY, $code);
	if ($attrIdTest === false) {
		$objCatalogEavSetup->addAttribute(Mage_Catalog_Model_Product::ENTITY, $code, $_attribute_data);
	}
}

//add vendor item no
createTextAttribute('vendor_item_no','Vendor Item Number','Vendor');

 

 

 

分享到:
评论

相关推荐

    微软数据库考试70-768: Exam Ref 70-768 Developing SQL Data Models

    Module 8: Introduction to Data Analysis [removed]DAX)This module describes how to use DAX to create measures and calculated columns in a tabular data model.Lessons DAX Fundamentals Using DAX to ...

    Dundas.Chart.for.Winform.Enterprise.v7.1.0.1812.for.VS2008

    Animation (ASP.NET Enterprise Edition only) - Version 4.0 now lets you enable charts with Flash and SVG Animation, to add a new level of presentation to your charts. With a variety of pre built ...

    Hands-On Database An IntroductIon to Database design and development 2nd

    • Create entities and add attributes • Determine the appropriate relationship between entities • Resolve many-to-many relationships with a linking table chapter 5: Normalization and design review ...

    WPTools.v6.29.1.Pro

    We recommend to use TMS components to create modern user interfaces, toolbars and ribbons. 19.2.2013 - WPTools 6.29.1 - fix in rtf writing code to solve problem with merged cells - fix possible range...

    Senfore_DragDrop_v4.1

    4) Add the Drag and Drop Component Suite components directory to your library path. 5) Load the demo project group: demo\dragdrop_delphi.bpg for Delphi 5 and 6 demo\dragdrop_bcb4.bpg for C++ ...

    数位板压力测试

    This specification was developed in response to a perceived need for a standardized programming inter-face to digitizing tablets, three dimensional position sensors, and other pointing devices by a ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    In particular, do not add new parameters to the end of the function just because they are new; place new input-only parameters before the output parameters. This is not a hard-and-fast rule. ...

    FastReport.v4.15 for.Delphi.BCB.Full.Source企业版含ClientServer中文修正版支持D4-XE5

    FastReport® VCL is an add-on component that allows your application to generate reports quickly and efficiently. FastReport® provides all the tools necessary for developing reports, including a ...

    Fast Report Enterprise v4.9.32 Full Source

    + added an ability to create multiimage TIFF files + added export headers/footers in ODF export + added ability to print/export transparent pictures (properties TfrxPictureView.Transparent and ...

    The Art of Assembly Language Programming

    3 Organization of This Text and Pedagogical Concerns 4 Obtaining Program Source Listings and Other Materials in This Text <br>Section One: Machine Organization <br>Art of Assembly ...

    arcgis工具

    先选责需要另存图层的要素(直接选择或者属性表),然后在图层上右键Selection/create Layer From Selected Features。 (以前都是直接export竟然没有发现) 27.利用Hyperlinks丰富数据库,为其添加超链接。 单击...

    thl_r16_tinav2.0_hm1375验证通过_增加打印设备ID_20170824_1447.7z

    ret = sysfs_create_group(&dev->pdev->dev.kobj, &vfe_attribute_group); #ifdef CONFIG_ES dev->early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1; dev->early_suspend.suspend = vfe_early_suspend...

    hm1375_tinav2.1验证通过_增加设备ID的读取显示_20170825_1333没有外层目录.7z

    ret = sysfs_create_group(&dev->pdev->dev.kobj, &vfe_attribute_group); #ifdef CONFIG_ES dev->early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1; dev->early_suspend.suspend = vfe_early_suspend...

    ORACLE OSB开发指南

    Working with Projects, Folders, Resources, and Configurations ................................................... 2-1 Resource Naming Restrictions ........................................................

    java 面试题 总结

    &是位运算符,表示按位与运算,&&是逻辑运算符,表示逻辑与(and)。 11、HashMap和Hashtable的区别。 HashMap是Hashtable的轻量级实现(非线程安全的实现),他们都完成了Map接口,主要区别在于HashMap允许空...

Global site tag (gtag.js) - Google Analytics