4

Hi guys i have a collection in which i add custom data to. I am then trying to filter the collection by one of the original fields but it doesn't seem to work.

Here is my collection building code:

$collection = $this->getCollection();
$collection->getSelect()->join(
    'sales_flat_order',
    'sales_flat_order.entity_id = main_table.magento_order_entity_id',
    array('increment_id')
);

foreach($collection->getItems() as $item){
    $status = $this->getState($item->getId());
    $item->addData(array('response_state' => $status));
 }

return $collection;

This builds the collection successfully but when i try to use addFieldToFilter() to the collection it doesn't filter at all.

Here is the filter code:

->addFieldToFilter('is_successful', array('eq' => $value));

Anyone know why and how i can get this to work? Cheers

1
  • Try using $item->setResponseState($status) and ->addFieldToFilter('is_successful', $value) instead.
    – laketuna
    Jun 27, 2015 at 2:25

1 Answer 1

3

Where exactly are you trying to use addFieldToFilter, also are you sure you shouldn't use addAttributeToFilter? Finally take a look at the query that is generated doing this.

$collection->getSelect()->__toString();

addAttributeToFilter() is used to filter EAV collections.

addFieldToFilter() is used to filter Non-EAV collections.

Check here for more details: https://magento.stackexchange.com/a/8581/5913

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.