Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
new logic of orders
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashnikovisme committed Feb 20, 2014
1 parent 0dfda80 commit 57f6099
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
13 changes: 9 additions & 4 deletions app/controllers/web/account/buys_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
class Web::Account::BuysController < Web::Account::ApplicationController
def pay
@order_pay = OrderPayType.new
@order = Order.new(items_count: 1, user_id: params[:shirt_order][:user_id])
@order.cost = 0
if params[:ticket_order]
@ticket_order = TicketOrder.new(items_count: 1, user_id: params[:shirt_order][:user_id])
@ticket_order.save
@order.cost += @ticket_order.its_cost
end
@order_pay.ticket_order = @ticket_order
@shirt_order = ShirtOrder.new params[:shirt_order]
if @shirt_order.save
@order_pay.shirt_order = @shirt_order
@order.cost += @shirt_order.its_cost
end
if @order.save
redirect_to build_payment_curl @order
else
redirect_to edit_account_path
end
redirect_to build_payment_curl @order_pay
end
end
2 changes: 1 addition & 1 deletion app/models/afterparty_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def to_s
"#{I18n.t("activerecord.models.afterparty_order")}"
end

def cost
def its_cost
self.items_count * configus.platidoma.afterparty_price
end

Expand Down
3 changes: 1 addition & 2 deletions app/models/shirt_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class ShirtOrder < Order
extend Enumerize

attr_accessible :item_size, :item_color
belongs_to :order_option

validates :item_size, presence: true
validates :item_color, presence: true
Expand All @@ -15,7 +14,7 @@ def to_s
"#{I18n.t("activerecord.models.shirt_order")} (#{item_size}, #{item_color})"
end

def cost
def its_cost
self.items_count * configus.platidoma.shirt_price
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/ticket_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class TicketOrder < Order
extend Enumerize
extend ActiveModel::Naming

def cost
def its_cost
configus.platidoma.ticket_price
end

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20140220004726_add_cost_to_order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCostToOrder < ActiveRecord::Migration
def change
add_column :orders, :cost, :integer
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20140211041744) do
ActiveRecord::Schema.define(:version => 20140220003814) do

create_table "audits", :force => true do |t|
t.integer "auditable_id"
Expand Down Expand Up @@ -134,6 +134,7 @@
t.string "item_color"
t.string "ticket_type"
t.integer "order_option_id"
t.integer "cost"
end

create_table "pages", :force => true do |t|
Expand Down

0 comments on commit 57f6099

Please sign in to comment.