diff --git a/app/controllers/products_controller_decorator.rb b/app/controllers/products_controller_decorator.rb new file mode 100644 index 0000000..781b270 --- /dev/null +++ b/app/controllers/products_controller_decorator.rb @@ -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 \ No newline at end of file diff --git a/app/views/products/_dropdown_variants.erb b/app/views/products/_dropdown_variants.erb index 9b64854..486e8eb 100644 --- a/app/views/products/_dropdown_variants.erb +++ b/app/views/products/_dropdown_variants.erb @@ -1,4 +1,7 @@
@@ -27,27 +30,6 @@ <% end%> -