Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/controllers/products_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ProductsController.class_eval do
HTTP_REFERER_REGEXP = /^https?:\/\/[^\/]+\/t\/([a-z0-9\-\/]+)$/
private
def show
@product = Product.find_by_permalink!(params[:id])
return unless @product

@variants = Variant.active.includes([:option_values, :images]).where(:product_id => @product.id)
@variant_opt_val = Hash[@variants.map{ |v| [v.option_values.map{ |ov| ov.option_type_id.to_s+"_"+ov.id.to_s }.sort.join("-"), v.id ] }]
@product_properties = ProductProperty.includes(:property).where(:product_id => @product.id)
@selected_variant = @variants.detect { |v| v.available? }

referer = request.env['HTTP_REFERER']

if referer && referer.match(HTTP_REFERER_REGEXP)
@taxon = Taxon.find_by_permalink($1)
end

respond_with(@product)
end

end
24 changes: 3 additions & 21 deletions app/views/products/_dropdown_variants.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div id="dropdown-variants">
<script type="text/javascript">
$('ul#product-thumbnails').data("opt_val", <%= @variant_opt_val.to_json.html_safe %> );
</script>
<% if product_price(@product) %>
<%= hook :product_price do %>
<p class="prices">
Expand Down Expand Up @@ -27,27 +30,6 @@
</li>
<% end%>
</ul>
<!--
<ul>
<% has_checked = false
@product.variants.active.each_with_index do |v,index|
next if v.option_values.empty? || (!v.in_stock && !Spree::Config[:show_zero_stock_products])
checked = !has_checked && (v.in_stock || Spree::Config[:allow_backorders])
has_checked = true if checked %>
<li>
<label>
<%= radio_button_tag "products[#{@product.id}]", v.id, checked, :disabled => !v.in_stock && !Spree::Config[:allow_backorders] %>
<span class="variant-description">
<%= variant_options v %>
</span>
<% if variant_price_diff v %>
<span class="price diff"><%= variant_price_diff v %></span>
<% end %>
</label>
</li>
<% end%>
</ul>
-->
</div>
<% end%>
<% if @product.has_stock? || Spree::Config[:allow_backorders] %>
Expand Down
14 changes: 11 additions & 3 deletions public/javascripts/dropdown_variants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
jQuery(document).ready(function() {
$('#product-variants select').live('change', function (event) {
show_variant_images(this.value);
});
$('ul#product-thumbnails').data("opt_val", <%= @variant_opt_val.to_json.html_safe %> );
$('#product-variants').delegate('select', 'change', function (event) {
var opt_val = eval($('ul.thumbnails').data("opt_val"));
var arr = [];
$("#product-variants select option:selected").each(function () {
var ot_ov_str = $(this).parent().attr('id').match(/(option_types_)(\d+)/)[2]+"_"+$(this).attr('value');
arr.push(ot_ov_str);
});
arr.sort();
show_variant_images(opt_val[arr.join("-")]);
});
});