Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 5 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 51 additions and 11 deletions.
  1. +39 −3 app/assets/javascripts/store/variant_options.js
  2. +12 −8 app/models/spree/variant_decorator.rb
View
42 app/assets/javascripts/store/variant_options.js
@@ -36,6 +36,11 @@ function VariantOptions(params) {
var allow_backorders = !params['track_inventory_levels'] || params['allow_backorders'];
var allow_select_outofstock = params['allow_select_outofstock'];
var default_instock = params['default_instock'];
+ var clear_select_on_other_variant_options = true
+
+ if (params['clear_select_on_other_variant_options'] != null){
+ clear_select_on_other_variant_options = params['clear_select_on_other_variant_options'];
+ }
var variant, divs, parent, index = 0;
var selection = [];
@@ -52,7 +57,11 @@ function VariantOptions(params) {
if (default_instock) {
divs.each(function(){
- $(this).find("ul.variant-option-values li a.in-stock:first").click();
+ var first_in_stock = $(this).find("ul.variant-option-values li a.in-stock:first");
+ if (first_in_stock.length > 0)
+ first_in_stock.click();
+ else
+ $(this).find("ul.variant-option-values li a.out-of-stock:first").click();
});
}
}
@@ -173,11 +182,26 @@ function VariantOptions(params) {
}
function toggle() {
+ var cart_button = $('#cart-form button[type=submit]');
if (variant) {
$('#variant_id, form[data-form-type="variant"] input[name$="[variant_id]"]').val(variant.id);
$('#product-price .price').removeClass('unselected').text(variant.price);
+
+ $('.width').text(variant.width);
+ $('.height').text(variant.height);
+ $('.depth').text(variant.depth);
+
+ $('#product-description .description .default_hide').hide();
+ $('#product-description .description .default_show').show();
+ $('#product-description .description .' + variant.color + '_show').show();
+ $('#product-description .description .' + variant.color + '_hide').hide();
+
if (variant.count > 0 || allow_backorders)
- $('#cart-form button[type=submit]').attr('disabled', false).fadeTo(100, 1);
+ {
+ cart_button.attr('disabled', false).fadeTo(100, 1);
+ if (cart_button.attr('original_text') != null)
+ cart_button.text(cart_button.attr('original_text'));
+ }
$('form[data-form-type="variant"] button[type=submit]').attr('disabled', false).fadeTo(100, 1);
try {
show_variant_images(variant.id);
@@ -187,6 +211,9 @@ function VariantOptions(params) {
} else {
$('#variant_id, form[data-form-type="variant"] input[name$="[variant_id]"]').val('');
$('#cart-form button[type=submit], form[data-form-type="variant"] button[type=submit]').attr('disabled', true).fadeTo(0, 0.5);
+ if (cart_button.attr('original_text') != null){
+ cart_button.text("Out of Stock");
+ }
price = $('#product-price .price').addClass('unselected')
// Replace product price by "(select)" only when there are at least 1 variant not out-of-stock
variants = $("div.variant-options.index-0")
@@ -195,19 +222,25 @@ function VariantOptions(params) {
}
}
+ var selected_options = [];
+
function clear(i) {
variant = null;
update(i);
enable(buttons.removeClass('selected'));
toggle();
+ selected_options = []
+
parent.nextAll().each(function(index, element) {
+ if (!clear_select_on_other_variant_options)
+ selected_options.push($(element).find('a.option-value.selected').show());
disable($(element).find('a.option-value').show().removeClass('in-stock out-of-stock').addClass('locked').unbind('click'));
$(element).find('a.clear-button').hide();
});
+
show_all_variant_images();
}
-
function handle_clear(evt) {
evt.preventDefault();
clear(get_index(this));
@@ -228,6 +261,9 @@ function VariantOptions(params) {
if (find_variant()) {
toggle();
}
+
+ $.each(selected_options, function(i, so){ so.click(); });
+ selected_options = []
}
$(document).ready(init);
View
20 app/models/spree/variant_decorator.rb
@@ -1,17 +1,21 @@
Spree::Variant.class_eval do
-
+
include ActionView::Helpers::NumberHelper
-
+
attr_accessible :option_values
-
+
def to_hash
actual_price = self.price
#actual_price += Calculator::Vat.calculate_tax_on(self) if Spree::Config[:show_price_inc_vat]
- {
- :id => self.id,
- :count => self.count_on_hand,
- :price => number_to_currency(actual_price)
+ {
+ :id => self.id,
+ :count => self.count_on_hand,
+ :price => number_to_currency(actual_price),
+ :width => self.width,
+ :height => self.height,
+ :depth => self.depth,
+ :color => self.option_values.select {|ov| ov.option_type.name.downcase == 'color'}.first.presentation.parameterize
}
end
-
+
end

No commit comments for this range

Something went wrong with that request. Please try again.