diff --git a/.gitignore b/.gitignore index 6a502e9..c8fc2c7 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ # Ignore all logfiles and tempfiles. /log/*.log /tmp +.DS_Store +public/uploads +config/config.yml diff --git a/Gemfile b/Gemfile old mode 100644 new mode 100755 index fba3b4e..5fc29c4 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,29 @@ gem 'sdoc', '~> 0.4.0', group: :doc # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring', group: :development + +gem "devise" +gem "stripe" + + +gem "bootstrap-sass" +gem "simple_form", "3.1.0rc1" +gem 'carrierwave' +gem "mini_magick" + +gem "aasm" + +gem 'settingslogic' +gem 'will_paginate' +gem 'ransack' + +gem 'sidekiq' + +group :development do + gem "annotate" + gem "letter_opener" + gem 'roadie' +end # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' diff --git a/Gemfile.lock b/Gemfile.lock old mode 100644 new mode 100755 index 53538d9..c07251d --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,7 @@ GEM remote: https://rubygems.org/ specs: + aasm (3.2.0) actionmailer (4.1.0) actionpack (= 4.1.0) actionview (= 4.1.0) @@ -27,8 +28,22 @@ GEM minitest (~> 5.1) thread_safe (~> 0.1) tzinfo (~> 1.1) + addressable (2.3.6) + annotate (2.6.3) + activerecord (>= 2.3.0) + rake (>= 0.8.7) arel (5.0.1.20140414130214) + bcrypt (3.1.7) + bootstrap-sass (3.0.3.0) + sass (~> 3.2) builder (3.2.2) + carrierwave (0.10.0) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + json (>= 1.7) + mime-types (>= 1.16) + celluloid (0.15.2) + timers (~> 1.1.0) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -36,6 +51,15 @@ GEM coffee-script-source execjs coffee-script-source (1.7.0) + connection_pool (2.0.0) + css_parser (1.3.5) + addressable + devise (3.2.4) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 3.2.6, < 5) + thread_safe (~> 0.1) + warden (~> 1.2.3) erubis (2.7.0) execjs (2.2.0) hike (1.2.3) @@ -47,12 +71,25 @@ GEM railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.8.1) + launchy (2.4.2) + addressable (~> 2.3) + letter_opener (1.2.0) + launchy (~> 2.2) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.25.1) + mini_magick (3.7.0) + subexec (~> 0.2.1) + mini_portile (0.6.0) minitest (5.3.4) multi_json (1.10.1) + netrc (0.7.7) + nokogiri (1.6.2.1) + mini_portile (= 0.6.0) + orm_adapter (0.5.0) + polyamorous (1.0.0) + activerecord (>= 3.0) polyglot (0.3.5) rack (1.5.2) rack-test (0.6.2) @@ -73,8 +110,25 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.3.2) + ransack (1.2.3) + actionpack (>= 3.0) + activerecord (>= 3.0) + activesupport (>= 3.0) + i18n + polyamorous (~> 1.0.0) rdoc (4.1.1) json (~> 1.4) + redis (3.1.0) + redis-namespace (1.5.0) + redis (~> 3.0, >= 3.0.4) + rest-client (1.7.2) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) + roadie (2.4.3) + actionmailer (> 3.0.0, < 5.0.0) + css_parser (~> 1.3.4) + nokogiri (> 1.5.0) + sprockets sass (3.2.19) sass-rails (4.0.3) railties (>= 4.0.0, < 5.0) @@ -84,6 +138,16 @@ GEM sdoc (0.4.0) json (~> 1.8) rdoc (~> 4.0, < 5.0) + settingslogic (2.0.9) + sidekiq (3.2.1) + celluloid (>= 0.15.2) + connection_pool (>= 2.0.0) + json + redis (>= 3.0.6) + redis-namespace (>= 1.3.1) + simple_form (3.1.0.rc1) + actionpack (~> 4.0) + activemodel (~> 4.0) spring (1.1.3) sprockets (2.11.0) hike (~> 1.2) @@ -95,9 +159,15 @@ GEM activesupport (>= 3.0) sprockets (~> 2.8) sqlite3 (1.3.9) + stripe (1.14.0) + json (~> 1.8.1) + mime-types (~> 1.25) + rest-client (~> 1.4) + subexec (0.2.3) thor (0.19.1) thread_safe (0.3.4) tilt (1.4.1) + timers (1.1.0) treetop (1.4.15) polyglot polyglot (>= 0.3.1) @@ -108,18 +178,35 @@ GEM uglifier (2.5.0) execjs (>= 0.3.0) json (>= 1.8.0) + warden (1.2.3) + rack (>= 1.0) + will_paginate (3.0.7) PLATFORMS ruby DEPENDENCIES + aasm + annotate + bootstrap-sass + carrierwave coffee-rails (~> 4.0.0) + devise jbuilder (~> 2.0) jquery-rails + letter_opener + mini_magick rails (= 4.1.0) + ransack + roadie sass-rails (~> 4.0.3) sdoc (~> 0.4.0) + settingslogic + sidekiq + simple_form (= 3.1.0rc1) spring sqlite3 + stripe turbolinks uglifier (>= 1.3.0) + will_paginate diff --git a/README.rdoc b/README.rdoc old mode 100644 new mode 100755 diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 diff --git a/TODO b/TODO new file mode 100755 index 0000000..d0ffb80 --- /dev/null +++ b/TODO @@ -0,0 +1,81 @@ + +購物: + ✔ 身為消費者,我要在前台能夠找到商品並加到購物車 @done (14-06-13 06:24) + ✔ 身為消費者,我要在前台能看到購物車裡面的明細 @done (14-06-13 07:02) + ✔ 身為消費者,我要在前台能夠將多樣商品加到購物車,並生成一張訂單 @done (14-06-13 13:22) + ✔ 身為消費者,當系統生成一張訂單後,我可以填寫寄送資訊,並且用信用卡結帳 @done (14-06-13 14:47) + ✔ 身為消費者,當我下單時,我的信箱要能收到一張下單確認信 @done (14-06-13 17:44) + ☐ use sidekiq to send mail + ✔ 訂單狀態應分為未結帳、已結帳、出貨中、已出貨、辦理退貨 @done (14-06-13 17:44) + ✔ 身為消費者,當我用信用卡結帳後,我的信箱要能收到一張訂購完成信 @done (14-07-28 01:16) + ✔ 身為消費者,可以從信中連結查看原始訂單 @done (14-07-28 00:59) + ☐ use sidekiq to send mail + ✔ 身為消費者,當我在結賬後,購物⾞應自動清空 @done (14-07-21 03:03) + ✔ 身為消費者,我可以從購物車內刪掉某些物品 @done (14-07-18 02:38) + ✔ 身為消費者,我可以從購物車內更新購買數量 @done (14-07-18 03:30) + ✔ 購物車的總價 => 小計 x 數量 @done (14-07-18 04:54) + ✔ 數量為 0 的貨物不能「購買」 @done (14-07-18 04:54) + ✔ 訂單支援「多重購買數量」 @done (14-07-21 03:04) + ✔ 建立 account/orders 可以看到該使用者過去所有訂單 @done (14-07-21 03:15) + ✔ 結賬後跳轉到 account/orders#index @done (14-07-21 03:16) + +Admin 管理訂單: + ✔ 身為管理者,可以在後台看訂單,訂單狀態分為未結帳、已結帳、出貨中、已出貨、辦理退貨 @done (14-07-21 03:20) + ✔ 身為管理者,我可以在後台對單張訂單做狀態改變 @done (14-07-21 05:04) + ✔ admin 的 order 列表應要能顯示訂單狀態 @done (14-07-21 05:04) + ✔ 身為管理者,當我在將商品設為已出貨時,消費者應該收到一張已出貨的通知信 @done (14-07-28 02:21) + ☐ use sidekiq to send mail + ☐ 身為商家,當消費者確定購物結帳後,該商品的庫存必須按照數量減少 + + +Admin: + ✔ Admin Should able to see admin panel link in dropdown menu @done (14-06-13 01:59) + Product: + ✔ Refine with Product List with table @done (14-06-13 02:14) + ✔ should be able to update image when create product @done (14-06-13 04:09) + ☐ should be able to upload image after update + +其他: + ✔ 套 Bootstrap 版 @done (14-06-12 18:33) + ✔ Login / Logout using bootstrap nav @done (14-06-12 18:33) + ✔ SimpleForm with Bootstrap @done (14-06-13 02:39) + ✔ 安裝 Carrierwave @done (14-06-13 03:21) + ✔ Search function ( using Ransack ) @done (14-07-22 07:26) + ✔ Refactor: Service Objects @done (14-07-22 07:36) + ✔ stripe charge @done (14-07-22 07:42) + ✔ Install SettingsLogic and move credentials to config.yml @done (14-07-22 07:41) + ✔ stripe @done (14-07-22 07:42) + ✔ mailgun @done (14-07-22 07:42) + ☐ Use rake to generate 10 fake accounts + +有空想做的: + ☐ 重新整理登入 / 登出畫面 + ☐ 加入 Facebook Login + + +--- ✄ ----------------------- + +身為商家的管理者,我要能夠在後台上架我的東西,並設定能夠販賣: + ✔ 管理者必須要有一個後台 @done (14-06-12 17:56) + ✔ 後台必須要可以新增產品 @done (14-06-12 17:56) + ✔ 產品內容必須要有標題、文字、數量 @done (14-06-12 18:02) + ✔ 產品必須要有價格 @done (14-06-13 03:21) + ✔ 產品內容必須要有圖片 @done (14-06-13 03:21) + +身為商家的管理者,我要能夠在後台設定權限,權限分成管理者以及消費者: + ✔ 身為管理者,才可以進入後台 @done (14-06-13 03:39) + ✔ 身為管理者,必須要登入且是 admin @done (14-06-13 03:39) + ✔ 管理者身份必須要被分為 admin / user @done (14-06-13 03:39) + + +任何使用者都要能看到首頁: + ✔ 首頁應該要能夠看到所有商品 @done (14-06-13 03:39) + ✔ 任何使用者都要能看到首頁 @done (14-06-13 03:39) + + + +任何使用者都要能看到產品頁: + ✔ 產品頁應該能要看到標題 @done (14-06-13 04:09) + ✔ 產品頁應該要能看到敘述 @done (14-06-13 04:09) + ✔ 產品頁應該要能看到圖片 @done (14-06-13 04:09) + diff --git a/app/assets/images/.keep b/app/assets/images/.keep old mode 100644 new mode 100755 diff --git a/app/assets/javascripts/account/orders.js.coffee b/app/assets/javascripts/account/orders.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/account/orders.js.coffee @@ -0,0 +1,3 @@ +# 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/ diff --git a/app/assets/javascripts/admin/orders.js.coffee b/app/assets/javascripts/admin/orders.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/admin/orders.js.coffee @@ -0,0 +1,3 @@ +# 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/ diff --git a/app/assets/javascripts/admin/products.js.coffee b/app/assets/javascripts/admin/products.js.coffee new file mode 100755 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/admin/products.js.coffee @@ -0,0 +1,3 @@ +# 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/ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js old mode 100644 new mode 100755 index d6925fa..c7a8bde --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,5 +12,6 @@ // //= require jquery //= require jquery_ujs -//= require turbolinks -//= require_tree . +//= require bootstrap/dropdown +//= require bootstrap/alert +//= require orders \ No newline at end of file diff --git a/app/assets/javascripts/card_charges.js.coffee b/app/assets/javascripts/card_charges.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/card_charges.js.coffee @@ -0,0 +1,3 @@ +# 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/ diff --git a/app/assets/javascripts/cart_items.js.coffee b/app/assets/javascripts/cart_items.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/cart_items.js.coffee @@ -0,0 +1,3 @@ +# 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/ diff --git a/app/assets/javascripts/carts.js.coffee b/app/assets/javascripts/carts.js.coffee new file mode 100755 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/carts.js.coffee @@ -0,0 +1,3 @@ +# 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/ diff --git a/app/assets/javascripts/orders.js.coffee b/app/assets/javascripts/orders.js.coffee new file mode 100755 index 0000000..4f19484 --- /dev/null +++ b/app/assets/javascripts/orders.js.coffee @@ -0,0 +1,35 @@ +# 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/ + +jQuery ($) -> + $("#payment-form").submit (event) -> + $form = $(this) + + # Disable the submit button to prevent repeated clicks + $form.find("button").prop "disabled", true + Stripe.createToken $form, stripeResponseHandler + + # Prevent the form from submitting with the default action + false + + return + +stripeResponseHandler = (status, response) -> + $form = $("#payment-form") + if response.error + + # Show the errors on the form + $form.find(".payment-errors").text response.error.message + $form.find("button").prop "disabled", false + else + + # token contains id, last4, and card type + token = response.id + + # Insert the token into the form so it gets submitted to the server + $form.append $("").val(token) + + # and submit + $form.get(0).submit() + return \ No newline at end of file diff --git a/app/assets/javascripts/products.js.coffee b/app/assets/javascripts/products.js.coffee new file mode 100755 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/products.js.coffee @@ -0,0 +1,3 @@ +# 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/ diff --git a/app/assets/stylesheets/account/orders.css.scss b/app/assets/stylesheets/account/orders.css.scss new file mode 100644 index 0000000..782d07c --- /dev/null +++ b/app/assets/stylesheets/account/orders.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the account::orders controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/admin/orders.css.scss b/app/assets/stylesheets/admin/orders.css.scss new file mode 100644 index 0000000..7ed90c7 --- /dev/null +++ b/app/assets/stylesheets/admin/orders.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the admin::orders controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/admin/products.css.scss b/app/assets/stylesheets/admin/products.css.scss new file mode 100755 index 0000000..da8969d --- /dev/null +++ b/app/assets/stylesheets/admin/products.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the admin::products controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css old mode 100644 new mode 100755 index a443db3..fc1ccf9 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -10,6 +10,20 @@ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new * file per style scope. * - *= require_tree . *= require_self + *= require bootstrap + *= require products */ + + + +.group:before, .group:after { + content: ""; + display: table; +} +.group:after { + clear: both; +} +.group { + zoom: 1; /* IE6&7 */ +} \ No newline at end of file diff --git a/app/assets/stylesheets/card_charges.css.scss b/app/assets/stylesheets/card_charges.css.scss new file mode 100644 index 0000000..24adb84 --- /dev/null +++ b/app/assets/stylesheets/card_charges.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the card_charges controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/cart_items.css.scss b/app/assets/stylesheets/cart_items.css.scss new file mode 100644 index 0000000..c8ba380 --- /dev/null +++ b/app/assets/stylesheets/cart_items.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the cart_items controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/carts.css.scss b/app/assets/stylesheets/carts.css.scss new file mode 100755 index 0000000..62647c9 --- /dev/null +++ b/app/assets/stylesheets/carts.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the carts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/orders.css.scss b/app/assets/stylesheets/orders.css.scss new file mode 100755 index 0000000..3b0428a --- /dev/null +++ b/app/assets/stylesheets/orders.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the orders controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/products.css.scss b/app/assets/stylesheets/products.css.scss new file mode 100755 index 0000000..e246322 --- /dev/null +++ b/app/assets/stylesheets/products.css.scss @@ -0,0 +1,8 @@ +.product-price{ + padding-top: 20px; + padding-bottom: 20px; + + font-size: 30px; + font-weight: bold; + color: #ff007c; +} diff --git a/app/controllers/account/orders_controller.rb b/app/controllers/account/orders_controller.rb new file mode 100644 index 0000000..842e43c --- /dev/null +++ b/app/controllers/account/orders_controller.rb @@ -0,0 +1,8 @@ +class Account::OrdersController < ApplicationController + + before_action :authenticate_user! + + def index + @orders = current_user.orders.recent + end +end \ No newline at end of file diff --git a/app/controllers/admin/orders_controller.rb b/app/controllers/admin/orders_controller.rb new file mode 100644 index 0000000..3019e37 --- /dev/null +++ b/app/controllers/admin/orders_controller.rb @@ -0,0 +1,40 @@ +class Admin::OrdersController < AdminController + + before_filter :find_order, :except => [:index] + + def index + @orders = Order.recent + end + + def show + @order_info = @order.info + @order_items = @order.items + end + + def ship + OrderShippingService.new(@order).ship_order! + redirect_to :back + end + + def shipped + @order.deliver! + redirect_to :back + end + + def cancel + @order.cancel_order! + redirect_to :back + end + + def return + @order.return_good! + redirect_to :back + end + + protected + + + def find_order + @order = Order.find_by_token(params[:id]) + end +end \ No newline at end of file diff --git a/app/controllers/admin/products_controller.rb b/app/controllers/admin/products_controller.rb new file mode 100755 index 0000000..6c9ece5 --- /dev/null +++ b/app/controllers/admin/products_controller.rb @@ -0,0 +1,41 @@ +class Admin::ProductsController < AdminController + + def new + @product = Product.new + @photo = @product.photos.new + end + + def create + @product = Product.new(product_params) + + if @product.save + redirect_to admin_products_path + else + render :new + end + end + + def edit + @product = Product.find(params[:id]) + end + + def update + @product = Product.find(params[:id]) + + if @product.update(product_params) + redirect_to admin_products_path + else + render :edit + end + end + + def index + @products = Product.all + end + + private + + def product_params + params.require(:product).permit(:title, :description,:quantity, :price, :photos_attributes => [:image] ) + end +end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb new file mode 100755 index 0000000..c29b3ba --- /dev/null +++ b/app/controllers/admin_controller.rb @@ -0,0 +1,8 @@ +class AdminController < ApplicationController + + layout "admin" + + before_action :authenticate_user! + before_action :admin_required + +end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb old mode 100644 new mode 100755 index d83690e..9bac024 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,31 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + + + + def admin_required + current_user.admin? + end + + + helper_method :current_cart + + def current_cart + @current_cart ||= find_cart + end + + def find_cart + + cart = Cart.find_by(id: session[:cart_id]) + + unless cart.present? + cart = Cart.create + end + + session[:cart_id] = cart.id + cart + end + + end diff --git a/app/controllers/card_charges_controller.rb b/app/controllers/card_charges_controller.rb new file mode 100644 index 0000000..fb0c149 --- /dev/null +++ b/app/controllers/card_charges_controller.rb @@ -0,0 +1,26 @@ +class CardChargesController < ApplicationController + + before_action :authenticate_user! + + def create + + @order = current_user.orders.find_by_token(params[:order_id]) + @amount = @order.total * 100 # in cents + + charge = StripeCharge.create( + :amount => @amount, + :card => params[:stripeToken], + :description => @order.token, + ) + + if charge.successful? + CardChargingService.new(@order).charge_card! + redirect_to order_path(@order.token), :notice => "成功完成付款" + else + flash[:error] = charge.error_message + render "orders/pay_with_credit_card" + end + + end + +end \ No newline at end of file diff --git a/app/controllers/cart_items_controller.rb b/app/controllers/cart_items_controller.rb new file mode 100644 index 0000000..98bd5db --- /dev/null +++ b/app/controllers/cart_items_controller.rb @@ -0,0 +1,29 @@ +class CartItemsController < ApplicationController + before_action :authenticate_user! + + def update + @cart = current_cart + @item = @cart.cart_items.find(params[:id]) + + @item.update(item_params) + + redirect_to carts_path + end + + def destroy + @cart = current_cart + @item = @cart.cart_items.find(params[:id]) + + @item.destroy + + flash[:warning] = "成功清空物品" + redirect_to :back + end + + private + + def item_params + params.require(:cart_item).permit(:quantity) + end + +end diff --git a/app/controllers/carts_controller.rb b/app/controllers/carts_controller.rb new file mode 100755 index 0000000..49b5744 --- /dev/null +++ b/app/controllers/carts_controller.rb @@ -0,0 +1,13 @@ +class CartsController < ApplicationController + + before_action :authenticate_user!, :only => [:checkout] + + def index + end + + def checkout + @order = current_user.orders.build + @info = @order.build_info + end + +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep old mode 100644 new mode 100755 diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100755 index 0000000..ff3cb4e --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,34 @@ +class OrdersController < ApplicationController + + before_action :authenticate_user! + + def create + @order = current_user.orders.build(order_params) + + if @order.save + OrderPlacingService.new(current_cart, @order).place_order! + + redirect_to order_path(@order.token) + else + render "carts/checkout" + end + end + + def show + @order = current_user.orders.find_by_token(params[:id]) + @order_info = @order.info + @order_items = @order.items + end + + def pay_with_credit_card + @order = current_user.orders.find_by_token(params[:id]) + end + + private + + def order_params + params.require(:order).permit(:info_attributes => + [:billing_name, :billing_address,:shipping_name, :shipping_address] ) + end + +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100755 index 0000000..a0be568 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,55 @@ +class ProductsController < ApplicationController + + before_action :validate_search_key, :only => [:search] + + def index + @products = Product.order("id DESC") + end + + + def show + @product = Product.find(params[:id]) + end + + def add_to_cart + + @product = Product.find(params[:id]) + + if !current_cart.items.include?(@product) + + if @product.quantity > 0 + current_cart.add_product_to_cart(@product, 1 ) + flash[:notice] = "你已成功將 #{@product.title} 加入購物車" + else + flash[:warning] = "商品缺貨中" + end + + else + flash[:warning] = "你的購物車內已有此物品" + end + + redirect_to :back + + end + + def search + if @query_string.present? + search_result = Product.ransack(@search_criteria).result(:distinct => true) + @products = search_result.paginate(:page => params[:page], :per_page => 20 ) + end + end + + + protected + + def validate_search_key + @query_string = params[:q].gsub(/\\|\'|\/|\?/, "") if params[:q].present? + @search_criteria = search_criteria(@query_string) + end + + + def search_criteria(query_string) + { :title_cont => query_string } + end + +end \ No newline at end of file diff --git a/app/helpers/account/orders_helper.rb b/app/helpers/account/orders_helper.rb new file mode 100644 index 0000000..6f690c4 --- /dev/null +++ b/app/helpers/account/orders_helper.rb @@ -0,0 +1,2 @@ +module Account::OrdersHelper +end diff --git a/app/helpers/admin/orders_helper.rb b/app/helpers/admin/orders_helper.rb new file mode 100644 index 0000000..d5d9069 --- /dev/null +++ b/app/helpers/admin/orders_helper.rb @@ -0,0 +1,8 @@ +module Admin::OrdersHelper + + def render_order_options_for_admin(order) + + render :partial => "admin/orders/state_option", :locals => { :order => order} + + end +end \ No newline at end of file diff --git a/app/helpers/admin/products_helper.rb b/app/helpers/admin/products_helper.rb new file mode 100755 index 0000000..977a242 --- /dev/null +++ b/app/helpers/admin/products_helper.rb @@ -0,0 +1,2 @@ +module Admin::ProductsHelper +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb old mode 100644 new mode 100755 index de6be79..6a25698 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,22 @@ module ApplicationHelper + + + def notice_message + alert_types = { :notice => :success, :alert => :danger } + + close_button_options = { :class => "close", "data-dismiss" => "alert", "aria-hidden" => true } + close_button = content_tag(:button, "×", close_button_options) + + alerts = flash.map do |type, message| + alert_content = close_button + message + + alert_type = alert_types[type.to_sym] || type + alert_class = "alert alert-#{alert_type} alert-dismissable" + + content_tag(:div, alert_content, :class => alert_class) + end + + alerts.join("\n").html_safe + end + end diff --git a/app/helpers/card_charges_helper.rb b/app/helpers/card_charges_helper.rb new file mode 100644 index 0000000..5c18c54 --- /dev/null +++ b/app/helpers/card_charges_helper.rb @@ -0,0 +1,2 @@ +module CardChargesHelper +end diff --git a/app/helpers/cart_items_helper.rb b/app/helpers/cart_items_helper.rb new file mode 100644 index 0000000..f30f683 --- /dev/null +++ b/app/helpers/cart_items_helper.rb @@ -0,0 +1,2 @@ +module CartItemsHelper +end diff --git a/app/helpers/carts_helper.rb b/app/helpers/carts_helper.rb new file mode 100755 index 0000000..a3429fd --- /dev/null +++ b/app/helpers/carts_helper.rb @@ -0,0 +1,10 @@ +module CartsHelper + + def cart_items_count(cart) + cart.cart_items.count + end + + def render_cart_total_price(current_cart) + current_cart.total_price + end +end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100755 index 0000000..8c74f2a --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,23 @@ +module OrdersHelper + + def render_order_link(order) + link_to(order.token, order_path(order.token)) + end + + def render_admin_order_link(order) + link_to(order.token, admin_order_path(order.token)) + end + + def render_order_created_time(order) + order.created_at.to_s(:short) + end + + + def render_order_user_name(user) + user.email + end + + def render_order_state(order) + t("orders.order_state.#{order.aasm_state}") + end +end \ No newline at end of file diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100755 index 0000000..1b908af --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,38 @@ +module ProductsHelper + + def render_product_photo(photo, size = "thumb") + + if photo.present? + image_url = photo.image.send(size).url + else + + case size + when :medium + volume = "300x300" + else + volume = "200x200" + end + + image_url = "http://placehold.it/#{volume}&text=No Pic" + end + + image_tag(image_url, :class => "thumbnail") + + end + + def render_product_name(product) + product.title + end + + def render_product_desc(product) + simple_format(product.description) + end + + def render_product_quantity(product) + product.quantity + end + + def render_product_price(product) + product.price + end +end diff --git a/app/mailers/.keep b/app/mailers/.keep old mode 100644 new mode 100755 diff --git a/app/mailers/card_charges_mailer.rb b/app/mailers/card_charges_mailer.rb new file mode 100644 index 0000000..6fef72a --- /dev/null +++ b/app/mailers/card_charges_mailer.rb @@ -0,0 +1,13 @@ +class CardChargesMailer < ActionMailer::Base + default from: "staff@artstore.com" + + def notify_card_charged(order) + + @order = order + @user = order.user + @order_items = @order.items + @order_info = @order.info + + mail(:to => @user.email , :subject => " [ArtStore] 您的訂單已付款成功,以下是您這次購物明細 #{order.token}") + end +end \ No newline at end of file diff --git a/app/mailers/order_mailer.rb b/app/mailers/order_mailer.rb new file mode 100755 index 0000000..f419871 --- /dev/null +++ b/app/mailers/order_mailer.rb @@ -0,0 +1,13 @@ +class OrderMailer < ActionMailer::Base + default from: "staff@artstore.com" + + def notify_order_placed(order) + + @order = order + @user = order.user + @order_items = @order.items + @order_info = @order.info + + mail(:to => @user.email , :subject => " [ArtStore] 感謝您完成本次的下單,以下是您這次購物明細 #{order.token}") + end +end diff --git a/app/mailers/ship_mailer.rb b/app/mailers/ship_mailer.rb new file mode 100644 index 0000000..1486eaa --- /dev/null +++ b/app/mailers/ship_mailer.rb @@ -0,0 +1,13 @@ +class ShipMailer < ActionMailer::Base + default from: "staff@artstore.com" + + def notify_order_shipped(order) + + @order = order + @user = order.user + @order_items = @order.items + @order_info = @order.info + + mail(:to => @user.email , :subject => " [ArtStore] 您的訂單已出貨 #{order.token}") + end +end diff --git a/app/models/.keep b/app/models/.keep old mode 100644 new mode 100755 diff --git a/app/models/cart.rb b/app/models/cart.rb new file mode 100755 index 0000000..915fd87 --- /dev/null +++ b/app/models/cart.rb @@ -0,0 +1,31 @@ +# == Schema Information +# +# Table name: carts +# +# id :integer not null, primary key +# created_at :datetime +# updated_at :datetime +# + +class Cart < ActiveRecord::Base + + has_many :cart_items, :dependent => :destroy + has_many :items, :through => :cart_items, :source => :product + + + def add_product_to_cart(product, amount) + cart_item = cart_items.build + cart_item.product = product + cart_item.quantity = amount + cart_item.save + end + + def total_price + items.inject(0) {|sum, item| sum + item.price } + cart_items.inject(0) {|sum, item| sum + (item.product.price * item.quantity)} + end + + def clear! + cart_items.delete_all + end +end diff --git a/app/models/cart_item.rb b/app/models/cart_item.rb new file mode 100755 index 0000000..b04b7db --- /dev/null +++ b/app/models/cart_item.rb @@ -0,0 +1,18 @@ +# == Schema Information +# +# Table name: cart_items +# +# id :integer not null, primary key +# cart_id :integer +# product_id :integer +# created_at :datetime +# updated_at :datetime +# + +class CartItem < ActiveRecord::Base + + belongs_to :cart + belongs_to :product + + +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep old mode 100644 new mode 100755 diff --git a/app/models/concerns/tokenable.rb b/app/models/concerns/tokenable.rb new file mode 100644 index 0000000..f30d375 --- /dev/null +++ b/app/models/concerns/tokenable.rb @@ -0,0 +1,13 @@ +module Tokenable + + extend ActiveSupport::Concern + + included do + before_create :generate_token + end + + def generate_token + self.token = SecureRandom.uuid + end + +end diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100755 index 0000000..54a25c7 --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,82 @@ +# == Schema Information +# +# Table name: orders +# +# id :integer not null, primary key +# user_id :integer +# total :integer default(0) +# paid :boolean default(FALSE) +# created_at :datetime +# updated_at :datetime +# token :string(255) +# payment_method :string(255) +# + +class Order < ActiveRecord::Base + + belongs_to :user + has_many :items, :class_name => "OrderItem", :dependent => :destroy + has_one :info, :class_name => "OrderInfo", :dependent => :destroy + + accepts_nested_attributes_for :info + + scope :recent, -> { order("id DESC")} + + include Tokenable + + def build_item_cache_from_cart(cart) + cart.cart_items.each do |cart_item| + item = items.build + item.product_name = cart_item.product.title + item.quantity = cart_item.quantity + item.price = cart_item.product.price + item.save + end + end + + def calculate_total!(current_cart) + self.total = current_cart.total_price + self.save + end + + def set_payment_with!(method) + self.update_column(:payment_method, method) + end + + def pay! + self.update_column(:paid, true) + end + + + include AASM + + aasm do + state :order_placed, :initial => true + state :paid, :after_commit => :pay! + event :make_payment do + transitions :from => :order_placed, :to => :paid + end + + state :shipping + event :ship do + transitions :from => :paid, :to => :shipping + end + + state :shipped + event :deliver do + transitions :from => :shipping, :to => :shipped + end + + state :order_cancelled + event :cancel_order do + transitions :from => [:order_placed, :paid ], :to => :order_cancelled + end + + state :good_returned + event :return_good do + transitions :from => [:shipped ], :to => :good_returned + end + + end + +end diff --git a/app/models/order_info.rb b/app/models/order_info.rb new file mode 100755 index 0000000..8d478cb --- /dev/null +++ b/app/models/order_info.rb @@ -0,0 +1,23 @@ +# == Schema Information +# +# Table name: order_infos +# +# id :integer not null, primary key +# order_id :integer +# billing_name :string(255) +# billing_address :string(255) +# shipping_name :string(255) +# shipping_address :string(255) +# created_at :datetime +# updated_at :datetime +# + +class OrderInfo < ActiveRecord::Base + belongs_to :order + + + validates :billing_name , :presence => true + validates :billing_address , :presence => true + validates :shipping_name , :presence => true + validates :shipping_address , :presence => true +end diff --git a/app/models/order_item.rb b/app/models/order_item.rb new file mode 100755 index 0000000..a780976 --- /dev/null +++ b/app/models/order_item.rb @@ -0,0 +1,16 @@ +# == Schema Information +# +# Table name: order_items +# +# id :integer not null, primary key +# product_name :string(255) +# price :float +# quantity :integer +# order_id :integer +# created_at :datetime +# updated_at :datetime +# + +class OrderItem < ActiveRecord::Base + belongs_to :order +end diff --git a/app/models/photo.rb b/app/models/photo.rb new file mode 100755 index 0000000..fa1a1f7 --- /dev/null +++ b/app/models/photo.rb @@ -0,0 +1,16 @@ +# == Schema Information +# +# Table name: photos +# +# id :integer not null, primary key +# product_id :integer +# image :string(255) +# created_at :datetime +# updated_at :datetime +# + +class Photo < ActiveRecord::Base + belongs_to :product + + mount_uploader :image, ImageUploader +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100755 index 0000000..629edd5 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,26 @@ +# == Schema Information +# +# Table name: products +# +# id :integer not null, primary key +# title :string(255) +# description :text +# quantity :integer default(0) +# created_at :datetime +# updated_at :datetime +# price :float default(0.0) +# + +class Product < ActiveRecord::Base + + has_many :photos + accepts_nested_attributes_for :photos + + validates :title , :presence => true + validates :quantity , :presence => true + + + def default_photo + photos.first + end +end diff --git a/app/models/setting.rb b/app/models/setting.rb new file mode 100644 index 0000000..7e27325 --- /dev/null +++ b/app/models/setting.rb @@ -0,0 +1,4 @@ +class Setting < Settingslogic + source "#{Rails.root}/config/config.yml" + namespace Rails.env +end diff --git a/app/models/settings.rb b/app/models/settings.rb new file mode 100644 index 0000000..43be32f --- /dev/null +++ b/app/models/settings.rb @@ -0,0 +1,4 @@ +class Settings < Settingslogic + source "#{Rails.root}/config/config.yml" + namespace Rails.env +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100755 index 0000000..04162dd --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,36 @@ +# == Schema Information +# +# Table name: users +# +# id :integer not null, primary key +# email :string(255) default(""), not null +# encrypted_password :string(255) default(""), not null +# reset_password_token :string(255) +# reset_password_sent_at :datetime +# remember_created_at :datetime +# sign_in_count :integer default(0), not null +# current_sign_in_at :datetime +# last_sign_in_at :datetime +# current_sign_in_ip :string(255) +# last_sign_in_ip :string(255) +# created_at :datetime +# updated_at :datetime +# is_admin :boolean default(FALSE) +# + +class User < ActiveRecord::Base + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable + + + has_many :orders + + def admin? + is_admin + end + + + +end diff --git a/app/services/card_charging_service.rb b/app/services/card_charging_service.rb new file mode 100644 index 0000000..b6ba795 --- /dev/null +++ b/app/services/card_charging_service.rb @@ -0,0 +1,11 @@ +class CardChargingService + def initialize(order) + @order = order + end + + def charge_card! + @order.set_payment_with!("credit_card") + @order.make_payment! + CardChargesMailer.notify_card_charged(@order).deliver + end +end diff --git a/app/services/order_placing_service.rb b/app/services/order_placing_service.rb new file mode 100644 index 0000000..d5b3a8d --- /dev/null +++ b/app/services/order_placing_service.rb @@ -0,0 +1,13 @@ +class OrderPlacingService + def initialize(cart,order) + @order = order + @cart = cart + end + + def place_order! + @order.build_item_cache_from_cart(@cart) + @order.calculate_total!(@cart) + @cart.clear! + OrderMailer.notify_order_placed(@order).deliver + end +end diff --git a/app/services/order_shipping_service.rb b/app/services/order_shipping_service.rb new file mode 100644 index 0000000..437fada --- /dev/null +++ b/app/services/order_shipping_service.rb @@ -0,0 +1,12 @@ +class OrderShippingService + def initialize(order) + @order = order + end + + def ship_order! + # Reserve for interactions with logistics + + @order.ship! + ShipMailer.notify_order_shipped(@order).deliver + end +end diff --git a/app/services/stripe_charge.rb b/app/services/stripe_charge.rb new file mode 100644 index 0000000..cdf489d --- /dev/null +++ b/app/services/stripe_charge.rb @@ -0,0 +1,31 @@ +class StripeCharge + + attr_reader :error_message, :response + + def initialize(options={}) + @response = options[:response] + @error_message = options[:error_message] + end + + def self.create(options={}) + + Stripe.api_key = Setting.stripe.secret_key + + begin + response = Stripe::Charge.create( + amount: options[:amount], + currency: "usd", + card: options[:card], + description: options[:description] + ) + new(:response => response) + rescue Stripe::CardError => e + new(:error_message => e.message) + end + end + + def successful? + @response.present? + end + +end \ No newline at end of file diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb new file mode 100755 index 0000000..298a698 --- /dev/null +++ b/app/uploaders/image_uploader.rb @@ -0,0 +1,63 @@ +# encoding: utf-8 + +class ImageUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + process :resize_to_fit => [800, 800] + + version :thumb do + process :resize_to_fill => [200,200] + end + + + version :medium do + process :resize_to_fill => [400,400] + end + + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process :scale => [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process :resize_to_fit => [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + # def extension_white_list + # %w(jpg jpeg gif png) + # end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end diff --git a/app/views/account/orders/index.html.erb b/app/views/account/orders/index.html.erb new file mode 100644 index 0000000..dc2bcfb --- /dev/null +++ b/app/views/account/orders/index.html.erb @@ -0,0 +1,20 @@ +

