title: Adding custom option to a product programatically in custom module frontend controller?
body: <p>i am trying to add product from frontend programatically following this link :</p>
  
  <p><a href="https://stackoverflow.com/questions/6735506/magento-adding-new-products-programmatically">Magento: Adding new products programmatically</a></p>
  
  <p>but i want to extend it to add custom options too to it .And i added the following code to it</p>
  
  <pre><code>$options = array();
          $options[$sku] = array(
          'title' =&gt; 'Option Title',
          'type' =&gt; 'radio',
          'is_require' =&gt; 1,
          'sort_order' =&gt; 0,
          'values' =&gt; array()
          );
          $options[$addvp['product']['sku']]['values'][] = array(
          'title' =&gt; 'Option Value 1',
          'price' =&gt; 0.00,
          'price_type' =&gt; 'fixed',
          'sku' =&gt; '',
          'sort_order' =&gt; '1'
          );
          $options[$sku]['values'][] = array(
          'title' =&gt; 'Option Value 2',
          'price' =&gt; 89.00,
          'price_type' =&gt; 'fixed',
          'sku' =&gt; '',
          'sort_order' =&gt; '1'
          );
  
      foreach($options as $sku =&gt; $option) {
          $id = Mage::getModel('catalog/product')-&gt;getIdBySku($sku);
          $product = Mage::getModel('catalog/product')-&gt;load($id);
  
          if(!$product-&gt;getOptionsReadonly()) {
          $product-&gt;setProductOptions(array($option));
          $product-&gt;setCanSaveCustomOptions(true);
          //$product-&gt;save();
          }
      }
  </code></pre>
  
  <p>but it prints this error instead of adding custom option to product.     </p>
  
  <pre><code>SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`vendor`.`catalog_product_entity`, CONSTRAINT `FK_CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_ID` FOREIGN KEY (`attribute_set_id`) REFERENCES `eav_attribute_set` (`attribute_set_id`) ON DEL)
  </code></pre>