1

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

["1","2","8","3","4","5"]

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

3 Answers 3

0

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

Try This :

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

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

0

Try this code regarding my friend RK

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

     Or

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

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.