訂單列表

+ + + + + + + + + + + <% @orders.each do |order| %> + + + + + <% end %> + + +
#生成時間
<%= render_order_link(order) %> <%= render_order_created_time(order) %>
\ No newline at end of file diff --git a/app/views/admin/orders/_state_option.html.erb b/app/views/admin/orders/_state_option.html.erb new file mode 100644 index 0000000..b5c9b53 --- /dev/null +++ b/app/views/admin/orders/_state_option.html.erb @@ -0,0 +1,19 @@ +
+ <% case order.aasm_state %> + <% when "order_placed" %> + <%= link_to("取消訂單", cancel_admin_order_path(order.token) , :class => "btn btn-default btn-sm", :method => :post) %> + + <% when "paid" %> + <%= link_to("取消訂單", cancel_admin_order_path(order.token) , :class => "btn btn-default btn-sm", :method => :post) %> + <%= link_to("出貨", ship_admin_order_path(order.token) , :class => "btn btn-default btn-sm", :method => :post) %> + <% when "shipping" %> + <%= link_to("設為已出貨", shipped_admin_order_path(order.token), :class => "btn btn-default btn-sm", :method => :post) %> + <% when "shipped" %> + <%= link_to("退貨", return_admin_order_path(order.token), :class => "btn btn-default btn-sm", :method => :post) %> + <% when "order_cancelled" %> + 訂單已取消 + <% when "good_returned" %> + 已退貨 + <% end %> + +
\ No newline at end of file diff --git a/app/views/admin/orders/index.html.erb b/app/views/admin/orders/index.html.erb new file mode 100644 index 0000000..20f45f8 --- /dev/null +++ b/app/views/admin/orders/index.html.erb @@ -0,0 +1,24 @@ +

