Today I had the task to fetch all products from my product collection in Magento which had a specific custom option. After some trial and error, I came up with the following and decided to share this with my audience:
How to get all products with a custom option called ‘FooBar’:
$products = Mage::getModel('catalog/product')->getCollection();
/* @var $products Mage_Catalog_Model_Resource_Product_Collection */
$products->joinTable('catalog/product_option', 'product_id=entity_id', array('main_option_id' => 'option_id'));
$products->joinTable('catalog/product_option_title', 'option_id=main_option_id', array('option_title' => 'title'));
Visitors give this article an average rating of 3.5 out of 5.
How would you rate this article?
★ ★ ★ ★ ★