Please be aware that I am relatively new to ZC but I do have a lot of experience with PHP and working on opensource applications. I make that disclaimer because in case this code is contrary to ZC coding standards, they are due to novice error. Also this changes some core code, so absolutely before you do anything make sure you create a backup. Also when I identify line numbers, those are not exact but should be close. The intention is to get you in the right section of the code and necessarily the exact line. Pay close attention to the content of the lines of code rather than the line numbers I use.
I've tested this and it appears to work as desired and does not appear to break anything in the process. My goal because our site is selling only downloads I wanted the cart to function so that if an attribute was a radio button and only had one option, not to display anything associated with attributes for the particular product. The value is still there but I modified it to pass as a hidden value rather than a radio button. Also make sure you have selected radio button as the type and not dropdown which will display as a radio button if there is only one option.
To begin I had a to make some changes to my template. The default template has similiar code, so I'll use that for example. And you should be able to apply it to your own template.
In the tpl_modules_attributes.php around line 29 find this code:
Code:
<?php if ($zv_display_select_option > 0) { ?>
This code checks to see if there are ANY options and if so displays the text to "Choose Options". I changed that code to this:
<?php if ($zv_display_select_option > 1) { ?>
Now the text will display only if there are more than one option available.
A little further down around line 61 find this code:
Code:
<h4 class="optionName back"><?php echo $options_name[$i]; ?></h4>
This is the code that displays the option name. Since in my case the option is always there and always selected by default, I didn't want to display it. So I applied the same solution as I did for the "Choose Options" text. So I added a line both above and below that line of code. The whole thing looks like this:
Code:
<?php if ($zv_display_select_option > 1) { ?>
<h4 class="optionName back"><?php echo $options_name[$i]; ?></h4>
<?php } // show please select unless all are readonly ?>
The next file I modified, and this is a core file, remember BACKUP, is attributes.php. If you look around line 451 you should find a line of code that looks like this:
Code:
switch ($products_options_names->fields['products_options_images_style']) {
This switch statement determines how a radio button with be displayed based on your configuration. For example if you have an image with it, that sort of thing. It's a fairly long section of code, so you want to be care here that you make the modifications in the correct place. Since in the case of only a single option, I don't want to display a radio button at all, I checked to see if indeed there was only one option and if so, skip this whole section. I added an if statement above the line above like this:
Code:
//*** begin mod for single option radio button ***********
if($products_options->RecordCount() == 1){
$tmp_radio .= zen_draw_hidden_field('id[' . $products_options_names->fields['products_options_id'] . ']', $products_options_value_id, $selected_attribute, 'id="' . 'attrib-' . $products_options_names->fields['products_options_id'] . '-' . $products_options_value_id . '"') .'<br />' . "\n";
} else {
//*** end mod for single option radio button *********
To help clarify the positioning, this code shows its relationship to the switch statement:
Code:
//*** begin mod for single option radio button ***********
if($products_options->RecordCount() == 1){
$tmp_radio .= zen_draw_hidden_field('id[' . $products_options_names->fields['products_options_id'] . ']', $products_options_value_id, $selected_attribute, 'id="' . 'attrib-' . $products_options_names->fields['products_options_id'] . '-' . $products_options_value_id . '"') .'<br />' . "\n";
} else {
//*** end mod for single option radio button *********
switch ($products_options_names->fields['products_options_images_style']) {
It's almost done, the last thing to do is close the else condition at the end of the switch statement. This is the tricky part, so you want to be careful to get the closing brace in the correct place. I'm including a lot of extra code here to help finding the correct place. Starting at around line 562 find this code:
Code:
$tmp_attributes_image .= '<div class="attribImg">' . zen_draw_radio_field('id[' . $products_options_names->fields['products_options_id'] . ']', $products_options_value_id, $selected_attribute, 'id="' . 'attrib-' . $products_options_names->fields['products_options_id'] . '-' . $products_options_value_id . '"') . '<br />' . '<label class="attribsRadioButton fiveA" for="' . 'attrib-' . $products_options_names->fields['products_options_id'] . '-' . $products_options_value_id . '">' . $products_options->fields['products_options_values_name'] . ($products_options_details_noname != '' ? '<br />' . $products_options_details_noname : '') . '</label></div>';
}
break;
} // end of switch statement
} // end of if radio button
// checkboxes
I've added the comments for the closing brackets for both the switch statement and the whole section which is if its a radio button. So what I wanted to do here was add a closing brace after the closing switch statement brace and before the ending if statement brace. So my final code looks like this:
Code:
$tmp_attributes_image .= '<div class="attribImg">' . zen_draw_radio_field('id[' . $products_options_names->fields['products_options_id'] . ']', $products_options_value_id, $selected_attribute, 'id="' . 'attrib-' . $products_options_names->fields['products_options_id'] . '-' . $products_options_value_id . '"') . '<br />' . '<label class="attribsRadioButton fiveA" for="' . 'attrib-' . $products_options_names->fields['products_options_id'] . '-' . $products_options_value_id . '">' . $products_options->fields['products_options_values_name'] . ($products_options_details_noname != '' ? '<br />' . $products_options_details_noname : '') . '</label></div>';
}
break;
} // end of switch statement
//*** begin mod for single option radio button ***********
}
//*** end mod for single option radio button ***********
} // end of if radio button
// checkboxes
And that's all there is to it. My suggestion is to take is slow and again make sure that you make a backup before making any changes at all. Also be aware that because there are changes to the core, if you apply an upgrade at some point in the future, you'll have to make these changes again to the new code. Hope this helps.
stage
Bookmarks