訂單列表

+ + + + + + + + + + + + + <% @orders.each do |order| %> + + + + + + + <% end %> + + +
#生成時間訂購者訂單狀態
<%= render_admin_order_link(order) %> <%= render_order_created_time(order) %> <%= render_order_user_name(order.user) %> <%= render_order_state(order) %>
\ No newline at end of file diff --git a/app/views/admin/orders/show.html.erb b/app/views/admin/orders/show.html.erb new file mode 100644 index 0000000..60d9396 --- /dev/null +++ b/app/views/admin/orders/show.html.erb @@ -0,0 +1,61 @@ +
+
+

訂單明細

+ <%= render_order_options_for_admin(@order) %> + + + + + + + + + + <% @order_items.each do |order_item| %> + + + + + + <% end %> + +
商品明細單價數量
+ <%= order_item.product_name %> + <%= order_item.price %> <%= order_item.quantity %>
+
+ + 總計 <%= @order.total %> NTD + +
+
+

寄送資訊

+ + + + + + + + + + + + + + + +
訂購人
+ <%= @order_info.billing_name %> - <%= @order_info.billing_address %> +
收貨人
+ <%= @order_info.shipping_name %> - <%= @order_info.shipping_address %> +
+ <% if @order.order_placed? %> +
+ <%= link_to("以信用卡付款", pay_with_credit_card_order_path(@order.token), :class => "btn btn-primary btn-lg btn-danger ") %> + <%= link_to("以 ATM 付款", "#", :class => "btn btn-primary btn-lg btn-danger ") %> +
+ <% else %> + 此訂單已完成付款 + <% end %> +
+
\ No newline at end of file diff --git a/app/views/admin/products/edit.html.erb b/app/views/admin/products/edit.html.erb new file mode 100755 index 0000000..d6925e1 --- /dev/null +++ b/app/views/admin/products/edit.html.erb @@ -0,0 +1,44 @@ +

