Commit 9443db4f by vulehuan

display products on homepage

parent b7d37151
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the Card controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
...@@ -233,7 +233,7 @@ h1 { ...@@ -233,7 +233,7 @@ h1 {
} }
.list { .list {
&>li { &>li {
background: url("../images/icon_1.gif") 0 7px no-repeat; background: url("../images/icon_1.gif") 0 8px no-repeat;
border-bottom: 1px solid #CCC; border-bottom: 1px solid #CCC;
&.last { &.last {
border-bottom: none; border-bottom: none;
...@@ -372,13 +372,13 @@ footer { ...@@ -372,13 +372,13 @@ footer {
h4 { h4 {
padding-left: 10px; padding-left: 10px;
margin-left: 25%; margin-left: 25%;
margin-bottom: -25px; margin-bottom: -40px;
} }
.price { .price {
font-size: 13px; font-size: 13px;
padding-bottom: 5px; padding-bottom: 5px;
font-weight: bold; font-weight: bold;
padding-top: 35px; padding-top: 45px;
span { span {
font-size: 14px; font-size: 14px;
color: #FF0000; color: #FF0000;
......
// Place all the styles related to the Product controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class CardController < ApplicationController
def index
end
def checkout
end
def confirm_checkout
end
def thankyou
end
end
class DefaultPagesController < ApplicationController class DefaultPagesController < ApplicationController
def home def home
@recommed_items = Product.get_recommended_products
@newest_items = Product.get_newest_products(limit: 4)
end end
end end
class ProductController < ApplicationController
def index
end
def show
end
end
class Product < ActiveRecord::Base class Product < ActiveRecord::Base
# Returns recommended products (order by rate, and available)
def self.get_recommended_products(options = { limit: 8 })
limit = options[:limit]
return Product.select('id, name, image_medium, price, price_currency').where(availability: 'instock').order('review_rate DESC').order('review_count DESC').limit(limit)
end
# Returns newest products
def self.get_newest_products(options = { limit: 8 })
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
end end
<h1>Card#checkout</h1>
<p>Find me in app/views/card/checkout.html.erb</p>
<h1>Card#confirm_checkout</h1>
<p>Find me in app/views/card/confirm_checkout.html.erb</p>
<h1>Card#index</h1>
<p>Find me in app/views/card/index.html.erb</p>
<h1>Card#thankyou</h1>
<p>Find me in app/views/card/thankyou.html.erb</p>
...@@ -3,106 +3,31 @@ ...@@ -3,106 +3,31 @@
<h2 class="sprite-2"> <h2 class="sprite-2">
Recommended Items<span class="sprite-2"></span> Recommended Items<span class="sprite-2"></span>
</h2> </h2>
<% @recommed_items.each_slice(4) do |row| %>
<div class="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="col-md-3 col-sm-3">
<div class="item"> <div class="item">
<h4> <h4>
<a href="">HP Pavilion DM1-4104AU – 11.6” / 500GB</a> <a href="<%= url %>" title="<%= obj.name %>"><%= obj.name %></a>
</h4> </h4>
<a href="" class="thumbnail"><img src="<%= image_path('') %>/images/upload/1.jpg" <a href="<%= url %>" class="thumbnail" title="<%= obj.name %>"><img src="<%= obj.image_medium %>" alt="<%= obj.name %>"></a>
alt=""></a>
<div class="price"> <div class="price">
Price: <span>6,699,000</span> Price: <span><%= number_with_delimiter(obj.price) %> <%= obj.price_currency %></span>
</div> </div>
<div class="action"> <div class="action">
<a class="view-detail" href="">Detail</a><a class="order" <a class="view-detail" href="<%= url %>" title="<%= obj.name %>">Detail</a><a class="order"
href="">Order</a> href="<%= add_to_card_url %>">Order</a>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3">
<div class="item">
<h4>
<a href="">Casio AE-1000W-1AVDF</a>
</h4>
<a href="" class="thumbnail"><img src="<%= image_path('') %>/images/upload/2.jpg"
alt=""></a>
<div class="price">
Price: <span>95,000</span>
</div>
<div class="action">
<a class="view-detail" href="">Detail</a><a class="order"
href="">Order</a>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3">
<div class="item">
<h4>
<a href="">Smooth Pillows Travel / Red</a>
</h4>
<a href="" class="thumbnail"><img src="<%= image_path('') %>/images/upload/3.jpg"
alt=""></a>
<div class="price">
Price: <span>95,000</span>
</div>
<div class="action">
<a class="view-detail" href="">Detail</a><a class="order"
href="">Order</a>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3">
<div class="item">
<h4>
<a href="">Kitybags BLVT-0164</a>
</h4>
<a href="" class="thumbnail"><img src="<%= image_path('') %>/images/upload/4.jpg"
alt=""></a>
<div class="price">
Price: <span>228,000</span>
</div>
<div class="action">
<a class="view-detail" href="">Detail</a><a class="order"
href="">Order</a>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3 col-sm-3">
<div class="item">
<h4>
<a href="">Charles &amp; Keith CK2-50150234</a>
</h4>
<a href="" class="thumbnail"><img src="<%= image_path('') %>/images/upload/5.jpg"
alt=""></a>
<div class="price">
Price: <span>1,199,000</span>
</div>
<div class="action">
<a class="view-detail" href="">Detail</a><a class="order"
href="">Order</a>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3">
<div class="item">
<h4>
<a href="">Ananas 40071</a>
</h4>
<a href="" class="thumbnail"><img src="<%= image_path('') %>/images/upload/6.jpg"
alt=""></a>
<div class="price">
Price: <span>449,000</span>
</div>
<div class="action">
<a class="view-detail" href="">Detail</a><a class="order"
href="">Order</a>
</div> </div>
</div> </div>
</div> </div>
<% end %>
</div> </div>
<% end %>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
<!-- Newest Items --> <!-- Newest Items -->
...@@ -110,70 +35,29 @@ ...@@ -110,70 +35,29 @@
<h2 class="sprite-2"> <h2 class="sprite-2">
Newest Items<span class="sprite-2"></span> Newest Items<span class="sprite-2"></span>
</h2> </h2>
<% @newest_items.each_slice(4) do |row| %>
<div class="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="col-md-3 col-sm-3">
<div class="item"> <div class="item">
<h4> <h4>
<a href="">HP Pavilion DM1-4104AU – 11.6” / 500GB</a> <a href="<%= url %>" title="<%= obj.name %>"><%= obj.name %></a>
</h4>
<a href="" class="thumbnail"><img src="<%= image_path('') %>/images/upload/1.jpg"
alt=""></a>
<div class="price">
Price: <span>6,699,000</span>
</div>
<div class="action">
<a class="view-detail" href="">Detail</a><a class="order"
href="">Order</a>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3">
<div class="item">
<h4>
<a href="">Casio AE-1000W-1AVDF</a>
</h4>
<a href="" class="thumbnail"><img src="<%= image_path('') %>/images/upload/2.jpg"
alt=""></a>
<div class="price">
Price: <span>95,000</span>
</div>
<div class="action">
<a class="view-detail" href="">Detail</a><a class="order"
href="">Order</a>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3">
<div class="item">
<h4>
<a href="">Smooth Pillows Travel / Red</a>
</h4>
<a href="" class="thumbnail"><img src="<%= image_path('') %>/images/upload/3.jpg"
alt=""></a>
<div class="price">
Price: <span>95,000</span>
</div>
<div class="action">
<a class="view-detail" href="">Detail</a><a class="order"
href="">Order</a>
</div>
</div>
</div>
<div class="col-md-3 col-sm-3">
<div class="item">
<h4>
<a href="">Kitybags BLVT-0164</a>
</h4> </h4>
<a href="" class="thumbnail"><img src="<%= image_path('') %>/images/upload/4.jpg" <a href="<%= url %>" class="thumbnail" title="<%= obj.name %>"><img src="<%= obj.image_medium %>" alt="<%= obj.name %>"></a>
alt=""></a>
<div class="price"> <div class="price">
Price: <span>228,000</span> Price: <span><%= number_with_delimiter(obj.price) %> <%= obj.price_currency %></span>
</div> </div>
<div class="action"> <div class="action">
<a class="view-detail" href="">Detail</a><a class="order" <a class="view-detail" href="<%= url %>" title="<%= obj.name %>">Detail</a><a class="order"
href="">Order</a> href="<%= add_to_card_url %>">Order</a>
</div> </div>
</div> </div>
</div> </div>
<% end %>
</div> </div>
<% end %>
</div> </div>
\ No newline at end of file
<h1>Product#index</h1>
<p>Find me in app/views/product/index.html.erb</p>
<h1>Product#show</h1>
<p>Find me in app/views/product/show.html.erb</p>
VenshopApp::Application.routes.draw do VenshopApp::Application.routes.draw do
get "card/index"
get "card/checkout"
get "card/confirm_checkout"
get "card/thankyou"
get "product/index"
get "product/show"
resources :users resources :users
resources :sessions, only: [:new, :create, :destroy] resources :sessions, only: [:new, :create, :destroy]
resources :product_category resources :product_categories
resources :products
resources :cards
get "default_pages/home" get "default_pages/home"
get "users/new" get "users/new"
match '/signup', to: 'users#new', via: 'get' match '/signup', to: 'users#new', via: 'get'
match '/signin', to: 'sessions#new', via: 'get' match '/signin', to: 'sessions#new', via: 'get'
match '/signout', to: 'sessions#destroy', via: 'delete' match '/signout', to: 'sessions#destroy', via: 'delete'
# The priority is based upon order of creation: first created -> highest priority. # The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes". # See how all your routes lay out with "rake routes".
......
...@@ -35,7 +35,7 @@ namespace :db do ...@@ -35,7 +35,7 @@ namespace :db do
end end
# Product list # Product list
# http://shopping.yahooapis.jp/ShoppingWebService/V1/itemSearch # http://developer.yahoo.co.jp/webapi/shopping/shopping/v1/itemsearch.html
list_url = 'http://shopping.yahooapis.jp/ShoppingWebService/V1/itemSearch' list_url = 'http://shopping.yahooapis.jp/ShoppingWebService/V1/itemSearch'
category_ids.each do |category_id| category_ids.each do |category_id|
...@@ -75,8 +75,9 @@ namespace :db do ...@@ -75,8 +75,9 @@ namespace :db do
review_count = child_ele.text review_count = child_ele.text
end end
price_currency = ele.attributes["currency"] price = ele.elements['Price']
price = ele.elements['Price'].text price_currency = price.attributes["currency"]
price = price.text
Product.create!( Product.create!(
name: name, name: name,
......
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