2 Comments

filter product collection by a comma-separated attribute [duplicate]

How to update attribute in SOAP v2?
Varien_Http_Client: getQuery() returns nothing

This question already has an answer here:

Related Posts

How to update attribute in SOAP v2?
Varien_Http_Client: getQuery() returns nothing

2 Comments on this article

  • User November 12, 2016

    You can convert your school ids to array and then apply the filter.

    $schoolid = '11,12,13,18'; //the schoolid attribute for a given product
    $schoolIds = explode(',', $schoolid);
    
    $collection
        //->addFieldToFilter('schoolid', '13');
        ->addFieldToFilter('schoolid', array('in' => $schoolIds));
    

    This should do the trick for you.

    UPDATE

    If schoolid is a attribute type then filter collection like this:

    $collection
        //->addFieldToFilter('schoolid', '13');
        ->addAttributeToFilter('schoolid', array('in' => $schoolIds));
    

    Reply

  • User November 12, 2016
    addAttributeToFilter() is used to filter EAV collections.
    
    addFieldToFilter() is used to filter Non-EAV collections.
    

    http://fishpig.co.uk/magento/tutorials/addattributetofilter/

    $collection->addAttributeToSelect('*');
    

    n – in

    $collection->addFieldToFilter('schoolid',array("in"=>array('11', '12', '13','18')))
    

    Not In – nin

    $collection->addFieldToFilter('schoolid',array("nin"=>array('11', '12', '13','18')))
    

    Reply

Add a comment