From 0487f8124f07a080017791f393dc54f968b66575 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Mon, 16 Dec 2024 14:56:17 -0500 Subject: [PATCH] fix: ensure course run key is passed in legacy enrollment urls --- enterprise_catalog/apps/catalog/models.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/enterprise_catalog/apps/catalog/models.py b/enterprise_catalog/apps/catalog/models.py index aaaf7999..ebc923b9 100644 --- a/enterprise_catalog/apps/catalog/models.py +++ b/enterprise_catalog/apps/catalog/models.py @@ -57,6 +57,7 @@ get_parent_content_key, localized_utcnow, ) +from enterprise_catalog.apps.catalog.algolia_utils import get_advertised_course_run LOGGER = getLogger(__name__) @@ -555,10 +556,19 @@ def get_content_enrollment_url(self, content_metadata): else: # Catalog param only needed for legacy (non-learner-portal) enrollment URLs params['catalog'] = self.uuid + + course_key = content_key if parent_content_key else None + course_run_key = content_key if not parent_content_key else None + + if parent_content_key: + advertised_course_run = get_advertised_course_run(content_metadata.json_metadata) + if advertised_course_run: + course_run_key = advertised_course_run['key'] + url = '{}/enterprise/{}/course/{}/enroll/'.format( settings.LMS_BASE_URL, self.enterprise_uuid, - content_key, + course_run_key or course_key, ) return update_query_parameters(url, params)