Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

special condition for collection
 
tman_f
Sr. Member
 
Total Posts:  85
Joined:  2008-02-12
 

I have created a custom EAV entity model, and extended Mage_Eav_Model_Entity_Collection_Abstract. i am trying to call results according to specific conditions. I have been using the common filter methods that allow me to declare an attribute with the desired value.

I would like to do a little more, for instance: ‘attribute’ > ‘value’, or ‘attribute’ LIKE ‘&#xva;lue%’.

With the methods that have been provided, is there any way to do this, or will I have to create my own low level join/filter methods?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
tman_f
Sr. Member
 
Total Posts:  85
Joined:  2008-02-12
 

nevermind, I found what I was looking for. Incase anybody runs into this same thing, here is what I have found:

$collection->addAttributeToFilter("attribute", array("like"=>"value%");

Seems to do the trick;

thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
tman_f
Sr. Member
 
Total Posts:  85
Joined:  2008-02-12
 

Apparently I have been mistaken. This seems to work with “LIKE” and “=”. However, any other operands seem to revert to “=”. For instance:

$collection->addAttributeToFilter("attribute", array(">" => 20));

This wont return records where “attribute” is greater than 20, but only records where “attribute” is equal to 20.

Any ideas?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
tman_f
Sr. Member
 
Total Posts:  85
Joined:  2008-02-12
 

Again, nevermind I traced the issue down. It was rather silly of me to think that an associative array would contain special characters for keys.

There are corresponding codes for each operand, found in Varien_Db_Collection.

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
metnor
Jr. Member
 
Total Posts:  10
Joined:  2008-09-02
 

thank you very much it helped me a lot.. and saved lotssss of time.

 
Magento Community Magento Community
Magento Community
Magento Community
 
cnrx
Member
 
Total Posts:  34
Joined:  2008-07-24
 

Fixed!
Thanks a lot!

Here’s the location of the file:

/lib/Varien/Data/Collection/Db.php

and here’s a list of what it takes (1.1.8):

/*
  eq  =
  neq  !=
  like  LIKE
  nlike  NOT LIKE
  in  IN
  nin  NOT IN
  is  IS
  notnull  NOT NULL
  null  NULL
  moreq  >=
  gt  >
  lt  <
  gteq  >=
  lteq  <=
  finset  FIND_IN_SET
*/

I hope this helps someone else.

smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top