2

I'm trying to fetch a product collection by custom attribute:

hidden_countries

The products will be saved in the backend with this attribute, which is a multi-select field. So there will be comma separated values like AE,ES,DK. The product will be hidden in these countries. If the user is browsing from any of these countries the product will not be displayed.

I have the current country code of user browsing from:

$current_country = 'AE';

While I'm trying to filter attribute, I cannot filter the product collection as per my requirement. I tried:

....
....
->addAttributeToFilter('hidden_countries', array('nin'=>array('finset'=>$current_country)));

Don't know how to check !finset.

Magento 1.9

EDIT

Example : The database field(hidden_countries ) will hold the value as : 'AE,DK,US,ES' etc Current country based on IP address : 'DK'

i don't want to select the row(s) that have DK in the field(hidden_countries)

1

Try to use addAttributeToFilter with or condition

$collection->addAttributeToFilter('hidden_countries',
    array(
        array('finset'=> array('AF')),
        array('finset'=> array('IN')),
        array('finset'=> array('UK')),
    )
);

Or

$collection->addAttributeToFilter(
    array(
        array('attribute'=> 'hidden_countries','finset' => array('AF')),
        array('attribute'=> 'hidden_countries','finset' => array('IN')),
        array('attribute'=> 'hidden_countries','finset' => array('UK')),
    )
);
  • Pardon for my unclear question. What i actually need is like this : WHERE FIND_IN_SET('AE',hidden_countries.value) = 0 – Shan Aug 22 '16 at 8:00
  • im unable to solve this problem !, what i had done so far is filtered using nlike(%$country_code%), which will work perfectly, since all the country codes are two lettered & have no duplicates – Shan Aug 28 '16 at 10:17

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.