addAttributeToFilter is used to filter EAV collections and will filter the products based on the attributes that you've included in your collection.
EAV-models: product, customer, sales, etc.
addFieldToFilter is used to filter Non-EAV collections and will filter the products based on columns in the database from the table catalog_product_entity.
EAV-models are for example product, customer, sales, etc so you can use use addAttributeToFilter()
for those entities.
addFieldToFilter()
is mapped to addAttributeToFilter()
for EAV entities. So you can just use addFieldToFiler()
.
You can have a look in app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php
where the Mapping is done:
public function addFieldToFilter($attribute, $condition = null) {
return $this->addAttributeToFilter($attribute, $condition);
}
addAttributeToSelect() : addAttributeToSelect() is used to filter the attributes fromthe magento database
$collections = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect(array('name', 'price','sku'));
//If we use addAttributeToSelect('*'), then all product attributes will be loaded.
addAttributeToFilter : addAttributeToFilter() is used to filter EAV collections in Magento,and filter the products based on the attributes that you have included in your collection.
addAttributeToFilter add a condition to the WHERE part of the MySQL query, used to extract a product collection from the database using specified condition.
$collections = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect(array('name', 'price','sku'))
->addAttributeToFilter('sku', array('like' => '%AM%'))
->load();
The above code would get a product collection, with each product having it’s name, price AND sku. The product collection would be filtered and contain only products that have an SKU WITH with AM.
If we use addAttributeToSelect(‘*’), then all product attributes will be loaded.
addFieldToFilter : addFieldToFilter will filter the products based on columns in the database from the table catalog_product_entity. and used for flat model.it is defined in Mage_Core_Model_Resource_Db_Collection_Abstract class so it is available in all its child classes.
$collection = Mage::getModel('news/post')->getCollection();
$collection->addFieldToFilter('file_id',3);
$collection->addFieldToFilter('list_id',array('in'=>array(1,2,3)));
更多参考:
- Magento模型集合addFieldToFilter常用过滤条件
- difference between addAttributeToSelect(), addAttributeToFilter() and addFieldToFilter() methods
- Magento Collection Filtering functions
原文/转自: Magento: addAttributeToFilter 和 addFieldToFilter 的区别 Difference between addAttributeToFilter and addFieldToFilter
相关推荐
MagentoBeginner's Guide.pdf [Packt]出品,最早的Magento精品书之一,原书地址:http://www.amazon.com/Magento-Beginners-Guide-William-Rice/dp/1847195946
NULL 博文链接:https://justcoding.iteye.com/blog/2100394
magento:magento-ce 2.4.0
通过SFTP或SSH导航到Magento [Magento]/app/code/ 。 上载带有扩展名的Dropday/OrderAutomation目录。 打开终端并导航到Magento根目录。 运行以下命令以启用Dropday扩展: php bin/magento module:enable Dropday_...
Magento:registered:2数据集成借助Datatric Connect扩展程序,可以轻松地将Magento:registered:2商店与Datatrics平台连接起来。安装在开始安装过程之前,我们建议您对webshop文件以及数据库进行备份。 有两种安装...
magento:Magento CE 1.x源代码
fresh-magento:新鲜的magento
Magento通过最佳的电子商务平台和灵活的云解决方案为成千上万的零售商和品牌提供支持,以实现快速创新和发展。 CMS Connect App-通过GraphQL API在Magento CMS和VueFront Web App之间添加连接。它有什么作用? 这是...
docker-magento:Mark Shust的Magento Docker配置
ansible-magento要求: -流浪汉-可以指示: 克隆此仓库无所事事在浏览器中导航到magento.dev。MySQL 数据库:magento 用户名:magento 密码:password123 这是基于的工作而进行的一些更改,以简化启动和运行过程...
Apress.The.Definitive.Guide.to.Magento.Dec.2009.pdf Apress于2009重磅推出的Magento上手书籍,原书地址:http://www.apress.com/book/view/9781430272298
magento:megento电子商务网站
deployer-extended-magento:Magento的基于部署程序的部署,具有媒体和数据库同步
MódulodeIntegraçãocom市场 Compatívelcom a ... 内华达州立电视台(Nesta telaépossívelhabilitar omóduloMHub em sua loja)和市场营销部(Fornecedor)。 没有Modo市场,可以在Epicom上生产产品,也可以
Magento 与 Apache OFBiz 集成,兼容 OFBiz-13.07 和主干 在 Apache OFBiz-13.07 和 OFBiz 主干中使用磁电机组件的步骤 启动终端并进入 Apache OFBiz 的主目录 在热部署文件夹中签出 magento 组件 使用命令加载数据...
为 Magento 添加 Gimmie 奖励,让用户在购买和推荐朋友时获得积分并获得真正的奖励。 要安装此插件,我们提供。 建造 克隆此插件所需的所有子模块(gimmie php 项目) $git submodule init && git submodule ...
流浪者-magento:**已弃用**
马恩托 magento 项目
马真托Magento片段。
导入和导出:用户可以导入目录,类别和产品以及客户的信息和地址。 Magento Tryton连接器会导入每个订单状态,包括已取消的订单。 其他导入的订单正在等待,排队,开始,完成或失败。 如果连接器较早不存在,该连接...