Sha256: 80d160cc0eb0423cc083592b699f00cd5a249b3970d057eba3e50a8216e283fb

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

class ProductsController < Spree::BaseController
  HTTP_REFERER_REGEXP = /^https?:\/\/[^\/]+\/t\/([a-z0-9\-\/]+)$/
  rescue_from ActiveRecord::RecordNotFound, :with => :render_404
  helper :taxons

  respond_to :html

  def index
    @searcher = Spree::Config.searcher_class.new(params)
    @products = @searcher.retrieve_products
    @new_sales=Product.where("available_on=?",Date.today-5.days)
    @coming_soon=Product.where("available_on > ? and deleted_at is NULL",Date.today)
    respond_with(@products)
  end

  def show
    @product = Product.find_by_permalink!(params[:id])
    return unless @product

    @variants = Variant.active.includes([:option_values, :images]).where(:product_id => @product.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

  private

  def accurate_title
    @product ? @product.name : super
  end
  
 end

Version data entries

6 entries across 6 versions & 5 rubygems

Version Path
apispree_core-0.0.0 app/controllers/products_controller.rb
My-Commerce_core-1.1.0 app/controllers/products_controller.rb
My-Commerce_core-1.0.0 app/controllers/products_controller.rb
MyCommerceapi-1.0.0 core/app/controllers/products_controller.rb
MyCommerce-0.0.3 core/app/controllers/products_controller.rb
rfcommerce_core-0.0.3 app/controllers/products_controller.rb