Commit b7c7f19b by vulehuan

products: update code get more product and category from yahoo, change number of…

products: update code get more product and category from yahoo, change number of items display on home page, product page, category page and product detail page
parent d04b2354
class DefaultPagesController < ApplicationController class DefaultPagesController < ApplicationController
def home def home
@recommed_items = Product.get_recommended_products @recommed_items = Product.get_recommended_products(limit: 12)
@newest_items = Product.get_newest_products(limit: 4) @newest_items = Product.get_newest_products(limit: 5)
end end
end end
...@@ -7,7 +7,7 @@ class ProductCategoriesController < ApplicationController ...@@ -7,7 +7,7 @@ class ProductCategoriesController < ApplicationController
@items = Array.new @items = Array.new
@title = '' @title = ''
else else
@items = Product.get_products_by_category(product_category_id: params[:id], page: params[:page], limit: 16) @items = Product.get_products_by_category(product_category_id: params[:id], page: params[:page], limit: 24)
@title = term.name @title = term.name
add_breadcrumb term.name, product_category_path(term) add_breadcrumb term.name, product_category_path(term)
end end
......
...@@ -3,7 +3,7 @@ class ProductsController < ApplicationController ...@@ -3,7 +3,7 @@ class ProductsController < ApplicationController
before_action :signed_in_user, only: [:new] before_action :signed_in_user, only: [:new]
def index def index
@products = Product.get_list(limit: 16, page: params[:page]) @products = Product.get_list(limit: 24, page: params[:page])
end end
def show def show
...@@ -19,7 +19,7 @@ class ProductsController < ApplicationController ...@@ -19,7 +19,7 @@ class ProductsController < ApplicationController
add_breadcrumb product_category.name, product_category_path(product_category) add_breadcrumb product_category.name, product_category_path(product_category)
add_breadcrumb @product.name, product_path(@product) add_breadcrumb @product.name, product_path(@product)
end end
@other_products = Product.get_other_products(@product.id, product_category_id: @product.product_category_id, limit: 16) @other_products = Product.get_other_products(@product.id, product_category_id: @product.product_category_id, limit: 20)
end end
def new def new
......
...@@ -16,7 +16,7 @@ namespace :db do ...@@ -16,7 +16,7 @@ namespace :db do
category_ids = Array.new category_ids = Array.new
doc.elements.each('ResultSet/Result/Categories/Children/Child') do |ele| doc.elements.each('ResultSet/Result/Categories/Children/Child') do |ele|
i += 1 i += 1
break if i > 5 break if i > 20
id = ele.elements['Id'].text id = ele.elements['Id'].text
title = ele.elements['Title'] title = ele.elements['Title']
...@@ -39,16 +39,17 @@ namespace :db do ...@@ -39,16 +39,17 @@ namespace :db do
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|
request_url = list_url + '?appid=' + YAHOO_SHOPPING_DATA_APP_ID + '&category_id=' + category_id i = 0
(1..20).each do |offset|
request_url = list_url + '?appid=' + YAHOO_SHOPPING_DATA_APP_ID + '&category_id=' + category_id.to_s + '&offset=' + offset.to_s + '&hits=50'
# get the XML data as a string # get the XML data as a string
xml_data = Net::HTTP.get_response(URI.parse(request_url)).body xml_data = Net::HTTP.get_response(URI.parse(request_url)).body
# extract product information # extract product information
doc = REXML::Document.new(xml_data) doc = REXML::Document.new(xml_data)
i = 0
doc.elements.each('ResultSet/Result/Hit') do |ele| doc.elements.each('ResultSet/Result/Hit') do |ele|
next if ele.elements['Name'] == nil next if ele.elements['Name'] == nil
i += 1 i += 1
break if i > 100 break if i > 2000
name = ele.elements['Name'].text name = ele.elements['Name'].text
description = ele.elements['Description'].text description = ele.elements['Description'].text
...@@ -98,4 +99,5 @@ namespace :db do ...@@ -98,4 +99,5 @@ namespace :db do
end end
end end
end end
end
end end
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