Question

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)?

Was it helpful?

Solution

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).

OTHER TIPS

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top