app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Config.php
/**
* Retrieve Product Attributes Used in Catalog Product listing
*
* @return array
*/
public function getAttributesUsedInListing() {
$select = $this->_getReadAdapter()->select()
->from(array('main_table' => $this->getTable('eav/attribute')))
->join(
array('additional_table' => $this->getTable('catalog/eav_attribute')),
'main_table.attribute_id = additional_table.attribute_id',
array()
)
->joinLeft(
array('al' => $this->getTable('eav/attribute_label')),
'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int) $this->getStoreId(),
array('store_label' => new Zend_Db_Expr('IFNULL(al.value, main_table.frontend_label)'))
)
->where('main_table.entity_type_id=?', $this->getEntityTypeId())
->where('additional_table.used_in_product_listing=?', 1);
// $sql = $select->assemble();
// echo $sql;
return $this->_getReadAdapter()->fetchAll($select);
}
Magento 操作数据库是在 Zend DB(Zend Framework)的基础上简单的做了下封装了。Zend DB 有自己的一套规则,来组合生成最终的SQL查询语句,可以看到上面的代码中有 from() join() joinLeft() where() 等函数,乱七八糟的一大堆东西,需要对 Zend DB的规则非常熟悉,才能知道实际执行的SQL语句,有没有办法直接打印出SQL语句?找了下,还真有,就是assemble()函数。在上面代码中最后部分可以看到。
顺被把SQL也附上来:
SELECT main_table.*,
IFNULL(al.value, main_table.frontend_label) AS store_label
FROM eav_attribute AS main_table
INNER JOIN catalog_eav_attribute AS additional_table
ON main_table.attribute_id = additional_table.attribute_id
LEFT JOIN eav_attribute_label AS al
ON al.attribute_id = main_table.attribute_id AND al.store_id = 1
WHERE (main_table.entity_type_id=’4′)
AND (additional_table.used_in_product_listing=1)
FROM:http://www.sqlstudy.com/article/magento-zend-db-select-sql-output.html
分享到:
相关推荐
magento事件清单
Zend中有个Zend_Filter组件用来实现过滤的功能。其中有个Zend_Filter_Interface子类,该子类为实现一般过滤器提供了接口。 要实现过滤器类,需要实现该接口中一个名为filter()的方法。 下面通过实例来演示如何使用...
dollstore_magento_1.2_weidea.net_BootstrapWordpress前端源码模板_.zip
Chapter 1: Getting Started with Magento 7 Introduction 7 Preparing the development environment 8 Installing Magento with sample data 11 Adding version control
magento首页展示用户设置的新产品模块列表
第一次上传文件,请多多关照。 自己写的magento2中batch压缩图片,以及把压缩文件的原图备份起来。
快速在服务器上复制为另一个站,版本用的是magento,php语言
iwd_m2_checkout_suite_pro_1.6.0
对于首次安装magento过程中出现的问题的小结
magento中文手册 magento教程
magento导出数据sql,magento批量导出数据,magento批量上传数据。
Amasty Advanced Permissions for Magento 2
magento中获得aw_blog博客插件可以获取分类与最近文章,用于新闻设置
Amasty Special Promotions
magento_GB_LP - 来自文件Magento GB 语言包 - /** Magento 英国 (en_GB) 语言包。 基于旧的 Magento 提供的语言文件,这些文件不再可用。 0.2版由 Lightnest 创建 联系 **/
Magento_China_Integration (建议使用内核原始代码,再用modman等模块管理工具加入各个模块,而不是使用本资源一样地将所有代码放在一起。模块代码和内核代码分开做版本管理可以更好地避免修改内核代码) 原始的...
Magento_Versions_Installer 你可能会更好就要去只使用具有Magento的安装程序:
$ git clone https://github.com/IOZ/magento_fe_tools 将文件夹皮肤复制到您的 Magento 项目。 下载 Gulp 依赖项。 通过终端打开你的主题 $ cd skin/frontend/<package>/<theme>/ 它将从package.json加载所有...
magento删除订单sql,通过phpmyadmin清空订单
可与任何Zend Framework项目一起使用,包括所有版本的Magento!特征使用来获得最佳性能(要求master分支或标记版本于2011年8月19日)。 如果无法使用库使用phpredis,则退回到独立PHP。 完全支持标记,使用Redis的...