Commit 55625ba6 by hades

card: insert card to db

parent 1a8d06d0
......@@ -117,6 +117,27 @@ class CardsController < ApplicationController
redirect_to cards_path
end
if request.post?
customer_info = @card_infos[:customer_info]
card_items = @card_infos[:card_items]
xml_data = '<?xml version="1.0"?>';
xml_data += '<root>'
total = 0
card_items.each do |card_item|
product = Product.find(card_item[:product_id])
total += product.price
xml_data += '<item product_id="' + card_item[:product_id].to_s + '" quantity="' + card_item[:quantity].to_s + '" price="' + product.price.to_s + '" currency="' + product.price_currency + '" />'
end
xml_data += '<total>' + total.to_s + '</total>'
xml_data += '</root>'
MyCard.create!(
full_name: customer_info[:full_name],
email: customer_info[:email],
phone: customer_info[:phone],
address: customer_info[:address],
note: customer_info[:note],
items: xml_data
)
session[:SHOPPING_CARD_SESSION_NAME] = nil
redirect_to url_for(action: 'thankyou')
end
end
......
class MyCard < ActiveRecord::Base
end
......@@ -31,7 +31,7 @@
<%= form_tag do %>
<div class="text-center">
The information above
<a href="<%= url_for(action: 'checkout') %>" class="btn btn-default">Incorrect, click here</a>
<a href="<%= url_for(action: 'checkout') %>" class="btn btn-default">Incorrect, edit</a>
<%= submit_tag "Correct, click here", class: 'btn btn-primary btn-submit' %>
</div>
<% end %>
......
class CreateMyCards < ActiveRecord::Migration
def change
create_table :my_cards do |t|
t.string :full_name
t.string :email
t.string :phone
t.string :address
t.text :note
t.text :items
t.integer :user_id
t.timestamps
end
end
end
......@@ -11,7 +11,19 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20131023094033) do
ActiveRecord::Schema.define(version: 20131024162951) do
create_table "my_cards", force: true do |t|
t.string "full_name"
t.string "email"
t.string "phone"
t.string "address"
t.text "note"
t.text "items"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "product_categories", force: true do |t|
t.string "name"
......
require 'spec_helper'
describe MyCard do
pending "add some examples to (or delete) #{__FILE__}"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment