Return to Snippet

Revision: 49702
at July 28, 2011 07:43 by necode


Initial Code
$collection->addAttributeToFilter('field_name', array(
        'in' => array(1, 2, 3),
        ));
     
    $collection->addAttributeToFilter('date_field', array(
       'from' => '2000-09-10',
        ));
     
    $collection->addAttributeToFilter('date_field', array(
        'from' => '10 September 2000',
        'from' => '11 September 2000',
        'date' => true, // specifies conversion of comparison values
        ));
     
    $collection->addAttributeToFilter('field_name', 1); // tests for equality
     
    // Add OR condition:
    $collection->addAttributeToFilter(array(
        array(
            'attribute' => 'field_name',
            'in'        => array(1, 2, 3),
            ),
        array(
            'attribute' => 'date_field',
            'from'      => '2000-09-10',
            ),
        ));

Initial URL
http://www.magentocommerce.com/wiki/5_-_modules_and_development/catalog/using_collections_in_magento

Initial Description
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.

Initial Title
Magento Using Collections, Filters and Manipulation Methods

Initial Tags
magento

Initial Language
PHP