集合是一个包含其他型号的机种型号,它基本上是用在Magento处理的产品清单(即从类别或捆绑选项),但不是唯一的。 TO DO:解释如何Magento的实现集合 – 使用此解释如何Magento的实现代码模型中的一个集合,使人们可以学会写自己的藏品 这是一个简单的例子,加载一些产品集合从一个类别,并命令他们在自己的产品名称使用Magento的API的。
$collection = Mage::getModel('catalog/category')->load($categoryId)
->getProductCollection()
->addAttributeToSort('name', 'ASC');
使用多个字段排序,您可以调用链接到该集合的方法 addAttributeToSort(preferred)
$collection = Mage::getModel('module/model_name')->getCollection()
->addAttributeToSort('order', 'ASC')
->addAttributeToSort('last_name', 'ASC')
->addAttributeToSort('first_name', 'ASC')
TODO:使用Magento的API使用的情况下,不是Zend_Db_Select的。 您也可以通过IF/THEN语句,但一定要使用正确引用表的字段。
$collection = Mage::getModel('module/model_name')->getCollection();
$collection->getSelect()->order( array('IF(`order`>0, `order`, 9999) ASC',
'last_name ASC', 'first_name ASC') );
在此示例中,将按顺序字段,排序表然后按上次的名称,然后按名字、 凡订单是否大于零,是秩序正在小于或等于零,所有升序。 联接表 若要添加 SQL 联接到选择
$collection = Mage::getModel('module/model_name')->getCollection();
$collection->getSelect()->join( array('table_alias'=>$this->getTable('module/table_name')), 'main_table.foreign_id = table_alias.primary_key', array('table_alias.*'), 'schema_name_if_different');
在此示例中的联接方法采用 alias⇒table_name 密钥对,然后使用 main_table 引用原始的选择中,标准的 join 子句的数组然后在联接中要检索的字段的数组 (默认为 *),可以作为最后一个参数指定不同的架构。 复审 → 默认为内部联接,其他人可以使用: →joinInner() →joinLeft() →joinRight() →joinFull() →joinCross() →joinNatural()
请参阅 lib/Zend/Db/Select.php 的源码。 |

ecshop抽奖插件免费送出
人气:5881
ecshop仿米奇网化妆品2014网
人气:549
ecshop简洁通用外贸模板
人气:1429
ecshop仿bianli100便利商城模
人气:5637
免费某ecshop商ecshop微信商
人气:21709
2012最佳办公用品商城程序
人气:1030