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_pricingObject



135
136
137
138
139
140
141
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 135

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_registrantObject



116
117
118
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 116

def build_course_registrant
  course_registrants.build(owner: owner, learndash_course: learndash_course)
end

#courseObject



100
101
102
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 100

def course
  learndash_course
end

#course!Object

After the course step.



144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 144

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 prices
  assign_pricing()
  raise('expected course_registrants to have a price') if course_registrants.any? { |registrant| registrant.price.blank? }

  # Save record
  save!
end

#course_registrantObject



112
113
114
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 112

def course_registrant
  course_registrants.first
end

#done?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 108

def done?
  
end

#in_progress?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 104

def in_progress?
  draft?
end

#learndash_ownerObject



120
121
122
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 120

def learndash_owner
  (course_registrant&.owner || owner)
end

#member_pricing?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 124

def member_pricing?
  learndash_owner.membership_present?
end

#registration_priceObject



128
129
130
131
132
133
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 128

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_sObject

Instance Methods



96
97
98
# File 'app/models/concerns/effective_learndash_course_registration.rb', line 96

def to_s
  persisted? ? "#{learndash_course} - #{owner}" : 'course registration'
end