Class: Caboose::Order
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Caboose::Order
- Defined in:
- app/models/caboose/order.rb
Constant Summary collapse
- STATUS_CART =
:payment_status, :cancel_reason,
:date_authorized, :date_captured, :date_cancelled, :email,
:payment_id, :gateway_id,
:transaction_d, :auth_code,
:amount_discounted, :shipping_carrier, :shipping_service_code, :order_number,
:date_shipped, :transaction_service, :transaction_id
'cart'
- STATUS_PENDING =
'pending'
- STATUS_CANCELED =
'canceled'
- STATUS_SHIPPED =
'shipped'
- STATUS_TESTING =
'testing'
Instance Method Summary collapse
- #authorized? ⇒ Boolean
- #calculate ⇒ Object
- #calculate_discount ⇒ Object
- #calculate_handling ⇒ Object
- #calculate_shipping ⇒ Object
- #calculate_subtotal ⇒ Object
- #calculate_tax ⇒ Object
- #calculate_total ⇒ Object
- #capture ⇒ Object
-
#decrement_quantities ⇒ Object
def as_json(options={}) self.attributes.merge({ :line_items => self.line_items, :shipping_address => self.shipping_address, :billing_address => self.billing_address }) end.
- #increment_quantities ⇒ Object
- #item_count ⇒ Object
- #line_item_added(line_item) ⇒ Object
- #line_item_removed(line_item) ⇒ Object
-
#packages ⇒ Object
Methods.
- #refuned ⇒ Object
- #resend_confirmation ⇒ Object
- #shipping_and_handling ⇒ Object
- #take_gift_card_funds ⇒ Object
- #test? ⇒ Boolean
- #void ⇒ Object
Instance Method Details
#authorized? ⇒ Boolean
143 144 145 |
# File 'app/models/caboose/order.rb', line 143 def self.financial_status == 'authorized' end |
#calculate ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'app/models/caboose/order.rb', line 167 def calculate self.update_column(:subtotal , self.calculate_subtotal ) self.update_column(:tax , self.calculate_tax ) self.update_column(:shipping , self.calculate_shipping ) self.update_column(:handling , self.calculate_handling ) self.update_column(:discount , self.calculate_discount ) self.update_column(:total , self.calculate_total ) end |
#calculate_discount ⇒ Object
200 201 202 203 204 205 206 |
# File 'app/models/caboose/order.rb', line 200 def calculate_discount return 0.0 if self.discounts.nil? || self.discounts.count == 0 x = 0.0 self.discounts.each{ |d| x = x + d.amount } x = x + self.custom_discount if self.custom_discount return x end |
#calculate_handling ⇒ Object
195 196 197 198 |
# File 'app/models/caboose/order.rb', line 195 def calculate_handling return 0.0 if self.site.nil? || self.site.store_config.nil? self.subtotal * self.site.store_config.handling_percentage.to_f end |
#calculate_shipping ⇒ Object
188 189 190 191 192 193 |
# File 'app/models/caboose/order.rb', line 188 def calculate_shipping return 0.0 if self.order_packages.nil? || self.order_packages.count == 0 x = 0.0 self.order_packages.each{ |op| x = x + op.total } return x end |
#calculate_subtotal ⇒ Object
176 177 178 179 180 181 |
# File 'app/models/caboose/order.rb', line 176 def calculate_subtotal return 0.0 if self.line_items.empty? x = 0.0 self.line_items.each{ |li| x = x + li.variant.price } return x end |
#calculate_tax ⇒ Object
183 184 185 186 |
# File 'app/models/caboose/order.rb', line 183 def calculate_tax return 0.0 if !self.shipping_address self.subtotal * TaxCalculator.tax_rate(self.shipping_address) end |
#calculate_total ⇒ Object
208 209 210 |
# File 'app/models/caboose/order.rb', line 208 def calculate_total return (self.subtotal + self.tax + self.shipping + self.handling) - self.discount end |
#capture ⇒ Object
147 148 149 |
# File 'app/models/caboose/order.rb', line 147 def capture PaymentProcessor.capture(self) end |
#decrement_quantities ⇒ Object
def as_json(options={})
self.attributes.merge({
:line_items => self.line_items,
:shipping_address => self.shipping_address,
:billing_address => self.billing_address
})
end
115 116 117 118 119 120 121 122 123 |
# File 'app/models/caboose/order.rb', line 115 def decrement_quantities return false if self.decremented self.line_items.each do |line_item| line_item.variant.update_attribute(:quantity, line_item.variant.quantity_in_stock - line_item.quantity) end self.update_attribute(:decremented, true) end |
#increment_quantities ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'app/models/caboose/order.rb', line 125 def increment_quantities return false if !self.decremented self.line_items.each do |line_item| line_item.variant.update_attribute(:quantity, line_item.variant.quantity_in_stock - line_item.quantity) end self.update_attribute(:decremented, false) end |
#item_count ⇒ Object
216 217 218 219 220 |
# File 'app/models/caboose/order.rb', line 216 def item_count count = 0 self.line_items.each{ |li| count = count + li.quantity } if self.line_items return count end |
#line_item_added(line_item) ⇒ Object
159 160 161 |
# File 'app/models/caboose/order.rb', line 159 def line_item_added(line_item) self.calculate end |
#line_item_removed(line_item) ⇒ Object
163 164 165 |
# File 'app/models/caboose/order.rb', line 163 def line_item_removed(line_item) self.calculate end |
#packages ⇒ Object
Methods
103 104 105 |
# File 'app/models/caboose/order.rb', line 103 def packages self.order_packages end |
#refuned ⇒ Object
151 152 153 |
# File 'app/models/caboose/order.rb', line 151 def refuned PaymentProcessor.refund(self) end |
#resend_confirmation ⇒ Object
135 136 137 |
# File 'app/models/caboose/order.rb', line 135 def resend_confirmation OrdersMailer.configure_for_site(self.site_id).customer_new_order(self).deliver end |
#shipping_and_handling ⇒ Object
212 213 214 |
# File 'app/models/caboose/order.rb', line 212 def shipping_and_handling (self.shipping ? self.shipping : 0.0) + (self.handling ? self.handling : 0.0) end |
#take_gift_card_funds ⇒ Object
222 223 224 225 226 227 228 229 |
# File 'app/models/caboose/order.rb', line 222 def take_gift_card_funds return if self.discounts.nil? || self.discounts.count == 0 self.discounts.each do |d| gc = d.gift_card gc.balance = gc.balance - d.amount gc.save end end |
#test? ⇒ Boolean
139 140 141 |
# File 'app/models/caboose/order.rb', line 139 def test? self.status == 'testing' end |
#void ⇒ Object
155 156 157 |
# File 'app/models/caboose/order.rb', line 155 def void PaymentProcessor.void(self) end |