I have created a new Product Type and have created a new tab to specify the details of the product type. Now what i am try to do is dynamically create some custom options upon saving based on the details of the product.
This is what i have tried. I put the following inside product/type.php inside save()
public function save($product = null)
{
//get $myProductDetails
$product = $this->getProduct($product);
foreach($myProductDetails as $fieldName){
$opt = Mage::getModel('catalog/product_option');
$opt->setProduct($product);
$values = array(
'title' => $fieldName,
'type' => 'field',
'is_require' => true
);
$product->setHasOptions(1);
$opt->setData($values);
$opt->saveOptions();
$product->addOption($opt);
}
parent::save($product);
}
Now when i debug i see that the options have been added to the $product variable before saving, but after saving when i go to edit the product i do开发者_如何学Gont see these options in the custom options tabs.
Figured out the solution this helped. Posting here if it helps someone. I had to use
$opt->addOption($values);
instead of
$opt->setData($values);
精彩评论