I am trying to delete custom options in a data install script. I have a list of product IDs and I am looping through them like this:

foreach ($productIds as $productId) {
    $product = Mage::getModel('catalog/product')->load($productId);
    $oldOptions = $product->getOptionInstance()->getOptions();
    foreach ($oldOptions as $key => $option) {
        $oldOptions[$key]['is_delete'] = 1;

The problem is, $oldOptions is always an empty array. I know for a fact that the products in question have custom options set. When I run it through a debugger, I can see that the _options property on the product is populated correctly.

I have a query I can use to delete the options from the database, but that makes me a bit nervous since I'm not 100% clear on how that will affect the product (i.e., what type of lifecycle methods may not be skipped by doing a direct SQL delete).

  • what happens when you simply call $product->getOptions() Feb 24 '15 at 13:45
  • It returns an array of Mage_Catalog_Model_Product_Option[s], as opposed to a straight PHP array. But, when I call saveOptions(), I get an exception since it's not expecting a Mage_Catalog_Model_Product_Option object. I'm wondering if it has something to do with the lifecycle? I was using this question as a start: magento.stackexchange.com/questions/9480/…
    – Laura
    Feb 24 '15 at 20:13
  • Hi @Laura, any news on your question? How did you finally solve it? Mar 24 '15 at 14:38
  • I ended up going with the brute force SQL query method :)
    – Laura
    Mar 25 '15 at 21:02