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, options = {}) ⇒ Object



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

def populate(variant_id, quantity, options = {})
  # protect against passing a nil hash being passed in
  # due to an empty params[:options]
  attempt_cart_add(variant_id, quantity, options || {})
  valid?
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  errors.empty?
end