編輯 <%= @product.title %>

+ +<%= simple_form_for [:admin, @product ] , :html => { :class => "form form-horizontal" } do |f| %> + +
+ +
+ <%= f.input :title %> +
+
+ +
+ +
+ <%= f.input :description, :as => :text %> +
+
+ + + +
+ +
+ <%= f.input :quantity %> +
+
+ + +
+ +
+ <%= f.input :price %> +
+
+ + +
+ <%= f.submit "Submit", :class => "btn btn-default" , :disable_with => 'Submiting...' %> +
+ + + + +<% end %> diff --git a/app/views/admin/products/index.html.erb b/app/views/admin/products/index.html.erb new file mode 100755 index 0000000..d0bd820 --- /dev/null +++ b/app/views/admin/products/index.html.erb @@ -0,0 +1,32 @@ + +

Product List

+ +
+ <%= link_to("新增產品", new_admin_product_path, :class => "btn btn-primary btn-sm") %> +
+ + + + + + + + + + + <% @products.each do |product| %> + + + + + <% end %> + + +
#Product NameManage Options
<%= product.id %> + + <%= render_product_photo(product.default_photo) %> + + <%= link_to(product.title, admin_product_path(product)) %> + <%= link_to("Edit", edit_admin_product_path(product)) %>
+ + diff --git a/app/views/admin/products/new.html.erb b/app/views/admin/products/new.html.erb new file mode 100755 index 0000000..07b60ae --- /dev/null +++ b/app/views/admin/products/new.html.erb @@ -0,0 +1,49 @@ +

新增產品

+ +<%= simple_form_for [:admin, @product ] , :html => { :class => "form form-horizontal" } do |f| %> + +
+ +
+ <%= f.input :title %> +
+
+ +
+ +
+ <%= f.input :description, :as => :text %> +
+
+ + + +
+ +
+ <%= f.input :quantity %> +
+
+ + +
+ +
+ <%= f.input :price %> +
+
+ + <%= f.simple_fields_for :photos do |c| %> + <%= c.input :image , :as => :file %> + <% end %> + + + +
+ <%= f.submit "Submit", :class => "btn btn-default" , :disable_with => 'Submiting...' %> +
+ + + + +<% end %> diff --git a/app/views/card_charges_mailer/notify_card_charged.html.erb b/app/views/card_charges_mailer/notify_card_charged.html.erb new file mode 100644 index 0000000..f91e2bc --- /dev/null +++ b/app/views/card_charges_mailer/notify_card_charged.html.erb @@ -0,0 +1,76 @@ + + +
+
+ +

">訂單明細

+ + + + + + + + + + + <% @order_items.each do |order_item| %> + + + + + + <% end %> + + +
商品明細單價數量
+ <%= order_item.product_name %> + <%= order_item.price %> <%= order_item.quantity %>
+ + +
+ + 總計 <%= @order.total %> NTD + +
+ +
+ +

寄送資訊

+ + + + + + + + + + + + + + + + + + + + + + + +
訂購人
+ <%= @order_info.billing_name %> - <%= @order_info.billing_address %> +
收貨人
+ <%= @order_info.shipping_name %> - <%= @order_info.shipping_address %> +
+ + + + + +
+ + +
diff --git a/app/views/carts/checkout.html.erb b/app/views/carts/checkout.html.erb new file mode 100755 index 0000000..9cd7c91 --- /dev/null +++ b/app/views/carts/checkout.html.erb @@ -0,0 +1,69 @@ +
+
+ +

購物明細

+ + + + + + + + + + <% current_cart.cart_items.each do |cart_item| %> + + + + + + <% end %> + + +
商品明細單價
+ + <%= link_to(cart_item.product.title, admin_product_path(cart_item.product)) %> + <%= cart_item.product.price %> <%= cart_item.quantity %>
+ +
+ + 總計 <%= render_cart_total_price(current_cart) %> NTD + +
+ +
+ +

訂單資訊

+ + +
+ + <%= simple_form_for @order do |f| %> + + <%= f.simple_fields_for :info do |c| %> + + 訂購人 + +
<%= c.input :billing_name %>
+
<%= c.input :billing_address %>
+ + 收貨人 + +
<%= c.input :shipping_name %>
+
<%= c.input :shipping_address %>
+ <% end %> + +
+ <%= f.submit "生成訂單", :class => "btn btn-primary btn-lg btn-danger pull-right", + :disable_with => 'Submiting...' %> +
+ + <% end %> +
+ + + +
+ + +
diff --git a/app/views/carts/index.html.erb b/app/views/carts/index.html.erb new file mode 100755 index 0000000..f42fd55 --- /dev/null +++ b/app/views/carts/index.html.erb @@ -0,0 +1,49 @@ +
+
+

購物車

+ + + + + + + + + + + + <% current_cart.cart_items.each do |item| %> + + + + + + + + <% end %> + +
商品資訊名稱單價數量刪除
<%= render_product_photo(item.product.default_photo) %> + <%= link_to(item.product.title, admin_product_path(item.product)) %> + <%= item.product.price %> + <%= form_for item, :url => cart_item_path(current_cart, item) do |f| %> + <%= f.select :quantity, [1,2,3,4,5] %> + <%= button_tag(type: 'submit', class: "btn btn-default btn-xs") do %> + + <% end %> + <% end -%> + <%= link_to cart_item_path(current_cart, item), :method => :delete do %> + + <% end %> +
+
+ + 總計 <%= render_cart_total_price(current_cart) %> NTD + +
+ +
+
+ <%= link_to("確認結賬", checkout_carts_path , :method => :post , :class => "btn btn-primary btn-lg btn-danger pull-right") %> +
+
+
\ No newline at end of file diff --git a/app/views/common/_navbar.html.erb b/app/views/common/_navbar.html.erb new file mode 100755 index 0000000..4ca1228 --- /dev/null +++ b/app/views/common/_navbar.html.erb @@ -0,0 +1,70 @@ + \ No newline at end of file diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb new file mode 100755 index 0000000..da95377 --- /dev/null +++ b/app/views/layouts/admin.html.erb @@ -0,0 +1,41 @@ + + + + + + <%= stylesheet_link_tag "application" %> + <%= javascript_include_tag "application" %> + <%= csrf_meta_tags %> + ArtStore + + + + +
+ <%= render "common/navbar" %> + + <%= notice_message %> + +
+
+ + + +
+
+ + <%= yield %> +
+ +
+ + + + + +
+ + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb old mode 100644 new mode 100755 index da9769d..157da14 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,14 +1,24 @@ - Artstore - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> - <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + + + <%= stylesheet_link_tag "application" %> + <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> + ArtStore + -<%= yield %> +
+ + <%= render "common/navbar" %> + + <%= notice_message %> + + <%= yield %> +
diff --git a/app/views/order_mailer/notify_order_placed.html.erb b/app/views/order_mailer/notify_order_placed.html.erb new file mode 100755 index 0000000..f91e2bc --- /dev/null +++ b/app/views/order_mailer/notify_order_placed.html.erb @@ -0,0 +1,76 @@ + + +
+
+ +

">訂單明細

+ + + + + + + + + + + <% @order_items.each do |order_item| %> + + + + + + <% end %> + + +
商品明細單價數量
+ <%= order_item.product_name %> + <%= order_item.price %> <%= order_item.quantity %>
+ + +
+ + 總計 <%= @order.total %> NTD + +
+ +
+ +

寄送資訊

