The following is a script for having defaults options on the individual product page selected through GET variables (the &X=someVal part of a URL). It is meant to work with Global Mega Options, though currently neither 'file' nor 'radio' type items. I don't plan to include 'file' in, as I don't know if browsers would allow it, and it is a security vulnerability at some level.
Place it in /catalog/view/theme/default/template/product/product.tpl alongside any of the other scripts at the bottom of the page.
Code: Select all
<!-- BEGIN GET VARIABLE TO VALUE SCRIPT -->
<script>
$(function () {
function get(q,s) {
s = (s) ? s : window.location.search;
var re = new RegExp('&'+q+'=([^&]*)','i');
return (s=s.replace(/^\?/,'&').match(re)) ? s=s[1] : s='';
}
$('form#product td').each(function (){
// Expects format /^\nOption Value:/n<br>/n<(select|textarea|input|
optionHTML = $(this).html();
// Grab the option value
optionValue = optionHTML.substr(1, optionHTML.search(/:/) - 1);
optionURLvalue = get(escape(optionValue));
if (optionURLvalue !== "") {
$(this).find('select, input[type][type!=radio], textarea').val(unescape(optionURLvalue));
}
});
});
</script>
<!-- END GET VARIABLE TO VALUE SCRIPT -->