Suppose, you have a product collection and you want to filter it by category. Suppose, you want to filter it by more than one category. You can use addCategoryFilter if you have only one category. But, what if you want to filter by more than one category?
Looking for improvement for your Magento Store?
Facebook Connector Extension
Product related article extension
Magento Offer popup on exit extension
Unlimited Slideshow Magento Extension
Light Checkout in One Step Magento Extension
Category ids are stored for product in a comma separated way. So, to filter product collection by more than one category, you have to use:
$categoryIds can be a single category id or comma separated category ids.
The following code filters product collection by two category ids (36 and 37).
finset does so… when we use finset, the mysql function find_in_set is used in the sql query by Magento.
mysql function find_in_set:
FIND_IN_SET() looks for the first occurrence of a string within another string containing comma-separated values.
SELECT FIND_IN_SET(‘b’,’a,b,c,d’); // result = 2