Skip to content

Commit db0159b

Browse files
rameerezclaude
andcommitted
Add has_plan_assignment? and plan_assignment helpers to PlanOwner
These helpers allow checking if a plan owner has a manual plan assignment without going through the full plan resolution logic. Useful for UI conditionals like upsell banners that should not show when an admin has manually assigned a plan. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f29647f commit db0159b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/pricing_plans/plan_owner.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ def on_free_plan?
203203
plan&.free? || false
204204
end
205205

206+
def has_plan_assignment?
207+
return false unless respond_to?(:id) && id.present?
208+
Assignment.exists?(plan_owner_type: self.class.name, plan_owner_id: id)
209+
end
210+
211+
def plan_assignment
212+
return nil unless respond_to?(:id) && id.present?
213+
Assignment.find_by(plan_owner_type: self.class.name, plan_owner_id: id)
214+
end
215+
206216
def assign_pricing_plan!(plan_key, source: "manual")
207217
Assignment.assign_plan_to(self, plan_key, source: source)
208218
end

0 commit comments

Comments
 (0)