Class: Caboose::Order
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Caboose::Order
- Defined in:
- app/models/caboose/order.rb
Constant Summary collapse
- STATUS_CART =
'cart'
- STATUS_PENDING =
'pending'
- STATUS_CANCELED =
'canceled'
- STATUS_READY_TO_SHIP =
'ready to ship'
- STATUS_SHIPPED =
'shipped'
- STATUS_TESTING =
'testing'
- FINANCIAL_STATUS_PENDING =
'pending'
- FINANCIAL_STATUS_AUTHORIZED =
'authorized'
- FINANCIAL_STATUS_CAPTURED =
'captured'
- FINANCIAL_STATUS_REFUNDED =
'refunded'
- FINANCIAL_STATUS_VOIDED =
'voided'
Instance Method Summary collapse
- #authorized? ⇒ Boolean
- #calculate ⇒ Object
- #calculate_discount ⇒ Object
- #calculate_gift_wrap ⇒ Object
- #calculate_handling ⇒ Object
- #calculate_shipping ⇒ Object
- #calculate_subtotal ⇒ Object
- #calculate_tax ⇒ Object
- #calculate_total ⇒ Object
- #capture ⇒ Object
- #check_nil_fields ⇒ Object
- #decrement_quantities ⇒ Object
- #has_downloadable_items? ⇒ Boolean
- #has_empty_shipping_methods? ⇒ Boolean
- #has_shippable_items? ⇒ Boolean
- #increment_quantities ⇒ Object
- #item_count ⇒ Object
- #refund ⇒ Object
- #resend_confirmation ⇒ Object
- #shipping_and_handling ⇒ Object
- #take_gift_card_funds ⇒ Object
- #test? ⇒ Boolean
- #void ⇒ Object
Instance Method Details
#authorized? ⇒ Boolean
123 124 125 |
# File 'app/models/caboose/order.rb', line 123 def self.financial_status == 'authorized' end |
#calculate ⇒ Object
139 140 141 142 143 144 145 146 147 |
# File 'app/models/caboose/order.rb', line 139 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(:gift_wrap , self.calculate_gift_wrap ) self.update_column(:discount , self.calculate_discount ) self.update_column(:total , self.calculate_total ) end |
#calculate_discount ⇒ Object
183 184 185 186 187 188 189 |
# File 'app/models/caboose/order.rb', line 183 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_gift_wrap ⇒ Object
173 174 175 176 177 178 179 180 181 |
# File 'app/models/caboose/order.rb', line 173 def calculate_gift_wrap x = 0.0 self.line_items.each do |li| next if !li.gift_wrap next if !li.variant.product.allow_gift_wrap x = x + li.variant.product.gift_wrap_price * li.quantity end return x end |
#calculate_handling ⇒ Object
168 169 170 171 |
# File 'app/models/caboose/order.rb', line 168 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
161 162 163 164 165 166 |
# File 'app/models/caboose/order.rb', line 161 def calculate_shipping return 0.0 if self.order_packages.nil? || self.order_packages.count == 0 x = 0.0 self.order_packages.all.each{ |op| x = x + op.total } return x end |
#calculate_subtotal ⇒ Object
149 150 151 152 153 154 155 |
# File 'app/models/caboose/order.rb', line 149 def calculate_subtotal return 0.0 if self.line_items.empty? self.line_items.each{ |li| li.verify_unit_price } # Make sure the unit prices are populated x = 0.0 self.line_items.each{ |li| x = x + (li.unit_price * li.quantity) } # Fixed issue with quantity return x end |
#calculate_tax ⇒ Object
157 158 159 |
# File 'app/models/caboose/order.rb', line 157 def calculate_tax return TaxCalculator.tax(self) end |
#calculate_total ⇒ Object
191 192 193 |
# File 'app/models/caboose/order.rb', line 191 def calculate_total return (self.subtotal + self.tax + self.shipping + self.handling + self.gift_wrap) - self.discount end |
#capture ⇒ Object
127 128 129 |
# File 'app/models/caboose/order.rb', line 127 def capture PaymentProcessor.capture(self) end |
#check_nil_fields ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'app/models/caboose/order.rb', line 85 def check_nil_fields self.subtotal = 0.00 if self.subtotal.nil? self.tax = 0.00 if self.tax.nil? self.shipping = 0.00 if self.shipping.nil? self.handling = 0.00 if self.handling.nil? self.custom_discount = 0.00 if self.custom_discount.nil? self.discount = 0.00 if self.discount.nil? self.total = 0.00 if self.total.nil? end |
#decrement_quantities ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'app/models/caboose/order.rb', line 95 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 |
#has_downloadable_items? ⇒ Boolean
223 224 225 226 227 228 |
# File 'app/models/caboose/order.rb', line 223 def has_downloadable_items? self.line_items.each do |li| return true if li.variant.downloadable end return false end |
#has_empty_shipping_methods? ⇒ Boolean
214 215 216 217 218 219 220 221 |
# File 'app/models/caboose/order.rb', line 214 def has_empty_shipping_methods? return true if self.order_packages.nil? return true if self.order_packages.count == 0 self.order_packages.all.each do |op| return true if op.shipping_method_id.nil? end return false end |
#has_shippable_items? ⇒ Boolean
230 231 232 233 234 235 |
# File 'app/models/caboose/order.rb', line 230 def has_shippable_items? self.line_items.each do |li| return true if !li.variant.downloadable end return false end |
#increment_quantities ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'app/models/caboose/order.rb', line 105 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
199 200 201 202 203 |
# File 'app/models/caboose/order.rb', line 199 def item_count count = 0 self.line_items.each{ |li| count = count + li.quantity } if self.line_items return count end |
#refund ⇒ Object
131 132 133 |
# File 'app/models/caboose/order.rb', line 131 def refund PaymentProcessor.refund(self) end |
#resend_confirmation ⇒ Object
115 116 117 |
# File 'app/models/caboose/order.rb', line 115 def resend_confirmation OrdersMailer.configure_for_site(self.site_id).customer_new_order(self).deliver end |
#shipping_and_handling ⇒ Object
195 196 197 |
# File 'app/models/caboose/order.rb', line 195 def shipping_and_handling (self.shipping ? self.shipping : 0.0) + (self.handling ? self.handling : 0.0) end |
#take_gift_card_funds ⇒ Object
205 206 207 208 209 210 211 212 |
# File 'app/models/caboose/order.rb', line 205 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
119 120 121 |
# File 'app/models/caboose/order.rb', line 119 def test? self.status == 'testing' end |
#void ⇒ Object
135 136 137 |
# File 'app/models/caboose/order.rb', line 135 def void PaymentProcessor.void(self) end |