11

I have a series of products with custom options of type checkbox. However I cannot set from the setup of the product the default state of that particular option.

I need at least one of the checkboxes (options) to be checked by default as the user enters the product page / adds to cart from category page.

Is this doable from the Magento administration or will it require some extra development (if so how this can be done)?

  • Cant you just set "is default" under Catalog -> Manage Attributes -> "Your Attribute" -> Manage Label / Options -> right next to your default option .... or if you use Input Type "yes/no" you can set default value under attribute properties – Stefan Gregori Jan 16 '14 at 11:20
  • Actually the options right now are set up with "Custom options" from the product page in admin. Your suggestion is to transform that into product attributes? Would it keep the same behavior for the product price? – Mike Jan 16 '14 at 17:15
16
+25

I don't know if recommending an extension counts as a valid answer (for a question with a bounty) but someone claims here that he wrote an extension that does exactly what you need. Extension can be downloaded from here. I haven't tested it but, as soon as I do, I will post and update. I only looked through the code and there is a lot of it. I lost interest after 2 files. I hope it works for you.

[EDIT]
I've got my interest back. I tested the extension on and it (almost) works.
If you use it with developer mode on you will get some errors. Here is what you need to change to make it work.
in /app/code/local/Magebuzz/Customoption/controllers/Adminhtml/CustomoptionController.php on line 28 there is this:

$model->setData('value['.$option_id.']',$value[0]['option_type_id']);

This shows an 'undefined index' warning. To avoid it, wrap it in an if statement.

if (isset($value[0])){
    $model->setData('value['.$option_id.']',$value[0]['option_type_id']);
}

In /app/code/local/Magebuzz/Customoption/Block/Adminhtml/Customoption/Edit/Tab/Form.php on line 129 there is this:

foreach ($values as $value) {
    $valuesArr[$value['option_type_id']]=$value['title'];
}

$values may be null so change the code to this:

if (is_array($values)){
    foreach ($values as $value) {
        $valuesArr[$value['option_type_id']]=$value['title'];
    }
}

Now it should work.
Now some review.

  1. PRO. Works perfectly for dropdown and radio custom options
  2. Neurtal. Kind of works for multiple select and checkbox custom options. You can select only one value for the available values.
  3. Inconvenient but I can overlook it. in order to set the default values you have to click on an other menu item in the backend and look for your product in the list.
  4. Con. It doesn't work for text, textarea, date, datetime, time, file custom options. But with a little work it can be changed to work correctly for all types (maybe except file).
1

Not default in Magento.

Can be achieved this way. Best to take back up before proceeding.

$option = array(
    'title' => 'Your custom option title',  
    'type' => 'checkbox', // could be drop_down ,radio , multiple
    'is_require' => 1,
    'sort_order' => 0,
    'values' => getOptions()
    );

function getOptions(){
  return array(
     array(
       'title' => 'Option Value 1',
       'price' =>100,
       'price_type' => 'fixed',
       'sku' => 'any sku for 1',
       'sort_order' => '1'
    ),
    array(
       'title' => 'Option Value 2',
       'price' =>100,
       'price_type' => 'fixed',
       'sku' => 'any sku for 2',
       'sort_order' => '1'
    ),
  array(
       'title' => 'Option Value 3',
       'price' =>100,
       'price_type' => 'fixed',
       'sku' => 'any sku for 3',
       'sort_order' => '1'
    )

); }

//Suppose we are creating a new product.

$product = Mage::getModel('catalog/product');
$product->setProductOptions(array($option));
$product->setCanSaveCustomOptions(true);

//Or if we are adding the options to a already created product.

$product = Mage::getModel('catalog/product')->load($id);
$product->setProductOptions(array($option));
$product->setCanSaveCustomOptions(true);

//Do not forget to save the product

$product->save();
  • This is a nice explanation on how to create by code custom options for a product, but I don't think it answers the question. The OP asked how can you set default values for custom options. – Marius Jan 22 '14 at 7:25

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.