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.
Answering the question
Please tell me which action or controller is called when this button is pressed, or any other method to overcome this problem is appreciated.
To observe the initial creation of a product you can observe the catalog_product_new_action
.
It sounds like you're trying to prevent certain products from being manipulated by your observer. If this is the case, I would recommend that you create an attribute that is Yes/No that enables/disables the the AutoMetaDescription function. Just check the value of the attribute before manipulating the product.