tags:

views:

175

answers:

1

hi,

i had to add custom options automatically when a product is added , the code works fine but i need to create a drop down menu with options and i dont know how to add options to the drop down created , my code is

public function Add_CustomOptions_Automatically($observer) {
    $product = $observer->getEvent()->getProduct();
    $save = false; if (!$product->getOptions()) $save = true;

    $optionData = array(
        'previous_group'    => 'text',
        'title'             => 'Size',
        'type'              => 'drop_down',
        'is_require'        => 0,
        'sort_order'        => 0,
        'price'             => 0,
        'price_type'        => 'fixed');    


    if($save):
        $product->setHasOptions(1)->save();
        $option = Mage::getModel('catalog/product_option')
                    ->setProductId($product->getId())
                    ->setStoreId($product->getStoreId())           
                    ->addData($optionData);

        $option->save();
        $product->addOption($option);
    endif;
}

}

I've created 'type' => 'drop_down' but how can I add options? I have no idea how to add the options, and any help would be very much appreciated.

thanks,

A: 

I am looking for the same exact info. Although I get this error

Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat::getAttribute() in D:\xampp\htdocs\www\laptops-pakistan\app\code\core\Mage\Catalog\Model\Resource\Eav\Mysql4\Url.php on line 354

Unless i change line $product->setHasOptions(1)->save(); to $product->setHasOptions(1);

So does anyone has a solution. BTW, have a look at this URL

http://subesh.com.np/2009/12/adding-custom-options-product-magento/

Thanks

nadshez