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?
-
Check this link magento.stackexchange.com/questions/12902/…MeenakshiSundaram R– MeenakshiSundaram R2015年07月07日 23:04:27 +00:00Commented Jul 7, 2015 at 23:04
2 Answers 2
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>';
-
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.Tijdschriftenzo– Tijdschriftenzo2015年07月08日 11:45:17 +00:00Commented 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 optionManashvi Birla– Manashvi Birla2015年07月08日 11:46:02 +00:00Commented 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) linkTijdschriftenzo– Tijdschriftenzo2015年07月08日 11:55:16 +00:00Commented Jul 8, 2015 at 11:55
-
You added the code at the wrong place. look at my answer. i have specified before which
$selectHtmlto add the codeManashvi Birla– Manashvi Birla2015年07月08日 12:11:12 +00:00Commented Jul 8, 2015 at 12:11
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');