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
def home
@recommed_items = Product.get_recommended_products
@newest_items = Product.get_newest_products(limit: 4)
@recommed_items = Product.get_recommended_products(limit: 12)
@newest_items = Product.get_newest_products(limit: 5)
end
end
......@@ -7,7 +7,7 @@ class ProductCategoriesController < ApplicationController
@items = Array.new
@title = ''
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
add_breadcrumb term.name, product_category_path(term)
end
......
......@@ -3,7 +3,7 @@ class ProductsController < ApplicationController
before_action :signed_in_user, only: [:new]
def index
@products = Product.get_list(limit: 16, page: params[:page])
@products = Product.get_list(limit: 24, page: params[:page])
end
def show
......@@ -19,7 +19,7 @@ class ProductsController < ApplicationController
add_breadcrumb product_category.name, product_category_path(product_category)
add_breadcrumb @product.name, product_path(@product)
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
def new
......
......@@ -16,7 +16,7 @@ namespace :db do
category_ids = Array.new
doc.elements.each('ResultSet/Result/Categories/Children/Child') do |ele|
i += 1
break if i > 5
break if i > 20
id = ele.elements['Id'].text
title = ele.elements['Title']
......@@ -39,16 +39,17 @@ namespace :db do
list_url = 'http://shopping.yahooapis.jp/ShoppingWebService/V1/itemSearch'
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
xml_data = Net::HTTP.get_response(URI.parse(request_url)).body
# extract product information
doc = REXML::Document.new(xml_data)
i = 0
doc.elements.each('ResultSet/Result/Hit') do |ele|
next if ele.elements['Name'] == nil
i += 1
break if i > 100
break if i > 2000
name = ele.elements['Name'].text
description = ele.elements['Description'].text
......@@ -98,4 +99,5 @@ namespace :db do
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