Class: Opensteam::OrderBase::Order
- Inherits:
-
Container::Base
- Object
- ActiveRecord::Base
- Container::Base
- Opensteam::OrderBase::Order
- Includes:
- StateMachine
- Defined in:
- lib/opensteam/order_base.rb
Overview
Order Model
Class Method Summary collapse
Instance Method Summary collapse
- #existing_customer=(cust) ⇒ Object
- #guest_customer=(cust) ⇒ Object
-
#payment_address=(addr) ⇒ Object
find or create payment-address and associate it with the order.
- #real_payment_address= ⇒ Object
- #real_shipping_address= ⇒ Object
-
#shipping_address=(addr) ⇒ Object
find or create shipping-address and associate it with the order.
-
#to_xml(options = {}) ⇒ Object
override to_xml method.
-
#update_price_and_tax! ⇒ Object
update the calculated tax of all items and the total_tax, total_price of the container (order).
Methods included from StateMachine
Methods inherited from Container::Base
#copy_items_from, #move_items_from, table_name
Class Method Details
.per_page ⇒ Object
101 |
# File 'lib/opensteam/order_base.rb', line 101 def self.per_page ; 3 ; end |
Instance Method Details
#existing_customer=(cust) ⇒ Object
135 136 137 |
# File 'lib/opensteam/order_base.rb', line 135 def existing_customer=(cust) self.real_customer = Opensteam::UserBase::User.find( cust ) end |
#guest_customer=(cust) ⇒ Object
128 129 130 131 132 |
# File 'lib/opensteam/order_base.rb', line 128 def guest_customer=( cust ) cust[:password] = cust[:password_confirmation] = "opensteam" unless cust[:password] cust[:profile] = "Guest" self.real_customer = Opensteam::UserBase::User.create( cust ) end |
#payment_address=(addr) ⇒ Object
find or create payment-address and associate it with the order
143 144 145 |
# File 'lib/opensteam/order_base.rb', line 143 def payment_address= addr self.real_payment_address = get_address( addr ) end |
#real_payment_address= ⇒ Object
141 |
# File 'lib/opensteam/order_base.rb', line 141 alias :real_payment_address= :payment_address= |
#real_shipping_address= ⇒ Object
148 |
# File 'lib/opensteam/order_base.rb', line 148 alias :real_shipping_address= :shipping_address= |
#shipping_address=(addr) ⇒ Object
find or create shipping-address and associate it with the order
150 151 152 |
# File 'lib/opensteam/order_base.rb', line 150 def shipping_address= addr self.real_shipping_address = get_address( addr ) end |
#to_xml(options = {}) ⇒ Object
override to_xml method
104 105 106 |
# File 'lib/opensteam/order_base.rb', line 104 def to_xml( = {} ) #:nodoc: super .merge( :root => "orders" ) end |
#update_price_and_tax! ⇒ Object
update the calculated tax of all items and the total_tax, total_price of the container (order)
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/opensteam/order_base.rb', line 110 def update_price_and_tax! country = shipping_address ? shipping_address.country : Opensteam::Config::DEFAULT_COUNTRY items.each do |item| item.update_attribute( :tax, item.calculate_tax( :country => country ) ) end returning( self ) do |s| s.total_price = items.collect(&:total_price).sum s.total_tax = items.collect(&:tax).sum end end |