0

My custom model collection has a database table that contains store_ids value separated by comma like this:

ID | store_ids  |
+++++++++++++++++
 1 |  0,1,3     |
 2 |  1         |
 3 |  0,1       |
 4 |  0,2       |
 5 |  3         |

I'm using this input field to save the store_ids in the backend:

enter image description here

i noticed the 0 value is the default value , and the rest is the specific store ids value. My question is , how can i retrieve by the current store id, and prioritize the record that has the single store id value, for example with store_id = 1 it will retrieve the record with ID 2 ?

i tried this, but this filter can not give the specific store_id as first priority :

     ->addFieldToFilter(
              'visible_stores',
              [
                  [
                      array('like' => '%'.$this->getStoreId().'%')
                  ],
                  [
                      array('like' => '%0%')
                  ]
              ]
          );
3
  • Can you please upload your code what you have tried? Sep 1 '20 at 4:19
  • @RohanHapani done
    – jojo
    Sep 1 '20 at 4:23
  • which code you are using to show the store list in admin configuration? Sep 1 '20 at 6:09
0
->addFieldToFilter(
              'visible_stores',
              [
                  [
                      array('finset' => $this->getStoreId())
                  ],
                  [
                      array('like' => '%0%')
                  ]
              ]
          );

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.