Commit 62fea398 by vulehuan

finish category list page

parent 1b6d61d5
class ProductCategoriesController < ApplicationController
def show
term = ProductCategory.find(params[:id])
if term == nil
@items = Array.new
@title = ''
else
@items = Product.get_products_by_category(product_category_id: params[:id], page: params[:page], limit: 16)
@title = term.name
end
end
end
......@@ -10,4 +10,15 @@ class Product < ActiveRecord::Base
limit = options[:limit]
return Product.select('id, name, image_medium, price, price_currency').where(availability: 'instock').order('created_at DESC').order('updated_at DESC').order('name').limit(limit)
end
# Returns products in a category
def self.get_products_by_category(options = { limit: 16, product_category_id: 0 })
limit = options[:limit]
product_category_id = options[:product_category_id]
page = options[:page]
return Product.select('id, name, image_medium, price, price_currency')
.where(availability: 'instock', product_category_id: product_category_id)
.paginate(:page => page, :per_page => limit)
.order('created_at DESC').order('updated_at DESC').order('name')
end
end
\ No newline at end of file
<h1>ProductCategories#show</h1>
<p>Find me in app/views/product_categories/show.html.erb</p>
<!-- Recommended Items -->
<div class="body-box grid-view">
<h2 class="sprite-2">
<%= @title %><span class="sprite-2"></span>
</h2>
<% @items.each_slice(4) do |row| %>
<div class="row">
<%
row.each do |obj|
url = product_path(obj)
add_to_card_url = cards_path + "?product_id=" + obj.id.to_s
%>
<div class="col-md-3 col-sm-3">
<div class="item">
<h4>
<a href="<%= url %>" title="<%= obj.name %>"><%= obj.name %></a>
</h4>
<a href="<%= url %>" class="thumbnail" title="<%= obj.name %>"><img src="<%= obj.image_medium %>" alt="<%= obj.name %>"></a>
<div class="price">
Price: <span><%= number_with_delimiter(obj.price) %> <%= obj.price_currency %></span>
</div>
<div class="action">
<a class="view-detail" href="<%= url %>" title="<%= obj.name %>">Detail</a><a class="order"
href="<%= add_to_card_url %>">Order</a>
</div>
</div>
</div>
<% end %>
</div>
<% end %>
<%= will_paginate @items, renderer: BootstrapPagination::Rails %>
<div class="clearfix"></div>
</div>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment