首页 > 其他分享 >magento Attribute Set Details

magento Attribute Set Details

时间:2022-12-16 20:04:06浏览次数:46  
标签:product set Attribute getModel Set magento attribute Mage


Introduction

An attribute set is a collection of attributes which can be created/edited from Catalog -> Manage Attribute Sets in backend.

Some useful snippets regarding Attribute Set.

1> Getting Attribute Set Details

​​$attributeSetModel​​​ ​​= Mage::getModel(​​​​'eav/entity_attribute_set'​​​​); ​​


​​$attributeSetId​​​ ​​= 9; ​​​​// or $_product->getAttributeSetId(); if you are using product model ​​


​​$attributeSetModel​​​​->load(​​​​$attributeSetId​​​​); ​​


​​print_r(​​​​$attributeSetModel​​​​->getData());​​


2> Getting Attribute Set Id by Name

​​$entityTypeId​​​ ​​= Mage::getModel(​​​​'eav/entity'​​​​) ​​


​​->setType(​​​​'catalog_product'​​​​) ​​


​​->getTypeId(); ​​


​​$attributeSetName​​​ ​​= ​​​​'Default'​​​​; ​​


​​$attributeSetId​​​ ​​= Mage::getModel(​​​​'eav/entity_attribute_set'​​​​) ​​


​​->getCollection() ​​


​​->setEntityTypeFilter(​​​​$entityTypeId​​​​) ​​


​​->addFieldToFilter(​​​​'attribute_set_name'​​​​, ​​​​$attributeSetName​​​​) ​​


​​->getFirstItem() ​​


​​->getAttributeSetId(); ​​


​​echo​​​ ​​$attributeSetId​​​​;​​


Note that the following code doesn’t work

​​$attributeSetId​​​ ​​= Mage::getModel(​​​​'eav/entity_attribute_set'​​​​) ​​


​​->load(​​​​$attributeSetName​​​​, ​​​​'attribute_set_name'​​​​) ​​


​​->getAttributeSetId();​​


Because if you refer to eav_attribute_set table then you can see there are lots of rows with same attribute set name(for example: Default)

3> Getting all Attribute Sets by Entity Type(catalog_product)

​​$entityTypeId​​​ ​​= Mage::getModel(​​​​'eav/entity'​​​​) ​​


​​->setType(​​​​'catalog_product'​​​​) ​​


​​->getTypeId(); ​​


​​$attributeSetCollection​​​ ​​= Mage::getModel(​​​​'eav/entity_attribute_set'​​​​) ​​


​​->getCollection() ​​


​​->setEntityTypeFilter(​​​​$entityTypeId​​​​); ​​


​​foreach​​​​(​​​​$attributeSetCollection​​​ ​​as​​​ ​​$_attributeSet​​​​){ ​​


​​print_r(​​​​$_attributeSet​​​​->getData()); ​​


​​}​​


Alternatively, you can also use:

​​$attributeSets​​​ ​​= Mage::getModel(​​​​'catalog/product_attribute_set_api'​​​​)->items(); ​​


​​foreach​​​​(​​​​$attributeSets​​​ ​​as​​​ ​​$_attributeSet​​​​){ ​​


​​print_r(​​​​$_attributeSet​​​​); ​​


​​}​​


4> Getting all attributes in an Attribute Set

​​$attributes​​​ ​​= Mage::getModel(​​​​'catalog/product_attribute_api'​​​​)->items(​​​​$attributeSetId​​​​); ​​


​​foreach​​​​(​​​​$attributes​​​ ​​as​​​ ​​$_attribute​​​​){ ​​


​​print_r(​​​​$_attribute​​​​); ​​


​​}​​


5> Filtering Products by Attribute Set

​​$productCollection​​​ ​​= Mage::getModel(​​​​'catalog/product'​​​​) ​​


​​->getCollection() ​​


​​->addAttributeToSelect(​​​​'*'​​​​) ​​


​​->addFieldToFilter(​​​​'attribute_set_id'​​​​, ​​​​$attributeSetId​​​​); ​​


​​foreach​​​​(​​​​$productCollection​​​ ​​as​​​ ​​$_product​​​​){ ​​


​​print_r(​​​​$_product​​​​->getData()); ​​


​​}​​



Hope you will find these snippets useful/helpful.
Please do share if you have any useful code snippets regarding Attribute Set.

Thanks for reading!

标签:product,set,Attribute,getModel,Set,magento,attribute,Mage
From: https://blog.51cto.com/u_5112239/5948298

相关文章

  • Magento导出所有分类ID和名称到数组中
    ​​//获取所有激活状态的分类模型集合​​​​$categories​​​​=Mage::getModel(​​​​'catalog/category'​​​​)->ge......
  • hasattr()、getattr()、setattr()函数简介
    hasattr(object,name)判断object对象中是否存在name属性,当然对于python的对象而言,属性包含变量和方法;有则返回True,没有则返回False;需要注意的是name参数是string类型,所以......
  • 应用设置Setting的实现
    有很多应用都在iOS设置中有相关的设置,如下图:   通过这个设置可以方便的对应用的一些基本的设置进行更改。要完整的实现这个设置功能,有以下几方面问题需要解决:1)设置的编......
  • 【快应用】初始化页面时,调用configuration.setLocale()不生效
    ​现象描述快应用app.ux中定义了全局方法changeLocaleConfiguration,用于设置应用显示语言,在首页生命周期onInit中调用changeLocaleConfiguration(),实际已经触发了该方法,但......
  • reset.css 2022
    /***ThenewCSSreset-version1.7.3(lastupdated7.8.2022)GitHubpage:https://github.com/elad2412/the-new-css-reset***//*Removeallthe......
  • Chapter 10.利用Redis Zset实现双维度排行榜
    欢迎来到「我是真的狗杂谈世界」,关注不迷路背景最近需要将遇到的几个排行需求点抽出来做一个独立的通用排行组件,整理记录一下。核心需求能获得连续的部分的榜单:比如......
  • VUE使用axios数据请求时报错 TypeError Cannot set property 'xxxx' of undefined 的
    正常情况下在data里面都有做了定义data(){list:"haha"}在函数里面进行赋值this.list=response.data.result这时候你运行时会发现,数据可以请求到,但是会报错TypeErr......
  • ATA驱动- hardreset&softreset分析
    内核文档内核路径下的文档Documentation/DocBook/libata.tmpl内核文档解释说明不同的reset调用对应的底层Errorhandlerreset函数;softreset&hardresetEH函数在内核a......
  • vue3.0--<script setup>的使用
    1.<scriptsetup>的定义<scriptsetup> 是在单文件组件(SFC)中使用组合式API的编译时语法糖。当同时使用SFC与组合式API时该语法是默认推荐。相比于普通的 <scr......
  • Vue笔记6--组合式API setup
    1、组合式api-setup组合式api将同一个逻辑关注点的代码收集在一起。在组件被创建前执行,props解析完成后被作为组合式api入口。setup取代了beforeCreate()和created(),由于......