I have a simple need which is that I hae a custom product type and that product needs options attached to it. I need these options to be editable and removable so I'm going to use what is built in. I have the observer working and the method is being fired. When I do a var_dump($product);die();
I can search for the title of the sample custom option and find that it is apart of the output. When I get to the new product page I am not seeing the options. This is what I have.
public function catalog_product_new_action($observer) {
//check that we haven't made the option already
$product = $observer->getEvent()->getProduct();
$options = $product->getOptions();
if ($options){
foreach ($options as $option) {
if ($option['title'] == 'Auto Date & Time' && $option['type'] == 'date_time' && !$option['is_delete']) {
//we've already added the option
return;
}
}
}
$option = array(
'title' => 'Auto Date & Time',
'type' => 'date_time',
'is_require' => 1,
'sort_order' => 0,
'is_delete' => '',
'previous_type' => '',
'previous_group' => '',
'price' => '0.00',
'price_type' => 'fixed',
'sku' => ''
);
$product->setProductOptions(array($option));
$product->setCanSaveCustomOptions(true);
$product->setHasOptions(true);
$product->save();
}
It is close, but it's not displaying on the back end. What I don't want to do is force a user to save the product and then auto generate the options after the fact, so I'm not wanting to use any of the on saves events and why I am using that catalog_product_new_action
event
Update
It is worth noting that the save ( $product->save();
) will save an empty product but it will not be used when you are landing on the next leg of a new product after choosing the type ( admin/product/new/type/#/
).