使用集合过滤器和操作方法的Magento

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用集合过滤器和操作方法的Magento相关的知识,希望对你有一定的参考价值。

A collection is a Model type containing other Models, it is basically used in Magento to handle product lists (ie. from a category or a bundle option), but not only.

TO DO: Explain how Magento Implements a collection - Use this to explain how Magento implements a collection by looking at code in a model, so that people can learn to write their own collections

This is a simple example of loading some product collection from a category and ordering them on their product name using Magento’s API.
  1. $collection->addAttributeToFilter('field_name', array(
  2. 'in' => array(1, 2, 3),
  3. ));
  4.  
  5. $collection->addAttributeToFilter('date_field', array(
  6. 'from' => '2000-09-10',
  7. ));
  8.  
  9. $collection->addAttributeToFilter('date_field', array(
  10. 'from' => '10 September 2000',
  11. 'from' => '11 September 2000',
  12. 'date' => true, // specifies conversion of comparison values
  13. ));
  14.  
  15. $collection->addAttributeToFilter('field_name', 1); // tests for equality
  16.  
  17. // Add OR condition:
  18. $collection->addAttributeToFilter(array(
  19. 'attribute' => 'field_name',
  20. 'in' => array(1, 2, 3),
  21. ),
  22. 'attribute' => 'date_field',
  23. 'from' => '2000-09-10',
  24. ),
  25. ));

以上是关于使用集合过滤器和操作方法的Magento的主要内容,如果未能解决你的问题,请参考以下文章

Magento模型集合addFieldToFilter常用过滤条件

过滤 Magento 集合而不是产品,使用 distinct

如何过滤日期的Magento集合或null

Magento JOIN 在两个过滤的自定义集合之间

markdown [magento] - 代码片段

在设置页面限制之前加载Magento 2集合