Module: EffectiveLearndashCourseRegistration
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/effective_learndash_course_registration.rb
Overview
EffectiveLearndashCourseRegistration
Mark your owner model with effective_learndash_course_registration to get all the includes
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary
collapse
Instance Method Details
#assign_pricing ⇒ Object
138
139
140
141
142
143
144
|
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 138
def assign_pricing
course_registrant.assign_attributes(
price: registration_price,
qb_item_name: learndash_course.qb_item_name,
tax_exempt: learndash_course.tax_exempt
)
end
|
#build_course_registrant ⇒ Object
119
120
121
|
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 119
def build_course_registrant
course_registrants.build(owner: owner, learndash_course: learndash_course)
end
|
#course ⇒ Object
103
104
105
|
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 103
def course
learndash_course
end
|
#course! ⇒ Object
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 147
def course!
raise('expected a learndash course') unless learndash_course.present?
raise('expected a course_registrant to be present') unless course_registrant.present?
raise('expected a course_registrant to have an owner') unless course_registrant.owner.present?
raise('expected a learndash owner') unless learndash_owner.class.try(:effective_learndash_owner?)
assign_pricing()
raise('expected course_registrants to have a price') if course_registrants.any? { |registrant| registrant.price.blank? }
save!
end
|
#course_registrant ⇒ Object
115
116
117
|
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 115
def course_registrant
course_registrants.first
end
|
#done? ⇒ Boolean
111
112
113
|
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 111
def done?
submitted?
end
|
#in_progress? ⇒ Boolean
107
108
109
|
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 107
def in_progress?
draft?
end
|
#learndash_owner ⇒ Object
123
124
125
|
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 123
def learndash_owner
(course_registrant&.owner || owner)
end
|
#member_pricing? ⇒ Boolean
127
128
129
|
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 127
def member_pricing?
learndash_owner.membership_present?
end
|
#registration_price ⇒ Object
131
132
133
134
135
136
|
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 131
def registration_price
raise('expected a learndash course') unless learndash_course.present?
raise('expected a learndash owner') unless learndash_owner.present?
member_pricing? ? learndash_course.member_price : learndash_course.regular_price
end
|
#to_s ⇒ Object
99
100
101
|
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 99
def to_s
persisted? ? "#{learndash_course} - #{owner}" : 'course registration'
end
|