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?

Aasim Goriya
5,4622 gold badges30 silver badges54 bronze badges
asked Jul 8, 2019 at 7:45

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)));
answered Jul 8, 2019 at 7:52
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

answered Jul 8, 2019 at 8:38
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]);
answered Jul 8, 2019 at 9:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.