Module: Stall::Models::ProductList

Extended by:
ActiveSupport::Concern
Included in:
ProductList
Defined in:
app/models/stall/models/product_list.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'app/models/stall/models/product_list.rb', line 90

def active?
  true
end

#checkoutable?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'app/models/stall/models/product_list.rb', line 86

def checkoutable?
  line_items.length > 0
end

#currencyObject



94
95
96
97
98
99
100
# File 'app/models/stall/models/product_list.rb', line 94

def currency
  @currency ||= if (currency = read_attribute(:currency).presence)
    Money::Currency.new(currency)
  else
    self.currency = Money.default_currency
  end
end

#eot_subtotalObject



60
61
62
# File 'app/models/stall/models/product_list.rb', line 60

def eot_subtotal
  line_items.map(&:eot_price).sum
end

#reset_state!Object



45
46
47
48
# File 'app/models/stall/models/product_list.rb', line 45

def reset_state!
  self.state = wizard.steps.first
  save(validate: false) if persisted?
end

#stateObject



41
42
43
# File 'app/models/stall/models/product_list.rb', line 41

def state
  read_attribute(:state).try(:to_sym)
end

#subtotalObject



54
55
56
57
58
# File 'app/models/stall/models/product_list.rb', line 54

def subtotal
  price = line_items.map(&:price).sum
  price = Money.new(price, currency) unless Money === price
  price
end

#to_paramObject



50
51
52
# File 'app/models/stall/models/product_list.rb', line 50

def to_param
  persisted? ? token : 'empty-cart'
end

#total_eot_priceObject



70
71
72
# File 'app/models/stall/models/product_list.rb', line 70

def total_eot_price
  items.map(&:eot_price).sum
end

#total_priceObject



64
65
66
67
68
# File 'app/models/stall/models/product_list.rb', line 64

def total_price
  price = items.map(&:price).sum
  price = Money.new(price, currency) unless Money === price
  price
end

#total_quantityObject



78
79
80
# File 'app/models/stall/models/product_list.rb', line 78

def total_quantity
  line_items.map(&:quantity).sum
end

#total_vatObject



74
75
76
# File 'app/models/stall/models/product_list.rb', line 74

def total_vat
  items.map(&:vat).sum
end

#wizardObject



82
83
84
# File 'app/models/stall/models/product_list.rb', line 82

def wizard
  @wizard ||= self.class.wizard
end