Class: Atreides::Order
- Includes:
- AASM, Extendable
- Defined in:
- app/models/atreides/order.rb
Constant Summary collapse
- BILLING_COLS =
Constants
%w(zip country street city province).freeze
Instance Attribute Summary collapse
-
#card_expires_on ⇒ Object
Returns the value of attribute card_expires_on.
-
#card_number ⇒ Object
Returns the value of attribute card_number.
-
#card_type ⇒ Object
Returns the value of attribute card_type.
-
#card_verification ⇒ Object
Returns the value of attribute card_verification.
Class Method Summary collapse
Instance Method Summary collapse
- #address ⇒ Object
-
#full_name ⇒ Object
Instance Methods.
- #number ⇒ Object
- #total_amounts ⇒ Object
Methods inherited from Base
Instance Attribute Details
#card_expires_on ⇒ Object
Returns the value of attribute card_expires_on.
17 18 19 |
# File 'app/models/atreides/order.rb', line 17 def card_expires_on @card_expires_on end |
#card_number ⇒ Object
Returns the value of attribute card_number.
17 18 19 |
# File 'app/models/atreides/order.rb', line 17 def card_number @card_number end |
#card_type ⇒ Object
Returns the value of attribute card_type.
17 18 19 |
# File 'app/models/atreides/order.rb', line 17 def card_type @card_type end |
#card_verification ⇒ Object
Returns the value of attribute card_verification.
17 18 19 |
# File 'app/models/atreides/order.rb', line 17 def card_verification @card_verification end |
Class Method Details
.build_order_for_user(user) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/models/atreides/order.rb', line 77 def build_order_for_user(user) # Get address info if user has previous orders attrs = {} if old_order = user.orders.first old_order.attributes.each{|k,v| attrs[k] = v if BILLING_COLS.include?(k) } end # Build new object new(attrs.update({ :user => user, :first_name => user.first_name, :last_name => user.last_name, :line_items => user.cart_items, :amount => Money.new(user.cart_items.sum(:price_cents)), :ip_address => user.current_login_ip })) end |
Instance Method Details
#address ⇒ Object
108 109 110 |
# File 'app/models/atreides/order.rb', line 108 def address %w(street city province zip country).map{|f| self.send(f) }.compact.join("\n") end |
#full_name ⇒ Object
Instance Methods
99 100 101 |
# File 'app/models/atreides/order.rb', line 99 def full_name [first_name, last_name].join(' ') end |
#number ⇒ Object
103 104 105 106 |
# File 'app/models/atreides/order.rb', line 103 def number # TODO: Format this as something more user friendly [id, created_at].map(&:to_i).join('-') end |
#total_amounts ⇒ Object
112 113 114 115 116 117 118 |
# File 'app/models/atreides/order.rb', line 112 def total_amounts # Set price self.amount = line_items.to_a.sum{ |i| i.total_price } # Set final amount to be paid self.final_amount = amount - discount end |