Magento对属性集进行筛选得到属性值

来源:互联网 发布:淘宝打印助手在哪里 编辑:程序博客网 时间:2024/06/11 06:49
  1. 一级属性集type所在的数据表:eav_entity_type
  2. 一级属性集下的二级属性集所在的数据表:eav_attribute_set
  3. 二级属性集下的三级属性集所在的数据表:eav_attribute

在magento中存在着eav模型,而eav模型中存在着很多属性集,大概有三级属性集,如下:

  • 在一级属性中是像用户属性集、用户地址属性集、产品分类属性集和产品属性集等;

后台位置:Catalog->Manage Categories->Default Category
- 在一级属性集下是对应的二级属性集,例如:产品属性集下包括Shoes、Bottoms、Tops等;

后台位置:Catalog->Attribute->Manage Attribute Sets
- 在二级属性集下就是三级属性,比如size、color等属于三级属性,这个就不是属性集,是单个的属性;

后台位置:Catalog->Attribute->Manage Attribute Sets属性下

下面的代码就是在商品的属性集过滤筛选出对应商品的属性:

$category= Mage::getModel('catalog/category')->load($category_id);$attribute_set = $category->getAttributeSet();$sizeAttribute= Mage::getResourceModel('catalog/product_attribute_collection')    ->setAttributeSetFilter($attribute_set)    ->addFieldToFilter('attribute_code',array('like' => '%size'))    ->getFirstItem();
  1. 第一行代码是通过分类ID得到该分类ID下的分类信息;
  2. 第二行代码通过该分类ID来得到attribute_set值,进而判断该商品属于哪个类型的ID;
  3. 第三行代码是得到Product属性集集合;
  4. 第四行代码是通过类型的ID过滤出属于product属性集下的哪个属性集;
  5. 第五行代码是在上面得到的属性集里通过模糊查询size;
  6. 第六行代码是去模糊查询到的第一个值。