How to Build an SQL Query for Products with Custom Options in Magento

custom-optionsquerysql

Need help making a query which returns the Product ID of all products which have custom options

Best Answer

Magento:

$options = Mage::getModel('catalog/product_option')->getCollection();
$options->addFieldToSelect('product_id');
$options->getSelect()->distinct(true);

foreach ($options as $option) {
    Zend_Debug::dump($option->getProductId());
}

Query:

SELECT DISTINCT `main_table`.`product_id` FROM `catalog_product_option` AS `main_table`
Related Topic