+ + + + + + + + + + + + + + + + + + + + + + + +
訂購人
+ <%= @order_info.billing_name %> - <%= @order_info.billing_address %> +
收貨人
+ <%= @order_info.shipping_name %> - <%= @order_info.shipping_address %> +
+ + + + + +
+ + +
diff --git a/app/views/orders/pay_with_credit_card.html.erb b/app/views/orders/pay_with_credit_card.html.erb new file mode 100644 index 0000000..932fc1c --- /dev/null +++ b/app/views/orders/pay_with_credit_card.html.erb @@ -0,0 +1,47 @@ + + + + +<%= form_tag order_card_charges_path(@order.token), :id => "payment-form", :class => "form form-horizontal" do %> + + + +
+
+ + +
+
+ +
+
+ + +
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + + + +<% end %> \ No newline at end of file diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb new file mode 100755 index 0000000..4f09006 --- /dev/null +++ b/app/views/orders/show.html.erb @@ -0,0 +1,85 @@ +
+
+ +

訂單明細

+ + + + + + + + + + <% @order_items.each do |order_item| %> + + + + + <% end %> + + +
商品明細單價
+ <%= order_item.product_name %> + <%= order_item.price %>
+ +
+ + 總計 <%= @order.total %> NTD + +
+ +
+ +

寄送資訊

+ + + + + + + + + + + + + + + + + + + + + + + +
訂購人
+ <%= @order_info.billing_name %> - <%= @order_info.billing_address %> +
收貨人
+ <%= @order_info.shipping_name %> - <%= @order_info.shipping_address %> +
+ + + <% if @order.order_placed? %> + +
+ <%= link_to("以信用卡付款", pay_with_credit_card_order_path(@order.token), :class => "btn btn-primary btn-lg btn-danger ") %> + + <%= link_to("以 ATM 付款", "#", :class => "btn btn-primary btn-lg btn-danger ") %> +
+ + <% else %> + + 此訂單已完成付款 + + <% end %> + + + + +
+ + +
diff --git a/app/views/products/_product_item.html.erb b/app/views/products/_product_item.html.erb new file mode 100755 index 0000000..dc79be8 --- /dev/null +++ b/app/views/products/_product_item.html.erb @@ -0,0 +1,13 @@ +
+ +
+ <%= link_to product_path(product) do %> + <%= render_product_photo(product.default_photo) %> + <% end %> + +
+ + <%= render_product_name(product) %> + + +
\ No newline at end of file diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100755 index 0000000..ce091dc --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,7 @@ +
+ + <%= render :partial => "product_item", :collection => @products , :as => :product %> + + + +
\ No newline at end of file diff --git a/app/views/products/search.html.erb b/app/views/products/search.html.erb new file mode 100644 index 0000000..24df3d0 --- /dev/null +++ b/app/views/products/search.html.erb @@ -0,0 +1,9 @@ +
+ +

搜尋字串: <%= @query_string %>

+ +
+ + <%= render :partial => "product_item", :collection => @products , :as => :product %> + +
\ No newline at end of file diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100755 index 0000000..7ab94bc --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,24 @@ +
+
+ <%= render_product_photo(@product.default_photo, :medium) %> +
+ +
+

<%= render_product_name(@product) %>

+
+

+ <%= render_product_desc(@product) %> +

+
+
數量 : <%= render_product_quantity(@product) %>
+
$ <%= render_product_price(@product) %>
+
+ <% if @product.quantity > 0 %> + <%= link_to("加入購物車", add_to_cart_product_path(@product) , :method => :post , :class => "btn btn-primary btn-lg btn-danger") %> + <% else %> + 已銷售一空,無法購買 + <% end %> +
+
+ +
\ No newline at end of file diff --git a/app/views/ship_mailer/notify_order_shipped.html.erb b/app/views/ship_mailer/notify_order_shipped.html.erb new file mode 100644 index 0000000..f91e2bc --- /dev/null +++ b/app/views/ship_mailer/notify_order_shipped.html.erb @@ -0,0 +1,76 @@ + + +
+
+ +

">訂單明細

+ + + + + + + + + + + <% @order_items.each do |order_item| %> + + + + + + <% end %> + + +
商品明細單價數量
+ <%= order_item.product_name %> + <%= order_item.price %> <%= order_item.quantity %>
+ + +
+ + 總計 <%= @order.total %> NTD + +
+ +
+ +

寄送資訊

