Skip to content

Commit

Permalink
Further imprvoemets of jvaascripts
Browse files Browse the repository at this point in the history
- Update price when variant changes if it has .update css class
- Updata span.on-hand with amount of products on hand
  • Loading branch information
swistak committed Dec 12, 2009
1 parent dbc8aed commit bbd49de
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions public/javascripts/enchanced-option-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ function possible_combination(values){

function variant_changed(variant_id) {
var va = variant_attributes[variant_id];
console.log(va);
var new_price = va.price;
if($('.price.update')[0]) {
new_price = $('.price.update').text().replace(/[\d,.-]+/, new_price.toFixed(2));
$('.price.update').text(new_price);
}
if($('span.on-hand')[0]) {
$('span.on-hand').text(va.on_hand);
}
}

$('#product-variants table.t2d input[type=radio]').bind("change", function(){
Expand Down Expand Up @@ -62,7 +69,6 @@ $('#product-variants select.option-type').bind("change", function(){
// for each option value
$(select).find("option").each(function(i, option){
var ov_value = option.value.replace(/\D+/, '');
console.log(selected_values.concat([ov_value]));
// check if there's at least one possible combination for this setting
var can_be_set = possible_combination(selected_values.concat([ov_value]));
$(option).attr('disabled', !can_be_set)
Expand Down

0 comments on commit bbd49de

Please sign in to comment.