• 首页
    • English
    • 中文
  • 关于我们
  • 服务项目
    • 谷歌SEO服务
    • WordPress建站服务
    • 谷歌ADS/SEM代运营
  • 项目案例
    • 医疗
    • 建材
    • 机械加工
    • 照明
    • 电商
    • 电脑硬件
  • 博客
    • 服务器运维
      • aliyun
      • 服务器安装
      • 宝塔面板
      • 虚拟化
      • 阿里云
      • Centos
      • linux
      • nginx
    • 电子商务
    • 免费资源
    • PHP
      • Magento
      • WordPress
    • 大数据采集
    • Python
    • Javascript
    • SEO
    • 未分类
  • 联系我们
What's Hot

机械模具加工公司网站设计案例

24 10 月, 2023

快速原型公司案例

24 10 月, 2023

陶瓷加工网站案例

24 10 月, 2023
Facebook Twitter Instagram
  • 中文
  • English
Facebook Twitter Instagram
VPSEO VPSEO
  • 首页
    • English
    • 中文
  • 关于我们
  • 服务项目
    • 谷歌SEO服务
    • WordPress建站服务
    • 谷歌ADS/SEM代运营
  • 项目案例
    • 医疗
    • 建材
    • 机械加工
    • 照明
    • 电商
    • 电脑硬件
  • 博客
    • 服务器运维
      • aliyun
      • 服务器安装
      • 宝塔面板
      • 虚拟化
      • 阿里云
      • Centos
      • linux
      • nginx
    • 电子商务
    • 免费资源
    • PHP
      • Magento
      • WordPress
    • 大数据采集
    • Python
    • Javascript
    • SEO
    • 未分类
  • 联系我们
VPSEO VPSEO
Home»Magento»magento 获取自定义产品属性和属性值
Magento

magento 获取自定义产品属性和属性值

chrispengcnBy chrispengcn7 8 月, 2021没有评论1 Min Read
Facebook Twitter Pinterest LinkedIn Tumblr Email
Share
Facebook Twitter LinkedIn Pinterest Email

magento 获取自定义产品属性和属性值

在magento系统中经常要自定义自己的产品属性,在后台自定义的产品属性如何获取呢,下面根据属性类型的不同分别说明

产品属性要想在前台获取到需要设置属性的Used in Product Listing 为true

1、下拉列表的产品属性

如定义了一个表示产品的硬件支持类型的下拉列表属性support_hardware就可以这样获取

[php]

$attributes[‘support_hardware’]=$product->getAttributeText(‘support_hardware’);

2、文本类型的产品属性

如定义了一个属性叫version_number用来表示产品的版本号,这个属性是文本类型的,那么就可以这样获取

[php]

$attributes[‘version_number’]=$product->getData(‘version_number’);

当得到产品对象后我们可以获取产品的各种属性,如果我们要获取满足一定属性条件的产品集呢?这时候就需要根据产品属性对产品过滤了

magento提供的根据属性过滤的接口有两种,一种是addAttributeToFilter,另一种是直接操作数据库通过getSelect()->where()的方法

1、addAttributeToFilter接口

比如我们想要获取APP产品支持的系统版本(属性name是system_version)在4.2以上的的产品集,就可以这么做

[php]

$_productCollection = Mage::getResourceModel(‘catalog/product_collection’)
->setStoreId(1)
->addAttributeToSelect(‘*’)
->addAttributeToFilter(‘system_version’,array(‘gteq’=>45));//45这个值是怎么得到的呢,这个值是system_version为4.2时对应的属性值,关于怎么获取属性的值在后面会讲

2、通过getSelect()->where()直接操作数据库

通过这种方式要求对数据库结构属性,通常我们会用

[php]

$_productCollection->getSelectSql()

来帮助我们写sql语句
[php]

$_productCollection->getSelect()->where(‘age’,array(‘gteq’=>45));

怎么通过where写复杂的查询数据库语句会在另一篇中讲解

获取产品后通常还要加上对产品做产品是否是激活,是否在当前商店的判断

[php]

$product->isSalable()

下面讲下怎么获去属性的值

1、假设我们知道attribute的ID为149,就可以这样获取属性的value和label

[php]

$attributeOption=Mage::getResourceModel(‘eav/entity_attribute_option_collection’)
->setPositionOrder(‘asc’)
->setAttributeFilter(149)
->setStoreFilter()
->load();
$attributeOptionArray=$attributeOption->toOptionArray();
echo ”


“;
print_r($attributeOptionArray);

2、怎么根据attribute的name来得到attribute对象还在研究中

在实际应用时通常要获取可用来过滤产品的的属性,也就是filterable attributes,获取的方法如下:

[php]

protected function _getFilterableAttributes(){
$layer = Mage::getModel(“catalog/layer”);
$rootCategory=Mage::getModel(‘catalog/category’)->load(Mage::app()->getStore()->getRootCategoryId());
$layer->setCurrentCategory($rootCategory);
$attributes = $layer->getFilterableAttributes();
$this->_filterableAttributesExists=array();
foreach ($attributes as $attribute) {
//echo $attribute->getAttributeCode(),”—“,$attribute->getId(),””;
$this->_filterableAttributes[$attribute->getAttributeCode()]=$attribute->getId();
}
krsort($this->_filterableAttributes);
return $this->_filterableAttributes;
}

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
chrispengcn
  • Website

Related Posts

docker 环境下 安装Magento2(麦进斗)

26 12 月, 2021

magento 2.3 nginx 安装

7 8 月, 2021

Magento忘记密码怎么办

7 8 月, 2021

解决magento后台无法登陆/登陆没有反应的方法

7 8 月, 2021
Add A Comment

Leave A Reply Cancel Reply

*

code

导航
  • 首页
  • 关于我们
  • 服务项目
  • 项目案例
  • 博客文章
  • 联系我们
博客
  • 服务器运维
  • 服务器安装
  • nginx
  • PHP
  • WordPress
  • Python
  • Javascript
  • SEO
  • 电子商务
  • 大数据采集
  • 宝塔面板
  • 数据库
  • 电子商务
  • 虚拟化
  • 阿里云
导航
  • 首页
  • 关于我们
  • 谷歌SEO服务
  • 谷歌ADS/SEM代运营
  • WordPress建站服务
  • 项目案例
  • 博客
  • 联系我们
最新文章
  • 机械模具加工公司网站设计案例
  • 快速原型公司案例
  • 陶瓷加工网站案例
  • CNC数控加工日文网站案例
  • 触摸一体机数字标牌厂家网站案例
关于我们
关于我们

广州纬来科技有限公司
联系地址:广东省广州市番禺区富华中路富源二街18号合和大厦809

QQ : 13602156
Email : 13926026058@139.com
Contact: +86 13926026058

Facebook Twitter YouTube LinkedIn
© 2025 广州纬来科技有限公司 粤ICP备2023105857号-2
  • 首页
  • 关于我们
  • 谷歌SEO服务
  • 谷歌ADS/SEM代运营
  • WordPress建站服务
  • 项目案例
  • 博客
  • 联系我们

Type above and press Enter to search. Press Esc to cancel.