Class: Cornerstore::Order
- Inherits:
-
Model::Base
- Object
- Model::Base
- Cornerstore::Order
- Defined in:
- lib/cornerstore/api/order.rb
Instance Attribute Summary collapse
-
#billing_address ⇒ Object
Returns the value of attribute billing_address.
-
#cancellations ⇒ Object
Returns the value of attribute cancellations.
-
#checkout_id ⇒ Object
Returns the value of attribute checkout_id.
-
#checkout_started_at ⇒ Object
Returns the value of attribute checkout_started_at.
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#customer_comment ⇒ Object
Returns the value of attribute customer_comment.
-
#invoice_number ⇒ Object
Returns the value of attribute invoice_number.
-
#invoiced_at ⇒ Object
Returns the value of attribute invoiced_at.
-
#line_items ⇒ Object
Returns the value of attribute line_items.
-
#number ⇒ Object
Returns the value of attribute number.
-
#payment_costs ⇒ Object
Returns the value of attribute payment_costs.
-
#payment_means ⇒ Object
Returns the value of attribute payment_means.
-
#placed_at ⇒ Object
Returns the value of attribute placed_at.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#requested_carrier ⇒ Object
Returns the value of attribute requested_carrier.
-
#sales_tax ⇒ Object
Returns the value of attribute sales_tax.
-
#shipments ⇒ Object
Returns the value of attribute shipments.
-
#shipping_address ⇒ Object
Returns the value of attribute shipping_address.
-
#shipping_costs ⇒ Object
Returns the value of attribute shipping_costs.
-
#subtotal ⇒ Object
Returns the value of attribute subtotal.
-
#total ⇒ Object
Returns the value of attribute total.
-
#weight ⇒ Object
Returns the value of attribute weight.
Attributes inherited from Model::Base
#_id, #_slugs, #created_at, #parent, #updated_at
Instance Method Summary collapse
-
#canceled? ⇒ Boolean
Returns true if at least one line item of this order is canceled.
- #check_signature ⇒ Object
-
#completely_canceled? ⇒ Boolean
Returns true if all line items are canceled.
-
#completely_shipped? ⇒ Boolean
Returns true if all line items are shipped.
- #handling_costs ⇒ Object
-
#initialize(attributes, parent = nil) ⇒ Order
constructor
A new instance of Order.
- #invoiced? ⇒ Boolean
- #requires_shipment? ⇒ Boolean
-
#shipped? ⇒ Boolean
Returns true if at least one line item of this order is shipped.
Methods inherited from Model::Base
#==, #attributes, #attributes=, #inspect, #method_missing, method_missing, #to_param, #url
Constructor Details
#initialize(attributes, parent = nil) ⇒ Order
Returns a new instance of Order.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cornerstore/api/order.rb', line 27 def initialize(attributes, parent=nil) self.payment_costs = Cornerstore::Price.new(attributes.delete('payment_costs')) if attributes['payment_costs'] self.shipping_costs = Cornerstore::Price.new(attributes.delete('shipping_costs')) if attributes['shipping_costs'] self.subtotal = Cornerstore::Price.new(attributes.delete('subtotal')) self.sales_tax = Cornerstore::Price.new(attributes.delete('sales_tax')) if attributes['sales_tax'] self.total = Cornerstore::Price.new(attributes.delete('total')) self.customer = Cornerstore::Customer.new(attributes.delete('customer')) self.shipping_address = Cornerstore::Address.new(attributes.delete('shipping_address')) self.billing_address = Cornerstore::Address.new(attributes.delete('billing_address')) self.payment_means = Cornerstore::PaymentMeans.new(attributes.delete('payment_means')) self.requested_carrier = Cornerstore::Carrier.new(attributes.delete('requested_carrier')) self.line_items = Cornerstore::LineItem::Resource.new(self, attributes.delete('line_items') || [], 'line_items') self.shipments = Cornerstore::Shipment::Resource.new(self, attributes.delete('shipments') || [], 'shipments') self.cancellations = Cornerstore::Cancellation::Resource.new(self, attributes.delete('cancellations') || [], 'cancellations') self.placed_at = DateTime.parse(attributes.delete('placed_at')) unless attributes['placed_at'].blank? self.invoiced_at = DateTime.parse(attributes.delete('invoiced_at')) unless attributes['invoiced_at'].blank? super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Cornerstore::Model::Base
Instance Attribute Details
#billing_address ⇒ Object
Returns the value of attribute billing_address.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def billing_address @billing_address end |
#cancellations ⇒ Object
Returns the value of attribute cancellations.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def cancellations @cancellations end |
#checkout_id ⇒ Object
Returns the value of attribute checkout_id.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def checkout_id @checkout_id end |
#checkout_started_at ⇒ Object
Returns the value of attribute checkout_started_at.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def checkout_started_at @checkout_started_at end |
#customer ⇒ Object
Returns the value of attribute customer.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def customer @customer end |
#customer_comment ⇒ Object
Returns the value of attribute customer_comment.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def customer_comment @customer_comment end |
#invoice_number ⇒ Object
Returns the value of attribute invoice_number.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def invoice_number @invoice_number end |
#invoiced_at ⇒ Object
Returns the value of attribute invoiced_at.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def invoiced_at @invoiced_at end |
#line_items ⇒ Object
Returns the value of attribute line_items.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def line_items @line_items end |
#number ⇒ Object
Returns the value of attribute number.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def number @number end |
#payment_costs ⇒ Object
Returns the value of attribute payment_costs.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def payment_costs @payment_costs end |
#payment_means ⇒ Object
Returns the value of attribute payment_means.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def payment_means @payment_means end |
#placed_at ⇒ Object
Returns the value of attribute placed_at.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def placed_at @placed_at end |
#reference ⇒ Object
Returns the value of attribute reference.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def reference @reference end |
#requested_carrier ⇒ Object
Returns the value of attribute requested_carrier.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def requested_carrier @requested_carrier end |
#sales_tax ⇒ Object
Returns the value of attribute sales_tax.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def sales_tax @sales_tax end |
#shipments ⇒ Object
Returns the value of attribute shipments.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def shipments @shipments end |
#shipping_address ⇒ Object
Returns the value of attribute shipping_address.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def shipping_address @shipping_address end |
#shipping_costs ⇒ Object
Returns the value of attribute shipping_costs.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def shipping_costs @shipping_costs end |
#subtotal ⇒ Object
Returns the value of attribute subtotal.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def subtotal @subtotal end |
#total ⇒ Object
Returns the value of attribute total.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def total @total end |
#weight ⇒ Object
Returns the value of attribute weight.
2 3 4 |
# File 'lib/cornerstore/api/order.rb', line 2 def weight @weight end |
Instance Method Details
#canceled? ⇒ Boolean
Returns true if at least one line item of this order is canceled
60 61 62 |
# File 'lib/cornerstore/api/order.rb', line 60 def canceled? !self.cancellations.empty? end |
#check_signature ⇒ Object
90 91 92 93 |
# File 'lib/cornerstore/api/order.rb', line 90 def check_signature # TODO: Implement signature check return true end |
#completely_canceled? ⇒ Boolean
Returns true if all line items are canceled
74 75 76 |
# File 'lib/cornerstore/api/order.rb', line 74 def completely_canceled? self.cancellations.collect(&:canceled_items).flatten.size == self.line_items.size end |
#completely_shipped? ⇒ Boolean
Returns true if all line items are shipped
69 70 71 |
# File 'lib/cornerstore/api/order.rb', line 69 def completely_shipped? self.shipments.collect(&:shipped_items).flatten.size == self.line_items.size end |
#handling_costs ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cornerstore/api/order.rb', line 78 def handling_costs if self.shipping_costs and self.payment_costs self.shipping_costs + self.payment_costs elsif self.shipping_costs self.shipping_costs elsif self.payment_costs self.payment_costs else nil end end |
#invoiced? ⇒ Boolean
64 65 66 |
# File 'lib/cornerstore/api/order.rb', line 64 def invoiced? !self.invoice_number.blank? end |
#requires_shipment? ⇒ Boolean
50 51 52 |
# File 'lib/cornerstore/api/order.rb', line 50 def requires_shipment? self.line_items.any? { |li| li.requires_shipment? } end |
#shipped? ⇒ Boolean
Returns true if at least one line item of this order is shipped
55 56 57 |
# File 'lib/cornerstore/api/order.rb', line 55 def shipped? !self.shipments.empty? end |