This extension I made works fine when I save the product. It simply adds the custom options.
Here is config.xml
<?xml version="1.0"?>
<config>
<modules>
<Custom_Options>
<version>0.0.1</version>
</Custom_Options>
</modules>
<global>
<models>
<custom_options>
<class>Custom_Options_Model</class>
</custom_options>
</models>
</global>
<adminhtml>
<events>
<catalog_product_save_before><!-- observe the event -->
<observers>
<custom_options>
<class>custom_options/observer</class>
<method>autoMetaDescription</method>
</custom_options>
</observers>
</catalog_product_save_before>
</events>
</adminhtml>
</config>
Observer.php
<?php
class Custom_Options_Model_Observer {
public function autoMetaDescription($observer) {
$product = $observer->getEvent()->getProduct();
//check that we haven't made the option already
$options = $product->hasCustomOptions();
if( $product->getData('has_options') && ($product->getTypeID() == 'simple')){
} else
{
$option6 = array(
'title' => 'Hardware Finish',
'type' => 'drop_down',
'is_require' => 1,
'sort_order' => 4,
'is_delete' => '',
'previous_type' => '',
'previous_group' => '',
'price' => '0.00',
'price_type' => 'fixed',
'sku' => '',
'values' => array(
array(
'is_delete' => 0,
'title' => 'Black Nickel',
'price_type' => 'fixed',
'price' => 0,
'option_type_id' => -1,
)
);
//don't use it like this because it has no effect
//$product->setProductOptions($options);
$product->setCanSaveCustomOptions(true);
$product->getOptionInstance()->addOption($option6);
//don't forget to state that the product has custom options
$product->setHasOptions(true);
//$product->save();
}
}
}
Basically there are some products which doesn't have custom options but it always adds options to them too. I think there's a way to overcome this problem is to use action called when creating a product. As In this image
Please tell me which action or controller is called when this button is pressed, or any other method to overcome this problem is appreciated.