I have a custom eav structure and there is store_id save in array format in the database field.

I need to filer collection with addFieldToFilter with store_id.

$collection = $this->xyzCollectionFactory->create();
$collection->addFieldToFilter('store_id', ['in' => $this->storeManager->getStore()->getId()]);

Datastore in the database below format


this filter is not working, anyone has an idea how can I do that?


Reference Link :- https://fishpig.co.uk/magento/tutorials/addattributetofilter/

Try This :

$storeId[] = $this->storeManager->getStore()->getId();
addAttributeToFilter('store_id', array('in' => array($storeId)));
| improve this answer | |
  • its not working – Yogesh Jul 8 '19 at 8:13
  • please explain briefly what type of data you want and which format of data – Rk Rathod Jul 8 '19 at 8:15
  • Its quite clear, i need to match value of field, which field value store in array format in database. – Yogesh Jul 8 '19 at 8:19
  • you mean data store in array format ? – Rk Rathod Jul 8 '19 at 8:21
  • please attach example of your data format – Rk Rathod Jul 8 '19 at 8:22

First of all, check that store_id field create in your custom table or not. If yes, then make sure that you extend Magento\Eav\Model\Entity\Collection\AbstractCollection class in your collection file.

For more reference : click here

| improve this answer | |

Try this code regarding my friend RK

     $storeIds = array();
     $storeIds[] = 1; //store id
     $collection = $this->xyzCollectionFactory->create();
     $collection->addFieldToFilter('store_id', ['in' => (array)$storeIds]);


     $storeId = 1;
     $collection->getSelect()->where('main_table.store_id in (?)', [0, $storeId]);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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