magento中的joinAttribute joinField
来源:互联网 发布:今年双11淘宝交易额 编辑:程序博客网 时间:2024/06/07 01:48
通常我们使用Mage::getModel('catalog/product')->getCollection()能够获取到产品集。
在这个产品集中,只包含了table catalog_product_entity
中的字段,但是很多时候我们都需要更多的字段,比如产品price,qty等;
一般情况下,我们会这样做:
$collection = Mage::getModel('catalog/product')->getCollection();$collection->addAttributeToSelect('filedname');//此处product为EAV模型,可使用addAttributeToSelectforeach($collection->getAllIds() as $id){ $prod= Mage::getModel('catalog/product')->load($id)->getData();//此时的prod包含了EAV模型中的所有属性}
实际上,上面虽然能获取产品的所有属性,但是在你的product有上万条的时候,就会严重影响性能了。或许你会说用下边的code也可以:
$collection->addExpressionFieldToSelect('filedname', "{{filedname}}", array('filedname' => 'filedname'));$collection->getSelect()->joinLeft('tablename','e.entity_id=`tablename`.entity_id','');不错,虽然可以得到你想要的属性,但是这仅仅限于系统属性,如qty,因为我们知道qty是存储于table cataloginventory_stock_item中的,但是
magento中又很多自定义属性,是采用EAV模型存储的,所以上面的方法也不可行了。
还好有 joinAttribute joinField这两个function解决了上面的问题。
比如我想将name添加到collection中
$collection->joinAttribute('name','catalog_product/name', 'entity_id', 'entity_id','left', 0);就可以了,将qty添加到collection中
$collection->joinField('qty', 'cataloginventory/stock_item','qty','product_id=entity_id', '{{table}}.stock_id=1','left');就可以了。
joinAttribute 用来添加EAV模型中的Attribute ,只要在table eav_attribute中能找到的attribute_code都可以在这里使用!
转载请注明出处!
- magento中的joinAttribute joinField
- magento中的attribute 总结
- magento中的启用https
- magento中的block
- Magento中的load()方法
- MAGENTO中的标签(TAGS)
- 安装Magento过程中的问题
- magento collection中的or条件
- magento SEO -- 删除掉magento URL中的session id字符串
- Magento
- magento
- 如何删除magento中的所有的订单
- magento 去掉网址 url 中的 index.php
- Magento 1.4 EAV 属性中的新东西
- Magento中的所见即所得插件 - Fontis WYSIWYG Editor
- 如何处理magento模版中的广告模块
- magento 去掉网址url中的index.php
- 在magento CMS中的标签变量使用
- 80386保护模式编程模型
- 手动进行释放内存的API
- jquery 实现input宽度自适应
- Oracle 高级SQL
- SICP Exercise 3.52
- magento中的joinAttribute joinField
- AJAX 跨域访问 — 方法大全
- 搭建OLAP系统新方法
- 疯狂Android讲义
- filenet小结
- 来源域名。
- 补码的由来
- 有用的linux 命令
- Spring小结