2

How do i set my radio button custom option to a default value? Now nothing is selected by default.

I suspect I can add or change something in -->

Mage/Catalog/Block/Product/View/Options/Type/Select.php?

Manashvi Birla
8,8739 gold badges29 silver badges53 bronze badges
asked Jul 7, 2015 at 20:16
1

2 Answers 2

5

Yes you are correct, the custom options are rendered from the file app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php

To set a set a radio button custom option to a default value, write this code

if($_value->getTitle() == 'Title_of_your_custom_option')
{
 $checked = 'checked';
}

before the below code

$selectHtml .= '<li>' . '<input type="' . $type . '" class="' . $class . ' ' . $require
 . ' product-custom-option"'
 . ($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"')
 . ' name="options[' . $_option->getId() . ']' . $arraySign . '" id="options_' . $_option->getId()
 . '_' . $count . '" value="' . $htmlValue . '" ' . $checked . ' price="'
 . $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false) . '" />'
 . '<span class="label"><label for="options_' . $_option->getId() . '_' . $count . '">'
 . $_value->getTitle() . ' ' . $priceStr . '</label></span>';
answered Jul 8, 2015 at 5:24
4
  • I got it working, but it seems to add a (new) third option which is then checked by default. So, almost there, but I cannot see what I'm doing wrong. Commented Jul 8, 2015 at 11:45
  • post your code here or else try my solution, It works perfectly for me and it wont add a new option Commented Jul 8, 2015 at 11:46
  • Not sure how to post that much code, but you can download the file from here (just change .zip to php or txt) link Commented Jul 8, 2015 at 11:55
  • You added the code at the wrong place. look at my answer. i have specified before which $selectHtml to add the code Commented Jul 8, 2015 at 12:11
0

If you have a place to put some JavaScript, you could also check the first radio button in all of these option lists:

$('.options-list').find('input[type=radio]').first().prop('checked','checked');
answered May 2, 2017 at 7:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.