Page 1 of 1

Setting a default option

Posted: Fri Nov 25, 2011 1:18 am
by altsheepy
Hi all,

Instead of having ---please select-- as the default option, is there a way i can set the default selected option in open cart?

Any help would be very much appreciated.

Regards

Re: Setting a default option

Posted: Fri Nov 25, 2011 4:46 am
by florinsith
In what instance , where?

Re: Setting a default option

Posted: Fri Nov 25, 2011 5:08 am
by altsheepy
Sorry my site is down at the moment and i am unable to link it, but basically. When purchasing a product, i added options , for example

Processor 0
Processor 1 +250
Processor 2 +300

When the customer selects the product, the drop-down box shows the following

---please select----
Processor 0
Processor 1 + 250
Processor 2 + 300

Where --please select-- is the default selection. I would like to set a default selection for the product if the customer makes no action.

This can be clearly seen on open cart's demo site.

http://demo.opencart.com/index.php?rout ... duct_id=42

The page loads with no default selections on any of the options. Can i set a default?

Thank you for the help!.

Re: Setting a default option

Posted: Fri Nov 25, 2011 5:12 pm
by florinsith
Edit the file catalog/view/theme/yourtheme/template/product/product.tpl

and look into this piece of code
<?php if ($option['type'] == 'select') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option">
<?php if ($option['required']) { ?>
<span class="required">*</span>
<?php } ?>
<b><?php echo $option['name']; ?>:</b><br />
<select name="option[<?php echo $option['product_option_id']; ?>]">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</option>
<?php } ?>
</select>
</div>
<br />
<?php } ?>
The line that you see highlited (<option value=""><?php echo $text_select; ?></option>) delete that and then the default option will be the first one entered in admin.

Re: Setting a default option

Posted: Fri Nov 25, 2011 9:28 pm
by altsheepy
Thank you so much! it worked!. is there a way to also do this for radio buttons? This worked for the dropdown box type selection.

Re: Setting a default option for Radio Button

Posted: Thu Dec 01, 2011 7:08 am
by nolaweb
v 1.51.

Overview - Under the next option (radio) modify as outlined here. Put a flag and set to 1, check with if and echo cheked for first run through loop, then set flag to 2,

<?php if ($option['type'] == 'radio') { ?>

<div id="option-<?php echo $option['product_option_id']; ?>" class="option">
<?php if ($option['required']) { ?>
<span class="required">*</span>


<?php } ?>
<b><?php echo $option['name'];
// Set the flag
$checkit = 1; ?>:</b><br />
<?php foreach ($option['option_value'] as $option_value) { ?>
<input type="radio" name="option[<?php echo $option['product_option_id']; ?>]"

// echo if it's the first radio
<?php if($checkit ==1) echo "checked=\"1\"" ?>

value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" />
<label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</label>
<br />

<?php
// set flag to 2 so it doesn't check next radio
$checkit = 2; } ?>
</div>
<br />
<?php } ?>

Re: Setting a default option

Posted: Wed Nov 27, 2013 8:30 pm
by redleaf
Sorry to dig up such an old thread but it seemed relevant.

I want to change the select list from "Please Select" but instead of the first option I want the second option selected by default on a great many of my products. Is this possible?

I have all my options sorted by price and I would prefer to keep them that way however my cheapest option is a small sample of my product that isn't really a good example of the starting price of my products

Example list

Sample $2
Regular $10
Large $15
X Large $20

Most customers buy regular and there is no real value in defaulting to the Sample price

Of course to make it even more difficult there may be times when I don't want to do this and would prefer to default to the first option as some of my products don't have sample options

If anyone has any ideas I'd appreciate it

Re: Setting a default option

Posted: Wed Dec 04, 2013 2:51 am
by rmullaney77
I would just adjust the sort order of your options (eg: set "Sample" sort to 9999)

Re: Setting a default option

Posted: Thu Jan 30, 2014 2:45 am
by opencart-sk
Hi, please how to solve this problem? Deleting line 86 in product.tpl:

Code: Select all

<option value=""><?php echo $text_select; ?></option>
does not work in 1.5.6.1 :(

Re: Setting a default option

Posted: Thu Jul 17, 2014 12:53 am
by dantheman50_98
Ditto, not working in 1.5.5.1 either. Help please!

Re: Setting a default option

Posted: Fri Jul 18, 2014 4:32 pm
by florinsith
How does it not work? Is there some error, something breaks? because since the please select option is not there anymore it cant still apear.

Re: Setting a default option

Posted: Fri Jul 18, 2014 6:58 pm
by dantheman50_98
Thanks for the reply, it turns out the options settings extension I'm using was putting it back in via vqmod. Now sorted.

Re: Setting a default option

Posted: Tue Jun 23, 2015 4:38 pm
by Manus
Hey guys,

I know this is an old thread, but how would I modify the coding to work on OpenCart 2.0.3? I have been trying to implement this into the product.tpl document of my OpenCart 2.0.3 installation and I just don't have the know-how to achieve this successfully. I only want this to apply to the radio options.

Assistance will be greatly appreciated. Thanks.

Re: Setting a default option

Posted: Mon Mar 27, 2017 3:14 am
by ronnieb
as above look for <option value=""><?php echo $text_select; ?></option> in theme/*/product.tpl and delete it

Re: Setting a default option

Posted: Fri Apr 21, 2017 8:46 pm
by wh1t3man2nd
Hello,
Even though its an old thread i tried it in ver 2.3.0.2 and nothing happens.
I removed ( <option value=""><?php echo $text_select; ?></option> ) and the "Please select" option remains.
Any ideas on how to do it??
Thank you.