Sha256: 8eddd16e71df91e6eefb6c7441366874edc87f1fd63460924bb191319bd0af76
Contents?: true
Size: 992 Bytes
Versions: 3
Compression:
Stored size: 992 Bytes
Contents
class TbCommerce::ProductsController < ApplicationController before_action :load_category, :except => [:search] before_action :load_product, :only => [:show] def index @products = @category.products.includes(:product_skus, :images).ordered render 'index' end def show if params[:sku] && sku = @product.product_skus.find_by(:sku => params[:sku]) @cart_item = TbCommerce::CartItem.new(:item => sku) else @cart_item = TbCommerce::CartItem.new() end render 'show' end def search @products = TbCommerce::Product.search(params[:search]).ordered render 'search' end private def load_category @category = TbCommerce::Category.find_by(:slug => params[:category_id]) if @category.blank? raise Spud::NotFoundError.new(:item => 'category') end end def load_product @product = @category.products.find_by(:slug => params[:id]) raise Spud::NotFoundError.new(:item => 'product') if @product.blank? end end
Version data entries
3 entries across 3 versions & 1 rubygems