Page 1 of 2
[MOD] - Add "Please select..." to all options and validate
Posted: Mon Feb 15, 2010 12:44 am
by Qphoria
FOR THOSE USING OPENCART 1.4.8 OR LATER, YOU NEED TO USE THE VQMOD SCRIPT VERSION OF THIS MOD FURTHER DOWN THIS THREAD. THE ORIGINAL METHOD NO LONGER WORKS AS OF OPENCART 1.4.8 SINCE I MOVED THE AJAX ADD SCRIPT TO ITS OWN FILE IN THE CORE
For those who want to have a "Please Select..." option in dropdown on product options, you can use this simple script to add the line and force the user to select an option. Do NOT add a please select option via the option page in the admin. This mod will add it for you.
1. EDIT: catalog/view/theme/YOURTHEME/template/module/cart.tpl
2. FIND:
Code: Select all
$('#add_to_cart').click(function () {
3. BEFORE, ADD:
Code: Select all
//Q: Add Please Select... and force choice before add to cart
defaultMsg = "<?php echo $this->language->get('text_please_select');?>";
warningMsg = "<?php echo $this->language->get('text_select_warning');?>";
$('#product select').each (function(i, select) {
$(select).prepend('<option value="0">'+defaultMsg+'</option>');
$(select).val(0);
});
$('#add_to_cart').click(function (event) {
$('#product select :selected').each (function(i, select) {
if ($(select).text() == defaultMsg) {
alert(warningMsg);
event.stopImmediatePropagation();
return false;
}
});
});
//Q: EOF
4. EDIT: catalog/language/english/module/cart.php
5. FIND:
6. BEFORE, ADD:
Code: Select all
$_['text_please_select'] = 'Please Select';
$_['text_select_warning'] = 'You must choose an option for each dropdown box';
[/s]
Re: [MOD] - Add "Please select..." to all options and validate
Posted: Mon Feb 15, 2010 8:26 am
by zollgut
Do you know how I can add this to the Regions List on Signup/Delivery Address Pages, so if region isnt in the list the user can leave this blank?
Re: [MOD] - Add "Please select..." to all options and validate
Posted: Mon Feb 15, 2010 9:15 am
by Qphoria
There already is a Please select on the zones list in 1.3.4 and 1.4.0
But you could modify it slightly to add "Not Listed" or something like that.
Re: [MOD] - Add "Please select..." to all options and validate
Posted: Mon Feb 15, 2010 5:29 pm
by espc
how to translate alert message and the text "please select" and at same time keeping english language ?
Re: [MOD] - Add "Please select..." to all options and validate
Posted: Tue Feb 23, 2010 9:25 am
by Qphoria
Updated to have support for multiple languages. Repaste the main code as some of the varialbles have changed
Re: [MOD] - Add "Please select..." to all options and validate
Posted: Tue Feb 23, 2010 3:49 pm
by espc
you're simply the best
Re: [MOD] - Add "Please select..." to all options and valida
Posted: Tue Sep 07, 2010 4:11 pm
by keclap
I'm using v1.4.9 and this didn't quite work for me. Although not sure whether due to version mismatch or my existing modifications.
Anyway, I got it working with v1.4.9 by editing this file:
catalog\view\javascript\jquery\ajax_add.js
(instead of Q's proposal: catalog/view/theme/YOURTHEME/template/module/cart.tpl)
All other changes are the same.
If script won't be able to pull the language strings, here is a quick and dirty fix:
when copying Q's portion of code (step 3.), replace:
Code: Select all
defaultMsg = "<?php echo $this->language->get('text_please_select');?>";
warningMsg = "<?php echo $this->language->get('text_select_warning');?>";
with
Code: Select all
defaultMsg = "Your replacement for please select";
warningMsg = "Your replacement for warning message";
Thanks Q!
Re: [MOD] - Add "Please select..." to all options and valida
Posted: Fri Sep 24, 2010 7:29 am
by visnetmedia
Hi what if you want to add dropdown option bu it isn't required?
Re: [MOD] - Add "Please select..." to all options and valida
Posted: Fri Sep 24, 2010 1:15 pm
by keclap
Well I did achieve something similar to this. I didn't want a specific option to be replaced with 'Please Choose', but just to be default value. First two options are therefor required (alert pops up) and third is filled with default.
Example:
Option 1: --Please choose--
Option 2: --Please choose--
Option 3: Yes
To make it work you have to modifiy Q's code in step 3 and catalog/view/theme/default/template/product/product.tpl.
In Q's step 3 replace this line:
Code: Select all
$('#product select').each (function(i, select) {
with this:
Code: Select all
$('#test select').each (function(i, select) {
in product.tpl find
parent <td> of this line:
Code: Select all
<select name="option[<?php echo $option['option_id']; ?>]">
Sorry I can't tell you exact line number as my product.tpl is highly modified.
and then change this <td> to:
Code: Select all
$id = "test";
<td<?php echo $id; ?>>
Of course if you visit your store front at this point, nothing will change. But it gives you an ability to add an if statement in product.tpl which will rewrite id="test" to lets say id="test2" and therefor Q's mod will not add --Please choose-- to this specific option.
Example:
If you want option not to be required, you must find its unique value and then you can add an if statement like this:
Code: Select all
$id = "test"; // required
if ($option['option_value'][0]['name'] == 'Ne') { $id="test2"; } // defines the option which is not required
And make sure you add this if statement before the
I hope this helps!

Re: [MOD] - Add "Please select..." to all options and valida
Posted: Wed Jan 05, 2011 1:09 am
by marc_cole
I was able to get this mod to work with OpenCart 1.4.9.3. Here it is as a vqmod file. It would be nice if this was a setting in the admin where we could turn it on or off by product, but in the meantime, this works just fine.
Marc
Re: [MOD] - Add "Please select..." to all options and valida
Posted: Wed Jan 05, 2011 3:06 am
by Qphoria
Ahh you beat me to making this one a vqmod

Nice work
Re: [MOD] - Add "Please select..." to all options and valida
Posted: Sun Jan 23, 2011 3:56 pm
by tommyz
exactly what I needed, thanks Qphoria and Marc for making the vqmod file for this mod :} I wish all the mods will go this direction!

Re: [MOD] - Add "Please select..." to all options and valida
Posted: Sun Jan 30, 2011 3:56 am
by tommyz
hi again
I'd like to use this mod on a store which uses a custom theme. What ever I try to do, I cannot get it working. The cart.tpl is modified in this theme, and even if I make the adjustments to the file path in the vqmod file, or if I try to manually insert this mod, it is just not working :/
Would anyone be so kind to look at the cart.tpl code and see what might be throwing it off?
Code: Select all
<?php ob_start(); ?>
<div id="module_cart">
<div class="az_cart">
<a href="<?php echo $view?>"><img src="<?php echo TMPL_IMAGES ?>/az_cart_icon.png" alt="cart_icon"/></a>
<span>
<span class="_title"><?php echo $heading_title ?></span>
<br />
<span class="_items">
<?php
if ($products) {
$prod_quantity = 0;
foreach($products as $prod){
$prod_quantity += (int)$prod['quantity'];
}
echo sprintf(AZ_HEADER_NOW_IN_CART, $prod_quantity);
echo " - ";
echo $totals[sizeof($totals)-1]['text'];
}else{
echo $text_empty;
}
?>
</span>
</span>
</div>
<div class="middle">
<?php if ($products) { ?>
<table cellpadding="2" cellspacing="0" style="width: 100%;">
<?php foreach ($products as $product) { ?>
<tr>
<td align="left" valign="top" style="width:1px"><span class="cart_remove" id="remove_<?php echo $product['key']; ?>"> </span></td><td valign="top" align="right" style="width:1px"><?php echo $product['quantity']; ?> x </td>
<td align="left" valign="top"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a>
<div>
<?php foreach ($product['option'] as $option) { ?>
- <small style="color: #999;"><?php echo $option['name']; ?> <?php echo $option['value']; ?></small><br />
<?php } ?>
</div></td>
</tr>
<?php } ?>
</table>
<br />
<?php if ($display_price) { ?>
<table cellpadding="0" cellspacing="0" align="right" style="display:inline-block;">
<?php foreach ($totals as $total) { ?>
<tr>
<td align="right"><span class="cart_module_total"><b><?php echo $total['title']; ?></b></span></td>
<td align="right"><span class="cart_module_total"><?php echo $total['text']; ?></span></td>
</tr>
<?php } ?>
</table>
<?php } ?>
<div style="padding-top:5px;text-align:center;clear:both;"><a href="<?php echo $view; ?>"><?php echo $text_view; ?></a> | <a href="<?php echo $checkout; ?>"><?php echo $text_checkout; ?></a></div>
<?php } else { ?>
<!--<div style="text-align: center;"><?php echo $text_empty; ?></div>-->
<?php } ?>
</div>
</div>
<?php
$cart_string = ob_get_contents();
ob_end_clean();
$infobox = new azInfoBox();
//$infobox->azSetBoxHeading($heading_title);
$infobox->azSetBoxHeading();
$infobox->azSetBoxContent($cart_string);
$infobox->azSetBoxFooter();
$infobox->azCreateBox('box2');
?>
<?php if ($ajax) { ?>
<script type="text/javascript">
$(document).ready(function () {
$('#add_to_cart').removeAttr('onclick');
$('#add_to_cart').click(function () {
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/callback',
dataType: 'html',
data: $('#product :input'),
success: function (html) {
$('#module_cart .middle').html(html);
},
complete: function () {
var image = $('#image').offset();
var cart = $('#module_cart').offset();
$('#image').before('<img src="' + $('#image').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');
params = {
top : cart.top + 'px',
left : cart.left + 'px',
opacity : 0.0,
width : $('#module_cart').width(),
height : $('#module_cart').height()
};
$('#temp').animate(params, 'slow', false, function () {
$('#temp').remove();
});
}
});
});
$('#add_to_cart').click(function () {
$.ajaxq("add_queue",{
type: 'post',
url: 'index.php?route=module/az_cart/callback',
dataType: 'html',
data: $('#product :input'),
success: function (html) {
$('.az_cart ._items').html(html);
},
complete: function () {}
});
});
$('.az_add').each(function(){
$(this).removeAttr('href');
$(this).click(function(){
var img = $('.image IMG', $(this).parents('.az_pbox_new')[0])[0];
var holder = $('.image', $(this).parents('.az_pbox_new')[0])[0];
$.ajaxq("add_queue",{
type: 'post',
url: 'index.php?route=module/cart/callback',
dataType: 'html',
data: '&product_id=' + this.name + '&quantity=1',
success: function (html) {
$('#module_cart .middle').html(html);
$.ajaxq("add_queue",{
type: 'post',
url: 'index.php?route=module/az_cart/callback',
dataType: 'html',
data: '&product_id=' + this.name + '&quantity=1',
success: function (html) {
$('.az_cart ._items').html(html);
},
complete: function () {}
});
},
complete: function () {
var image = $(img).position();
var cart = $('#module_cart .az_cart').offset();
$(holder).after('<img src="' + img.src + '" id="temp" style="z-index: 999; position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');
params = {
opacity : 0.0,
width : $(img).width()*1.25,
heigth : $(img).height()*1.25
};
$('#temp').animate(params, 'slow', false, function () {
$('#temp').remove();
});
}
});
});
});
});
</script>
<?php } ?>
<script type="text/javascript"><!--
function getUrlParam(name) {
var name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
$(document).ready(function () {
$('.cart_remove').live('click', function () {
if (!confirm('<?php echo $text_confirm; ?>')) {
return false;
}
$(this).removeClass('cart_remove').addClass('cart_remove_loading');
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/callback',
dataType: 'html',
data: 'remove=' + this.id,
success: function (html) {
$('#module_cart .middle').html(html);
if (getUrlParam('route').indexOf('checkout') != -1) {
window.location.reload();
}
},
complete: function(){
$.ajaxq("add_queue",{
type: 'post',
url: 'index.php?route=module/az_cart/callback',
dataType: 'html',
data: $('#product :input'),
success: function (html) {
$('.az_cart ._items').html(html);
},
complete: function () {}
});
}
});
});
});
//--></script>
Thanks in advance
tom
Re: [MOD] - Add "Please select..." to all options and valida
Posted: Thu Feb 03, 2011 1:40 pm
by tommyz
anyone :/?
Re: [MOD] - Add "Please select..." to all options and valida
Posted: Thu Mar 10, 2011 3:21 pm
by sneha
@tommyz : if you want I can do install of this mod for you
Re: [MOD] - Add "Please select..." to all options and valida
Posted: Sat Apr 02, 2011 8:02 am
by mberlant
keclap wrote:Example:
If you want option not to be required, you must find its unique value and then you can add an if statement like this:
Code: Select all
$id = "test"; // required
if ($option['option_value'][0]['name'] == 'Ne') { $id="test2"; } // defines the option which is not required
And make sure you add this if statement before the
I hope this helps!

This does, indeed, help. I wonder, though, if it is possible to make modifications to reverse this logic. Could we test for the presence of "option value 0 = ----Please Choose----", and if this is true, then invoke marc_cole's script? If the value does not match, then we proceed as normal in OpenCart as a non-required option.
My client stores have products with both required and non-required options, so I have been making do with "Please Choose" in option 0 and having that option be Out of Stock.
Re: [MOD] - Add "Please select..." to all options and valida
Posted: Tue Apr 12, 2011 5:59 pm
by Daz1847
Just a little note!...
I have been using this little vQmod on my website and I have noticed that the Please select option is not automatically selected when browsing with IE9 unless you use IE9 in compatibilty mode.
hmm strange.
Hope this will not effect all vQmod scripts ?...
I'm using it on both
Opencart 1.4.9.3 & 1.4.9.4
Re: [MOD] - Add "Please select..." to all options and valida
Posted: Tue Apr 12, 2011 9:23 pm
by Qphoria
The fact that people use IE9 after the history of IE to date amazes me. I recommend adding a redirect script that checks if the user has IE9 then redirect to Chrome or Firefox and tell them that if they don't get a good browser, God will kill a kitten.
Re: [MOD] - Add "Please select..." to all options and valida
Posted: Wed Apr 13, 2011 3:23 am
by Daz1847
Lol yes I agree Qphoria but sadly lots of people do still use IE.
Now Micro$oft have released the official IE9 update through windows update I would imagine a lot of new users will be installing it as they think it will be better Lol!...
I figured out a little meta tag trick that seems to do the job by forcing IE9 to run in compatibility mode.
Open your templates common folder and edit header.tpl
Find
Code: Select all
<meta name="description" content="<?php echo $description; ?>" />
Then add this on a new line underneath
Code: Select all
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
Save the file then restart IE9 browser.
Works with all themes and is a commonly used method all over the net especially since IE9 and even IE8 it can solve quite a lot of compatibility problems with newer IE versions in general.
Sorry I don't know how to make a vQmod version of it shouldn’t be to difficult though maybe.
Or maybe its not realy worth it not sure but it is nice to have a website fully cross platform compatible I guess.
Re: [MOD] - Add "Please select..." to all options and valida
Posted: Wed Jun 22, 2011 7:55 pm
by s31teg
hello
i have the issue that with the 2 options chosen it added x2 products instead of 1 product with all the options listed below
show in this example:
http://www.wehaveanysticker.com/index.p ... duct_id=49
thanks, steven