7

I am having custom options created for the products. I need to set some option as default for the custom option so that when user checks on the front end default option will be seen instead of "Please Select".

enter image description here

I found one Extension default state of custom option for simple products

But I am looking for if I can show at the place where I am creating the options.

4

Go to Mage/Catalog/Block/Product/View/Options/Type/Select.php::getValuesHtml()

Comment (in line no 59) the addOption part of

$select->setName('options['.$_option->getid().']');
                ->addOption('', $this->__('-- Please Select --'));

i.e.

/* ->addOption('', $this->__('-- Please Select --')); */

Hope this solves your issue.

  • Great idea. I just did this and it worked like a charm. I was looking at an extension that is $699 that does that (plus a little extra). Then, all you need to do is change the "order" of the values under the custom options. Thank you! – NotJay Jul 6 '15 at 18:58
  • I made main product with 0 price, and all the custom product with actual price, Your option is real good to set default option in product details page, how about grid page, i am getting price 0, is there any option to update there? – manny Jan 11 '16 at 12:54
  • not sure why experts like you will post one answer and dont reopen site at all, community need guys like you..... – Baby in Magento Jan 12 '17 at 11:45
0

I suppose you have the product in that form:

    $product = Mage::getModel('catalog/product');

    $product->setWebsiteIds(array(1));//Your website id
    $product->setAttributeSetId(9);//Your attribute code

    $product->setName('A name');
    .
    .
    more attributes you want to set.

After that you need this code:

$optionInstance = $product->getOptionInstance()->unsetOptions();
$product->setHasOptions(true);

$optionInstance->addOption($this->makeCustomOptions());
$product->setCanSaveCustomOptions(true);
$optionInstance->setProduct($product);

$product->save();


protected function makeCustomOptions(){

        return $option = array(
            'title' => 'Licenses',
            'type' => 'drop_down',//That can be checkbox and more
            'is_require' => 0,//1 if required

            'values'=>array(//These are the options
                array(

                    'title'             => "30 Days",
                    'price'             => -5,
                    'price_type'        => "fixed",
                    'sku'               => "30"
                ),
                array(

                    'title'             => "365 Days",
                    'price'             => -3,
                    'price_type'        => "fixed",
                    'sku'               => "365"
                ),
                array(

                    'title'             => "730 Days",
                    'price'             => -2,
                    'price_type'        => "fixed",
                    'sku'               => "730"
                )
            )

        );
    }

And that's it.You can change whatever you want..

  • vbak, it doesn't answer a question. Pradeep asked how to choose one custom option as default to avoid having "Please Select" in frontend field. – Wojtek Naruniec Dec 8 '14 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.