+ + + + + + + + + + + + + + + + + + + + + + + +
訂購人
+ <%= @order_info.billing_name %> - <%= @order_info.billing_address %> +
收貨人
+ <%= @order_info.shipping_name %> - <%= @order_info.shipping_address %> +
+ + + + + +
+ + +
diff --git a/config.ru b/config.ru old mode 100644 new mode 100755 diff --git a/config/application.rb b/config/application.rb old mode 100644 new mode 100755 diff --git a/config/boot.rb b/config/boot.rb old mode 100644 new mode 100755 diff --git a/config/config.yml.example b/config/config.yml.example new file mode 100644 index 0000000..9d2677e --- /dev/null +++ b/config/config.yml.example @@ -0,0 +1,17 @@ +defaults: &defaults + app_name: "ArtStore" + stripe: + secret_key: + publishable_key: + mailgun: + username: + password: +development: + <<: *defaults + +test: + <<: *defaults + +production: + <<: *defaults + \ No newline at end of file diff --git a/config/database.yml b/config/database.yml old mode 100644 new mode 100755 diff --git a/config/database.yml.example b/config/database.yml.example new file mode 100755 index 0000000..1c1a37c --- /dev/null +++ b/config/database.yml.example @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: sqlite3 + pool: 5 + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: db/production.sqlite3 diff --git a/config/environment.rb b/config/environment.rb old mode 100644 new mode 100755 diff --git a/config/environments/development.rb b/config/environments/development.rb old mode 100644 new mode 100755 index ddf0e90..8147517 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -16,6 +16,17 @@ # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + # config.action_mailer.delivery_method = :letter_opener + config.action_mailer.smtp_settings = { + :port => 587, + :address => 'smtp.mailgun.org', + :user_name => Settings.mailgun.username, + :password => Settings.mailgun.password, + :domain => 'sandbox2c75a23ba2d740f5b0df61a33941633a.mailgun.org', + :authentication => :plain, + } + config.action_mailer.delivery_method = :smtp + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log diff --git a/config/environments/production.rb b/config/environments/production.rb old mode 100644 new mode 100755 index 47d3553..dec1c86 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -80,4 +80,4 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false -end +end \ No newline at end of file diff --git a/config/environments/test.rb b/config/environments/test.rb old mode 100644 new mode 100755 diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb old mode 100644 new mode 100755 diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb old mode 100644 new mode 100755 diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb new file mode 100755 index 0000000..e863a94 --- /dev/null +++ b/config/initializers/devise.rb @@ -0,0 +1,256 @@ +# Use this hook to configure devise mailer, warden hooks and so forth. +# Many of these configuration options can be set straight in your model. +Devise.setup do |config| + # The secret key used by Devise. Devise uses this key to generate + # random tokens. Changing this key will render invalid all existing + # confirmation, reset password and unlock tokens in the database. + # config.secret_key = '266c58bfeb609ad81cc719a526f11cffa3a5351cea704fdb294a90af06e4d97e4dc3b7c68b029b260f3608cfadc6764fd9b4b1bcbc80f7e193412cee4295845c' + + # ==> Mailer Configuration + # Configure the e-mail address which will be shown in Devise::Mailer, + # note that it will be overwritten if you use your own mailer class + # with default "from" parameter. + config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' + + # Configure the class responsible to send e-mails. + # config.mailer = 'Devise::Mailer' + + # ==> ORM configuration + # Load and configure the ORM. Supports :active_record (default) and + # :mongoid (bson_ext recommended) by default. Other ORMs may be + # available as additional gems. + require 'devise/orm/active_record' + + # ==> Configuration for any authentication mechanism + # Configure which keys are used when authenticating a user. The default is + # just :email. You can configure it to use [:username, :subdomain], so for + # authenticating a user, both parameters are required. Remember that those + # parameters are used only when authenticating and not when retrieving from + # session. If you need permissions, you should implement that in a before filter. + # You can also supply a hash where the value is a boolean determining whether + # or not authentication should be aborted when the value is not present. + # config.authentication_keys = [ :email ] + + # Configure parameters from the request object used for authentication. Each entry + # given should be a request method and it will automatically be passed to the + # find_for_authentication method and considered in your model lookup. For instance, + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. + # The same considerations mentioned for authentication_keys also apply to request_keys. + # config.request_keys = [] + + # Configure which authentication keys should be case-insensitive. + # These keys will be downcased upon creating or modifying a user and when used + # to authenticate or find a user. Default is :email. + config.case_insensitive_keys = [ :email ] + + # Configure which authentication keys should have whitespace stripped. + # These keys will have whitespace before and after removed upon creating or + # modifying a user and when used to authenticate or find a user. Default is :email. + config.strip_whitespace_keys = [ :email ] + + # Tell if authentication through request.params is enabled. True by default. + # It can be set to an array that will enable params authentication only for the + # given strategies, for example, `config.params_authenticatable = [:database]` will + # enable it only for database (email + password) authentication. + # config.params_authenticatable = true + + # Tell if authentication through HTTP Auth is enabled. False by default. + # It can be set to an array that will enable http authentication only for the + # given strategies, for example, `config.http_authenticatable = [:database]` will + # enable it only for database authentication. The supported strategies are: + # :database = Support basic authentication with authentication key + password + # config.http_authenticatable = false + + # If http headers should be returned for AJAX requests. True by default. + # config.http_authenticatable_on_xhr = true + + # The realm used in Http Basic Authentication. 'Application' by default. + # config.http_authentication_realm = 'Application' + + # It will change confirmation, password recovery and other workflows + # to behave the same regardless if the e-mail provided was right or wrong. + # Does not affect registerable. + # config.paranoid = true + + # By default Devise will store the user in session. You can skip storage for + # particular strategies by setting this option. + # Notice that if you are skipping storage for all authentication paths, you + # may want to disable generating routes to Devise's sessions controller by + # passing skip: :sessions to `devise_for` in your config/routes.rb + config.skip_session_storage = [:http_auth] + + # By default, Devise cleans up the CSRF token on authentication to + # avoid CSRF token fixation attacks. This means that, when using AJAX + # requests for sign in and sign up, you need to get a new CSRF token + # from the server. You can disable this option at your own risk. + # config.clean_up_csrf_token_on_authentication = true + + # ==> Configuration for :database_authenticatable + # For bcrypt, this is the cost for hashing the password and defaults to 10. If + # using other encryptors, it sets how many times you want the password re-encrypted. + # + # Limiting the stretches to just one in testing will increase the performance of + # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use + # a value less than 10 in other environments. Note that, for bcrypt (the default + # encryptor), the cost increases exponentially with the number of stretches (e.g. + # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). + config.stretches = Rails.env.test? ? 1 : 10 + + # Setup a pepper to generate the encrypted password. + # config.pepper = 'ed5602debb7c3eb05e509ed3ed54763f2cb5caa0158cbab4fd70692b3f334d1c3c36a73ab473efb7644dca1e53963e3f9a9672cf4a10040272e49d2ac3017cc7' + + # ==> Configuration for :confirmable + # A period that the user is allowed to access the website even without + # confirming their account. For instance, if set to 2.days, the user will be + # able to access the website for two days without confirming their account, + # access will be blocked just in the third day. Default is 0.days, meaning + # the user cannot access the website without confirming their account. + # config.allow_unconfirmed_access_for = 2.days + + # A period that the user is allowed to confirm their account before their + # token becomes invalid. For example, if set to 3.days, the user can confirm + # their account within 3 days after the mail was sent, but on the fourth day + # their account can't be confirmed with the token any more. + # Default is nil, meaning there is no restriction on how long a user can take + # before confirming their account. + # config.confirm_within = 3.days + + # If true, requires any email changes to be confirmed (exactly the same way as + # initial account confirmation) to be applied. Requires additional unconfirmed_email + # db field (see migrations). Until confirmed, new email is stored in + # unconfirmed_email column, and copied to email column on successful confirmation. + config.reconfirmable = true + + # Defines which key will be used when confirming an account + # config.confirmation_keys = [ :email ] + + # ==> Configuration for :rememberable + # The time the user will be remembered without asking for credentials again. + # config.remember_for = 2.weeks + + # If true, extends the user's remember period when remembered via cookie. + # config.extend_remember_period = false + + # Options to be passed to the created cookie. For instance, you can set + # secure: true in order to force SSL only cookies. + # config.rememberable_options = {} + + # ==> Configuration for :validatable + # Range for password length. + config.password_length = 8..128 + + # Email regex used to validate email formats. It simply asserts that + # one (and only one) @ exists in the given string. This is mainly + # to give user feedback and not to assert the e-mail validity. + # config.email_regexp = /\A[^@]+@[^@]+\z/ + + # ==> Configuration for :timeoutable + # The time you want to timeout the user session without activity. After this + # time the user will be asked for credentials again. Default is 30 minutes. + # config.timeout_in = 30.minutes + + # If true, expires auth token on session timeout. + # config.expire_auth_token_on_timeout = false + + # ==> Configuration for :lockable + # Defines which strategy will be used to lock an account. + # :failed_attempts = Locks an account after a number of failed attempts to sign in. + # :none = No lock strategy. You should handle locking by yourself. + # config.lock_strategy = :failed_attempts + + # Defines which key will be used when locking and unlocking an account + # config.unlock_keys = [ :email ] + + # Defines which strategy will be used to unlock an account. + # :email = Sends an unlock link to the user email + # :time = Re-enables login after a certain amount of time (see :unlock_in below) + # :both = Enables both strategies + # :none = No unlock strategy. You should handle unlocking by yourself. + # config.unlock_strategy = :both + + # Number of authentication tries before locking an account if lock_strategy + # is failed attempts. + # config.maximum_attempts = 20 + + # Time interval to unlock the account if :time is enabled as unlock_strategy. + # config.unlock_in = 1.hour + + # Warn on the last attempt before the account is locked. + # config.last_attempt_warning = false + + # ==> Configuration for :recoverable + # + # Defines which key will be used when recovering the password for an account + # config.reset_password_keys = [ :email ] + + # Time interval you can reset your password with a reset password key. + # Don't put a too small interval or your users won't have the time to + # change their passwords. + config.reset_password_within = 6.hours + + # ==> Configuration for :encryptable + # Allow you to use another encryption algorithm besides bcrypt (default). You can use + # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, + # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) + # and :restful_authentication_sha1 (then you should set stretches to 10, and copy + # REST_AUTH_SITE_KEY to pepper). + # + # Require the `devise-encryptable` gem when using anything other than bcrypt + # config.encryptor = :sha512 + + # ==> Scopes configuration + # Turn scoped views on. Before rendering "sessions/new", it will first check for + # "users/sessions/new". It's turned off by default because it's slower if you + # are using only default views. + # config.scoped_views = false + + # Configure the default scope given to Warden. By default it's the first + # devise role declared in your routes (usually :user). + # config.default_scope = :user + + # Set this configuration to false if you want /users/sign_out to sign out + # only the current scope. By default, Devise signs out all scopes. + # config.sign_out_all_scopes = true + + # ==> Navigation configuration + # Lists the formats that should be treated as navigational. Formats like + # :html, should redirect to the sign in page when the user does not have + # access, but formats like :xml or :json, should return 401. + # + # If you have any extra navigational formats, like :iphone or :mobile, you + # should add them to the navigational formats lists. + # + # The "*/*" below is required to match Internet Explorer requests. + # config.navigational_formats = ['*/*', :html] + + # The default HTTP method used to sign out a resource. Default is :delete. + config.sign_out_via = :delete + + # ==> OmniAuth + # Add a new OmniAuth provider. Check the wiki for more information on setting + # up on your models and hooks. + # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + + # ==> Warden configuration + # If you want to use other strategies, that are not supported by Devise, or + # change the failure app, you can configure them inside the config.warden block. + # + # config.warden do |manager| + # manager.intercept_401 = false + # manager.default_strategies(scope: :user).unshift :some_external_strategy + # end + + # ==> Mountable engine configurations + # When using Devise inside an engine, let's call it `MyEngine`, and this engine + # is mountable, there are some extra configurations to be taken into account. + # The following options are available, assuming the engine is mounted as: + # + # mount MyEngine, at: '/my_engine' + # + # The router that invoked `devise_for`, in the example above, would be: + # config.router_name = :my_engine + # + # When using omniauth, Devise cannot automatically set Omniauth path, + # so you need to do it manually. For the users scope, it would be: + # config.omniauth_path_prefix = '/my_engine/users/auth' +end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb old mode 100644 new mode 100755 diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb old mode 100644 new mode 100755 diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb old mode 100644 new mode 100755 diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb old mode 100644 new mode 100755 diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb new file mode 100755 index 0000000..bf7be1c --- /dev/null +++ b/config/initializers/simple_form.rb @@ -0,0 +1,161 @@ +# Use this setup block to configure all options available in SimpleForm. +SimpleForm.setup do |config| + # Wrappers are used by the form builder to generate a + # complete input. You can remove any component from the + # wrapper, change the order or even add your own to the + # stack. The options given below are used to wrap the + # whole input. + config.wrappers :default, class: :input, + hint_class: :field_with_hint, error_class: :field_with_errors do |b| + ## Extensions enabled by default + # Any of these extensions can be disabled for a + # given input by passing: `f.input EXTENSION_NAME => false`. + # You can make any of these extensions optional by + # renaming `b.use` to `b.optional`. + + # Determines whether to use HTML5 (:email, :url, ...) + # and required attributes + b.use :html5 + + # Calculates placeholders automatically from I18n + # You can also pass a string as f.input placeholder: "Placeholder" + b.use :placeholder + + ## Optional extensions + # They are disabled unless you pass `f.input EXTENSION_NAME => :lookup` + # to the input. If so, they will retrieve the values from the model + # if any exists. If you want to enable the lookup for any of those + # extensions by default, you can change `b.optional` to `b.use`. + + # Calculates maxlength from length validations for string inputs + b.optional :maxlength + + # Calculates pattern from format validations for string inputs + b.optional :pattern + + # Calculates min and max from length validations for numeric inputs + b.optional :min_max + + # Calculates readonly automatically from readonly attributes + b.optional :readonly + + ## Inputs + b.use :label_input + b.use :hint, wrap_with: { tag: :span, class: :hint } + b.use :error, wrap_with: { tag: :span, class: :error } + + ## full_messages_for + # If you want to display the full error message for the attribute, you can + # use the component :full_error, like: + # + # b.use :full_error, wrap_with: { tag: :span, class: :error } + end + + # The default wrapper to be used by the FormBuilder. + config.default_wrapper = :default + + # Define the way to render check boxes / radio buttons with labels. + # Defaults to :nested for bootstrap config. + # inline: input + label + # nested: label > input + config.boolean_style = :nested + + # Default class for buttons + config.button_class = 'btn' + + # Method used to tidy up errors. Specify any Rails Array method. + # :first lists the first message for each field. + # Use :to_sentence to list all errors for each field. + # config.error_method = :first + + # Default tag used for error notification helper. + config.error_notification_tag = :div + + # CSS class to add for error notification helper. + config.error_notification_class = 'error_notification' + + # ID to add for error notification helper. + # config.error_notification_id = nil + + # Series of attempts to detect a default label method for collection. + # config.collection_label_methods = [ :to_label, :name, :title, :to_s ] + + # Series of attempts to detect a default value method for collection. + # config.collection_value_methods = [ :id, :to_s ] + + # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none. + # config.collection_wrapper_tag = nil + + # You can define the class to use on all collection wrappers. Defaulting to none. + # config.collection_wrapper_class = nil + + # You can wrap each item in a collection of radio/check boxes with a tag, + # defaulting to :span. Please note that when using :boolean_style = :nested, + # SimpleForm will force this option to be a label. + # config.item_wrapper_tag = :span + + # You can define a class to use in all item wrappers. Defaulting to none. + # config.item_wrapper_class = nil + + # How the label text should be generated altogether with the required text. + # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" } + + # You can define the class to use on all labels. Default is nil. + # config.label_class = nil + + # You can define the class to use on all forms. Default is simple_form. + # config.form_class = :simple_form + + # You can define which elements should obtain additional classes + # config.generate_additional_classes_for = [:wrapper, :label, :input] + + # Whether attributes are required by default (or not). Default is true. + # config.required_by_default = true + + # Tell browsers whether to use the native HTML5 validations (novalidate form option). + # These validations are enabled in SimpleForm's internal config but disabled by default + # in this configuration, which is recommended due to some quirks from different browsers. + # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations, + # change this configuration to true. + config.browser_validations = false + + # Collection of methods to detect if a file type was given. + # config.file_methods = [ :mounted_as, :file?, :public_filename ] + + # Custom mappings for input types. This should be a hash containing a regexp + # to match as key, and the input type that will be used when the field name + # matches the regexp as value. + # config.input_mappings = { /count/ => :integer } + + # Custom wrappers for input types. This should be a hash containing an input + # type as key and the wrapper that will be used for all inputs with specified type. + # config.wrapper_mappings = { string: :prepend } + + # Default priority for time_zone inputs. + # config.time_zone_priority = nil + + # Default priority for country inputs. + # config.country_priority = nil + + # When false, do not use translations for labels. + # config.translate_labels = true + + # Automatically discover new inputs in Rails' autoload path. + # config.inputs_discovery = true + + # Cache SimpleForm inputs discovery + # config.cache_discovery = !Rails.env.development? + + # Default class for inputs + # config.input_class = nil + + # Define the default class of the input wrapper of the boolean input. + config.boolean_label_class = 'checkbox' + + # Defines if the default input wrapper class should be included in radio + # collection wrappers. + # config.include_default_input_wrapper_class = true + + # Defines which i18n scope will be used in Simple Form. + # config.i18n_scope = 'simple_form' +end diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb new file mode 100755 index 0000000..ddeb7e5 --- /dev/null +++ b/config/initializers/simple_form_bootstrap.rb @@ -0,0 +1,106 @@ +# Use this setup block to configure all options available in SimpleForm. +SimpleForm.setup do |config| + config.button_class = 'btn btn-default' + config.boolean_label_class = nil + + config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.use :label, class: 'control-label' + + b.wrapper tag: 'div' do |ba| + ba.use :input, class: 'form-control' + ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + end + + config.wrappers :vertical_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.use :label, class: 'control-label' + + b.wrapper tag: 'div' do |ba| + ba.use :input + ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + end + + config.wrappers :vertical_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + + b.wrapper tag: 'div', class: 'checkbox' do |ba| + ba.use :label_input + end + + b.use :error, wrap_with: { tag: 'span', class: 'help-block' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + + config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.use :label_input + b.use :error, wrap_with: { tag: 'span', class: 'help-block' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + + config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.use :label, class: 'col-sm-3 control-label' + + b.wrapper tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input, class: 'form-control' + ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + end + + config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.use :label, class: 'col-sm-3 control-label' + + b.wrapper tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input + ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + end + + config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + + b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr| + wr.wrapper tag: 'div', class: 'checkbox' do |ba| + ba.use :label_input, class: 'col-sm-9' + end + + wr.use :error, wrap_with: { tag: 'span', class: 'help-block' } + wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + end + + config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + + b.use :label, class: 'col-sm-3 control-label' + + b.wrapper tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input + ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + end + + # Wrappers for forms and inputs using the Bootstrap toolkit. + # Check the Bootstrap docs (http://getbootstrap.com) + # to learn about the different styles for forms and inputs, + # buttons and other elements. + config.default_wrapper = :vertical_form +end diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb old mode 100644 new mode 100755 diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml new file mode 100755 index 0000000..abccdb0 --- /dev/null +++ b/config/locales/devise.en.yml @@ -0,0 +1,59 @@ +# Additional translations at https://github.com/plataformatec/devise/wiki/I18n + +en: + devise: + confirmations: + confirmed: "Your account was successfully confirmed." + send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes." + failure: + already_authenticated: "You are already signed in." + inactive: "Your account is not activated yet." + invalid: "Invalid email or password." + locked: "Your account is locked." + last_attempt: "You have one more attempt before your account will be locked." + not_found_in_database: "Invalid email or password." + timeout: "Your session expired. Please sign in again to continue." + unauthenticated: "You need to sign in or sign up before continuing." + unconfirmed: "You have to confirm your account before continuing." + mailer: + confirmation_instructions: + subject: "Confirmation instructions" + reset_password_instructions: + subject: "Reset password instructions" + unlock_instructions: + subject: "Unlock Instructions" + omniauth_callbacks: + failure: "Could not authenticate you from %{kind} because \"%{reason}\"." + success: "Successfully authenticated from %{kind} account." + passwords: + no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." + send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." + updated: "Your password was changed successfully. You are now signed in." + updated_not_active: "Your password was changed successfully." + registrations: + destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon." + signed_up: "Welcome! You have signed up successfully." + signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." + signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." + signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account." + update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address." + updated: "You updated your account successfully." + sessions: + signed_in: "Signed in successfully." + signed_out: "Signed out successfully." + unlocks: + send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes." + send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes." + unlocked: "Your account has been unlocked successfully. Please sign in to continue." + errors: + messages: + already_confirmed: "was already confirmed, please try signing in" + confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" + expired: "has expired, please request a new one" + not_found: "not found" + not_locked: "was not locked" + not_saved: + one: "1 error prohibited this %{resource} from being saved:" + other: "%{count} errors prohibited this %{resource} from being saved:" diff --git a/config/locales/en.yml b/config/locales/en.yml old mode 100644 new mode 100755 index 0653957..6580f0e --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -21,3 +21,12 @@ en: hello: "Hello world" + + orders: + order_state: + order_placed: 已下單 + paid: 已付款 + shipping: 出貨中 + shipped: 已到貨 + order_cancelled: 取消訂單 + good_returned: 退貨 \ No newline at end of file diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml new file mode 100755 index 0000000..2374383 --- /dev/null +++ b/config/locales/simple_form.en.yml @@ -0,0 +1,31 @@ +en: + simple_form: + "yes": 'Yes' + "no": 'No' + required: + text: 'required' + mark: '*' + # You can uncomment the line below if you need to overwrite the whole required html. + # When using html, text and mark won't be used. + # html: '*' + error_notification: + default_message: "Please review the problems below:" + # Examples + # labels: + # defaults: + # password: 'Password' + # user: + # new: + # email: 'E-mail to sign in.' + # edit: + # email: 'E-mail.' + # hints: + # defaults: + # username: 'User name to sign in.' + # password: 'No special characters, please.' + # include_blanks: + # defaults: + # age: 'Rather not say' + # prompts: + # defaults: + # age: 'Select your age' diff --git a/config/routes.rb b/config/routes.rb old mode 100644 new mode 100755 index 3f66539..a3c8bfc --- a/config/routes.rb +++ b/config/routes.rb @@ -1,56 +1,48 @@ Rails.application.routes.draw do - # The priority is based upon order of creation: first created -> highest priority. - # See how all your routes lay out with "rake routes". - - # You can have the root of your site routed with "root" - # root 'welcome#index' - - # Example of regular route: - # get 'products/:id' => 'catalog#view' - - # Example of named route that can be invoked with purchase_url(id: product.id) - # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - - # Example resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Example resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Example resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Example resource route with more complex sub-resources: - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', on: :collection - # end - # end - - # Example resource route with concerns: - # concern :toggleable do - # post 'toggle' - # end - # resources :posts, concerns: :toggleable - # resources :photos, concerns: :toggleable - - # Example resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end -end + + devise_for :users + + namespace :admin do + resources :products + resources :orders do + member do + post :cancel + post :ship + post :shipped + post :return + end + end + end + + namespace :account do + resources :orders + end + + resources :products do + member do + post :add_to_cart + end + collection do + post :search + end + end + + resources :carts do + collection do + post :checkout + end + + resources :items, :controller => "cart_items" + + end + + resources :orders do + member do + get :pay_with_credit_card + end + + resources :card_charges + end + + root :to => "products#index" +end \ No newline at end of file diff --git a/config/secrets.yml b/config/secrets.yml old mode 100644 new mode 100755 diff --git a/db/migrate/20140609080805_create_products.rb b/db/migrate/20140609080805_create_products.rb new file mode 100755 index 0000000..805c976 --- /dev/null +++ b/db/migrate/20140609080805_create_products.rb @@ -0,0 +1,11 @@ +class CreateProducts < ActiveRecord::Migration + def change + create_table :products do |t| + t.string :title + t.text :description + t.integer :quantity + + t.timestamps + end + end +end diff --git a/db/migrate/20140609082943_devise_create_users.rb b/db/migrate/20140609082943_devise_create_users.rb new file mode 100755 index 0000000..cf497c2 --- /dev/null +++ b/db/migrate/20140609082943_devise_create_users.rb @@ -0,0 +1,42 @@ +class DeviseCreateUsers < ActiveRecord::Migration + def change + create_table(:users) do |t| + ## Database authenticatable + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, default: 0, null: false + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.string :current_sign_in_ip + t.string :last_sign_in_ip + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + + t.timestamps + end + + add_index :users, :email, unique: true + add_index :users, :reset_password_token, unique: true + # add_index :users, :confirmation_token, unique: true + # add_index :users, :unlock_token, unique: true + end +end diff --git a/db/migrate/20140609083725_add_is_admin_to_user.rb b/db/migrate/20140609083725_add_is_admin_to_user.rb new file mode 100755 index 0000000..1ef84cf --- /dev/null +++ b/db/migrate/20140609083725_add_is_admin_to_user.rb @@ -0,0 +1,5 @@ +class AddIsAdminToUser < ActiveRecord::Migration + def change + add_column :users, :is_admin, :boolean, :default => false + end +end diff --git a/db/migrate/20140612184021_change_quantity_default.rb b/db/migrate/20140612184021_change_quantity_default.rb new file mode 100755 index 0000000..e43e9ae --- /dev/null +++ b/db/migrate/20140612184021_change_quantity_default.rb @@ -0,0 +1,6 @@ +class ChangeQuantityDefault < ActiveRecord::Migration + def change + change_column :products, :quantity, :integer, :default => 0 + add_column :products, :price, :float, :default => 0 + end +end diff --git a/db/migrate/20140612185019_create_photos.rb b/db/migrate/20140612185019_create_photos.rb new file mode 100755 index 0000000..83c4126 --- /dev/null +++ b/db/migrate/20140612185019_create_photos.rb @@ -0,0 +1,9 @@ +class CreatePhotos < ActiveRecord::Migration + def change + create_table :photos do |t| + t.integer :product_id + t.string :image + t.timestamps + end + end +end diff --git a/db/migrate/20140612214432_create_carts.rb b/db/migrate/20140612214432_create_carts.rb new file mode 100755 index 0000000..8e66adb --- /dev/null +++ b/db/migrate/20140612214432_create_carts.rb @@ -0,0 +1,8 @@ +class CreateCarts < ActiveRecord::Migration + def change + create_table :carts do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20140612214503_create_cart_items.rb b/db/migrate/20140612214503_create_cart_items.rb new file mode 100755 index 0000000..0fb13b1 --- /dev/null +++ b/db/migrate/20140612214503_create_cart_items.rb @@ -0,0 +1,10 @@ +class CreateCartItems < ActiveRecord::Migration + def change + create_table :cart_items do |t| + t.integer :cart_id + t.integer :product_id + + t.timestamps + end + end +end diff --git a/db/migrate/20140612231815_create_orders.rb b/db/migrate/20140612231815_create_orders.rb new file mode 100755 index 0000000..72cd83c --- /dev/null +++ b/db/migrate/20140612231815_create_orders.rb @@ -0,0 +1,12 @@ +class CreateOrders < ActiveRecord::Migration + def change + create_table :orders do |t| + t.integer :user_id + t.integer :total, :default => 0 + t.boolean :paid, :default => false + t.timestamps + end + end +end + + diff --git a/db/migrate/20140612231956_create_order_infos.rb b/db/migrate/20140612231956_create_order_infos.rb new file mode 100755 index 0000000..09d6331 --- /dev/null +++ b/db/migrate/20140612231956_create_order_infos.rb @@ -0,0 +1,13 @@ +class CreateOrderInfos < ActiveRecord::Migration + def change + create_table :order_infos do |t| + t.integer :order_id + t.string :billing_name + t.string :billing_address + + t.string :shipping_name + t.string :shipping_address + t.timestamps + end + end +end diff --git a/db/migrate/20140612232138_create_order_items.rb b/db/migrate/20140612232138_create_order_items.rb new file mode 100755 index 0000000..cebcd4f --- /dev/null +++ b/db/migrate/20140612232138_create_order_items.rb @@ -0,0 +1,11 @@ +class CreateOrderItems < ActiveRecord::Migration + def change + create_table :order_items do |t| + t.string :product_name + t.float :price + t.integer :quantity + t.integer :order_id + t.timestamps + end + end +end diff --git a/db/migrate/20140613052337_add_token_to_order.rb b/db/migrate/20140613052337_add_token_to_order.rb new file mode 100755 index 0000000..cb455b4 --- /dev/null +++ b/db/migrate/20140613052337_add_token_to_order.rb @@ -0,0 +1,6 @@ +class AddTokenToOrder < ActiveRecord::Migration + def change + add_column :orders, :token, :string + add_index :orders, :token + end +end diff --git a/db/migrate/20140613054444_add_payment_method_to_order.rb b/db/migrate/20140613054444_add_payment_method_to_order.rb new file mode 100755 index 0000000..e7eb536 --- /dev/null +++ b/db/migrate/20140613054444_add_payment_method_to_order.rb @@ -0,0 +1,5 @@ +class AddPaymentMethodToOrder < ActiveRecord::Migration + def change + add_column :orders, :payment_method, :string + end +end diff --git a/db/migrate/20140613065223_add_aasm_state_to_orders.rb b/db/migrate/20140613065223_add_aasm_state_to_orders.rb new file mode 100755 index 0000000..37097ca --- /dev/null +++ b/db/migrate/20140613065223_add_aasm_state_to_orders.rb @@ -0,0 +1,6 @@ +class AddAasmStateToOrders < ActiveRecord::Migration + def change + add_column :orders, :aasm_state, :string, :default => "order_placed" + add_index :orders, :aasm_state + end +end diff --git a/db/migrate/20140717191755_add_quantity_to_cart_item.rb b/db/migrate/20140717191755_add_quantity_to_cart_item.rb new file mode 100644 index 0000000..b8e0866 --- /dev/null +++ b/db/migrate/20140717191755_add_quantity_to_cart_item.rb @@ -0,0 +1,5 @@ +class AddQuantityToCartItem < ActiveRecord::Migration + def change + add_column :cart_items, :quantity, :integer, :default => 1 + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100755 index 0000000..c5b6ce3 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,97 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20140717191755) do + + create_table "cart_items", force: true do |t| + t.integer "cart_id" + t.integer "product_id" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "quantity", default: 1 + end + + create_table "carts", force: true do |t| + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "order_infos", force: true do |t| + t.integer "order_id" + t.string "billing_name" + t.string "billing_address" + t.string "shipping_name" + t.string "shipping_address" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "order_items", force: true do |t| + t.string "product_name" + t.float "price" + t.integer "quantity" + t.integer "order_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "orders", force: true do |t| + t.integer "user_id" + t.integer "total", default: 0 + t.boolean "paid", default: false + t.datetime "created_at" + t.datetime "updated_at" + t.string "token" + t.string "payment_method" + t.string "aasm_state", default: "order_placed" + end + + add_index "orders", ["aasm_state"], name: "index_orders_on_aasm_state" + add_index "orders", ["token"], name: "index_orders_on_token" + + create_table "photos", force: true do |t| + t.integer "product_id" + t.string "image" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "products", force: true do |t| + t.string "title" + t.text "description" + t.integer "quantity", default: 0 + t.datetime "created_at" + t.datetime "updated_at" + t.float "price", default: 0.0 + end + + create_table "users", force: true do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.datetime "created_at" + t.datetime "updated_at" + t.boolean "is_admin", default: false + end + + add_index "users", ["email"], name: "index_users_on_email", unique: true + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + +end diff --git a/db/seeds.rb b/db/seeds.rb old mode 100644 new mode 100755 diff --git a/lib/assets/.keep b/lib/assets/.keep old mode 100644 new mode 100755 diff --git a/lib/tasks/.keep b/lib/tasks/.keep old mode 100644 new mode 100755 diff --git a/lib/templates/erb/scaffold/_form.html.erb b/lib/templates/erb/scaffold/_form.html.erb new file mode 100755 index 0000000..201a069 --- /dev/null +++ b/lib/templates/erb/scaffold/_form.html.erb @@ -0,0 +1,13 @@ +<%%= simple_form_for(@<%= singular_table_name %>) do |f| %> + <%%= f.error_notification %> + +
+ <%- attributes.each do |attribute| -%> + <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %> + <%- end -%> +
+ +
+ <%%= f.button :submit %> +
+<%% end %> diff --git a/log/.keep b/log/.keep old mode 100644 new mode 100755 diff --git a/public/404.html b/public/404.html old mode 100644 new mode 100755 diff --git a/public/422.html b/public/422.html old mode 100644 new mode 100755 diff --git a/public/500.html b/public/500.html old mode 100644 new mode 100755 diff --git a/public/favicon.ico b/public/favicon.ico old mode 100644 new mode 100755 diff --git a/public/robots.txt b/public/robots.txt old mode 100644 new mode 100755 diff --git a/test/controllers/.keep b/test/controllers/.keep old mode 100644 new mode 100755 diff --git a/test/controllers/account/orders_controller_test.rb b/test/controllers/account/orders_controller_test.rb new file mode 100644 index 0000000..b041941 --- /dev/null +++ b/test/controllers/account/orders_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class Account::OrdersControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/admin/orders_controller_test.rb b/test/controllers/admin/orders_controller_test.rb new file mode 100644 index 0000000..8af7f0c --- /dev/null +++ b/test/controllers/admin/orders_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class Admin::OrdersControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/admin/products_controller_test.rb b/test/controllers/admin/products_controller_test.rb new file mode 100755 index 0000000..508fe6b --- /dev/null +++ b/test/controllers/admin/products_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class Admin::ProductsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/card_charges_controller_test.rb b/test/controllers/card_charges_controller_test.rb new file mode 100644 index 0000000..c5002f2 --- /dev/null +++ b/test/controllers/card_charges_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CardChargesControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/cart_items_controller_test.rb b/test/controllers/cart_items_controller_test.rb new file mode 100644 index 0000000..76b2b02 --- /dev/null +++ b/test/controllers/cart_items_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CartItemsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/carts_controller_test.rb b/test/controllers/carts_controller_test.rb new file mode 100755 index 0000000..1e748b8 --- /dev/null +++ b/test/controllers/carts_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CartsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb new file mode 100755 index 0000000..0afece1 --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class OrdersControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb new file mode 100755 index 0000000..c881fa6 --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ProductsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/.keep b/test/fixtures/.keep old mode 100644 new mode 100755 diff --git a/test/fixtures/cart_items.yml b/test/fixtures/cart_items.yml new file mode 100755 index 0000000..2565a88 --- /dev/null +++ b/test/fixtures/cart_items.yml @@ -0,0 +1,20 @@ +# == Schema Information +# +# Table name: cart_items +# +# id :integer not null, primary key +# cart_id :integer +# product_id :integer +# created_at :datetime +# updated_at :datetime +# + +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + cart_id: 1 + product_id: 1 + +two: + cart_id: 1 + product_id: 1 diff --git a/test/fixtures/carts.yml b/test/fixtures/carts.yml new file mode 100755 index 0000000..9fdbb40 --- /dev/null +++ b/test/fixtures/carts.yml @@ -0,0 +1,20 @@ +# == Schema Information +# +# Table name: carts +# +# id :integer not null, primary key +# created_at :datetime +# updated_at :datetime +# + +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/order_infos.yml b/test/fixtures/order_infos.yml new file mode 100755 index 0000000..b237e26 --- /dev/null +++ b/test/fixtures/order_infos.yml @@ -0,0 +1,25 @@ +# == Schema Information +# +# Table name: order_infos +# +# id :integer not null, primary key +# order_id :integer +# billing_name :string(255) +# billing_address :string(255) +# shipping_name :string(255) +# shipping_address :string(255) +# created_at :datetime +# updated_at :datetime +# + +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml new file mode 100755 index 0000000..3446899 --- /dev/null +++ b/test/fixtures/order_items.yml @@ -0,0 +1,24 @@ +# == Schema Information +# +# Table name: order_items +# +# id :integer not null, primary key +# product_name :string(255) +# price :float +# quantity :integer +# order_id :integer +# created_at :datetime +# updated_at :datetime +# + +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100755 index 0000000..8ee4061 --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,25 @@ +# == Schema Information +# +# Table name: orders +# +# id :integer not null, primary key +# user_id :integer +# total :integer default(0) +# paid :boolean default(FALSE) +# created_at :datetime +# updated_at :datetime +# token :string(255) +# payment_method :string(255) +# + +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/photos.yml b/test/fixtures/photos.yml new file mode 100755 index 0000000..b4879c9 --- /dev/null +++ b/test/fixtures/photos.yml @@ -0,0 +1,22 @@ +# == Schema Information +# +# Table name: photos +# +# id :integer not null, primary key +# product_id :integer +# image :string(255) +# created_at :datetime +# updated_at :datetime +# + +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100755 index 0000000..b7a6fb6 --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,24 @@ +# == Schema Information +# +# Table name: products +# +# id :integer not null, primary key +# title :string(255) +# description :text +# quantity :integer default(0) +# created_at :datetime +# updated_at :datetime +# price :float default(0.0) +# + +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + title: MyString + description: MyText + quantity: 1 + +two: + title: MyString + description: MyText + quantity: 1 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100755 index 0000000..ef336eb --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,31 @@ +# == Schema Information +# +# Table name: users +# +# id :integer not null, primary key +# email :string(255) default(""), not null +# encrypted_password :string(255) default(""), not null +# reset_password_token :string(255) +# reset_password_sent_at :datetime +# remember_created_at :datetime +# sign_in_count :integer default(0), not null +# current_sign_in_at :datetime +# last_sign_in_at :datetime +# current_sign_in_ip :string(255) +# last_sign_in_ip :string(255) +# created_at :datetime +# updated_at :datetime +# is_admin :boolean default(FALSE) +# + +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/helpers/.keep b/test/helpers/.keep old mode 100644 new mode 100755 diff --git a/test/helpers/account/orders_helper_test.rb b/test/helpers/account/orders_helper_test.rb new file mode 100644 index 0000000..6073420 --- /dev/null +++ b/test/helpers/account/orders_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class Account::OrdersHelperTest < ActionView::TestCase +end diff --git a/test/helpers/admin/orders_helper_test.rb b/test/helpers/admin/orders_helper_test.rb new file mode 100644 index 0000000..8511d6d --- /dev/null +++ b/test/helpers/admin/orders_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class Admin::OrdersHelperTest < ActionView::TestCase +end diff --git a/test/helpers/admin/products_helper_test.rb b/test/helpers/admin/products_helper_test.rb new file mode 100755 index 0000000..0b696b1 --- /dev/null +++ b/test/helpers/admin/products_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class Admin::ProductsHelperTest < ActionView::TestCase +end diff --git a/test/helpers/card_charges_helper_test.rb b/test/helpers/card_charges_helper_test.rb new file mode 100644 index 0000000..1fe502e --- /dev/null +++ b/test/helpers/card_charges_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class CardChargesHelperTest < ActionView::TestCase +end diff --git a/test/helpers/cart_items_helper_test.rb b/test/helpers/cart_items_helper_test.rb new file mode 100644 index 0000000..4cfc7e9 --- /dev/null +++ b/test/helpers/cart_items_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class CartItemsHelperTest < ActionView::TestCase +end diff --git a/test/helpers/carts_helper_test.rb b/test/helpers/carts_helper_test.rb new file mode 100755 index 0000000..0fac3c4 --- /dev/null +++ b/test/helpers/carts_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class CartsHelperTest < ActionView::TestCase +end diff --git a/test/helpers/orders_helper_test.rb b/test/helpers/orders_helper_test.rb new file mode 100755 index 0000000..52dacae --- /dev/null +++ b/test/helpers/orders_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class OrdersHelperTest < ActionView::TestCase +end diff --git a/test/helpers/products_helper_test.rb b/test/helpers/products_helper_test.rb new file mode 100755 index 0000000..0f5beab --- /dev/null +++ b/test/helpers/products_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class ProductsHelperTest < ActionView::TestCase +end diff --git a/test/integration/.keep b/test/integration/.keep old mode 100644 new mode 100755 diff --git a/test/mailers/.keep b/test/mailers/.keep old mode 100644 new mode 100755 diff --git a/test/mailers/card_charges_mailer_test.rb b/test/mailers/card_charges_mailer_test.rb new file mode 100644 index 0000000..2812b2e --- /dev/null +++ b/test/mailers/card_charges_mailer_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CardChargesMailerTest < ActionMailer::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/mailers/order_mailer_test.rb b/test/mailers/order_mailer_test.rb new file mode 100755 index 0000000..6e2129d --- /dev/null +++ b/test/mailers/order_mailer_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class OrderMailerTest < ActionMailer::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/mailers/previews/card_charges_mailer_preview.rb b/test/mailers/previews/card_charges_mailer_preview.rb new file mode 100644 index 0000000..6bfdd3f --- /dev/null +++ b/test/mailers/previews/card_charges_mailer_preview.rb @@ -0,0 +1,4 @@ +# Preview all emails at http://localhost:3000/rails/mailers/card_charges_mailer +class CardChargesMailerPreview < ActionMailer::Preview + +end diff --git a/test/mailers/previews/order_mailer_preview.rb b/test/mailers/previews/order_mailer_preview.rb new file mode 100755 index 0000000..7be457e --- /dev/null +++ b/test/mailers/previews/order_mailer_preview.rb @@ -0,0 +1,4 @@ +# Preview all emails at http://localhost:3000/rails/mailers/order_mailer +class OrderMailerPreview < ActionMailer::Preview + +end diff --git a/test/mailers/previews/ship_mailer_preview.rb b/test/mailers/previews/ship_mailer_preview.rb new file mode 100644 index 0000000..cbbb2dc --- /dev/null +++ b/test/mailers/previews/ship_mailer_preview.rb @@ -0,0 +1,4 @@ +# Preview all emails at http://localhost:3000/rails/mailers/ship_mailer +class ShipMailerPreview < ActionMailer::Preview + +end diff --git a/test/mailers/ship_mailer_test.rb b/test/mailers/ship_mailer_test.rb new file mode 100644 index 0000000..15ca92c --- /dev/null +++ b/test/mailers/ship_mailer_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ShipMailerTest < ActionMailer::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/.keep b/test/models/.keep old mode 100644 new mode 100755 diff --git a/test/models/cart_item_test.rb b/test/models/cart_item_test.rb new file mode 100755 index 0000000..881afe1 --- /dev/null +++ b/test/models/cart_item_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CartItemTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/cart_test.rb b/test/models/cart_test.rb new file mode 100755 index 0000000..9fad43a --- /dev/null +++ b/test/models/cart_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CartTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/order_info_test.rb b/test/models/order_info_test.rb new file mode 100755 index 0000000..e268911 --- /dev/null +++ b/test/models/order_info_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class OrderInfoTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb new file mode 100755 index 0000000..e473b9e --- /dev/null +++ b/test/models/order_item_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class OrderItemTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100755 index 0000000..15b8ed1 --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class OrderTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/photo_test.rb b/test/models/photo_test.rb new file mode 100755 index 0000000..e2ec03a --- /dev/null +++ b/test/models/photo_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PhotoTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100755 index 0000000..211cdd0 --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ProductTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100755 index 0000000..82f61e0 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/test_helper.rb b/test/test_helper.rb old mode 100644 new mode 100755 diff --git a/vendor/assets/javascripts/.keep b/vendor/assets/javascripts/.keep old mode 100644 new mode 100755 diff --git a/vendor/assets/stylesheets/.keep b/vendor/assets/stylesheets/.keep old mode 100644 new mode 100755