Class: Spree::OrderPopulator

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/order_populator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, currency) ⇒ OrderPopulator

Returns a new instance of OrderPopulator.



6
7
8
9
10
# File 'app/models/spree/order_populator.rb', line 6

def initialize(order, currency)
  @order = order
  @currency = currency
  @errors = ActiveModel::Errors.new(self)
end

Instance Attribute Details

#currencyObject

Returns the value of attribute currency.



3
4
5
# File 'app/models/spree/order_populator.rb', line 3

def currency
  @currency
end

#errorsObject (readonly)

Returns the value of attribute errors.



4
5
6
# File 'app/models/spree/order_populator.rb', line 4

def errors
  @errors
end

#orderObject

Returns the value of attribute order.



3
4
5
# File 'app/models/spree/order_populator.rb', line 3

def order
  @order
end

Instance Method Details

#populate(variant_id, quantity) ⇒ Object



12
13
14
15
16
# File 'app/models/spree/order_populator.rb', line 12

def populate(variant_id, quantity)
  attempt_cart_add(variant_id, quantity)
  order.ensure_updated_shipments
  valid?
end

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/models/spree/order_populator.rb', line 18

def valid?
  errors.empty?
end