Magento Collections conditional statements overzicht

Komt rechtstreeks uit /lib/Varien/Data/Collection/Db.php (_getConditionSql()).

Voorbeeldje;

[php]$products = Mage::getModel(’catalog/product’)->getCollection(); $products->addAttributeToFilter(’entity_id’,
array(’in’=> array(1,2,36,35) )
);
$products->load();[/php]

Extragratis tip; om de daadwerkelijke query te zien, doe je $products->load(true);. Ook handig is de exportToArray() functie om zo snel een 2D array van je object te maken.

* Build SQL statement for condition
*
* If $condition integer or string – exact value will be filtered (‘eq’ condition)
*
* If $condition is array – one of the following structures is expected:
* – array(“from” => $fromValue, “to” => $toValue)
* – array(“eq” => $equalValue)
* – array(“neq” => $notEqualValue)
* – array(“like” => $likeValue)
* – array(“in” => array($inValues))
* – array(“nin” => array($notInValues))
* – array(“notnull” => $valueIsNotNull)
* – array(“null” => $valueIsNull)
* – array(“moreq” => $moreOrEqualValue)
* – array(“gt” => $greaterValue)
* – array(“lt” => $lessValue)
* – array(“gteq” => $greaterOrEqualValue)
* – array(“lteq” => $lessOrEqualValue)
* – array(“finset” => $valueInSet)
* – array(“regexp” => $regularExpression)
* – array(“seq” => $stringValue)
* – array(“sneq” => $stringValue)
*
* If non matched – sequential array is expected and OR conditions
* will be built using above mentioned structure
*