Skip to content

Commit

Permalink
feat: add override option to upgrade CTA utils and add course_run_key…
Browse files Browse the repository at this point in the history
… identifier (openedx#35441)

* feat: add override option to upgrade CTAs and send course_run_key identifier
  • Loading branch information
aht007 authored Sep 16, 2024
1 parent 1103544 commit 6a63cfc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
8 changes: 6 additions & 2 deletions common/djangoapps/course_modes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,13 @@ def get(self, request, course_id, error=None): # lint-amnesty, pylint: disable=
if ecommerce_service.is_enabled(request.user):
professional_mode = modes.get(CourseMode.NO_ID_PROFESSIONAL_MODE) or modes.get(CourseMode.PROFESSIONAL)
if purchase_workflow == "single" and professional_mode.sku:
redirect_url = ecommerce_service.get_checkout_page_url(professional_mode.sku)
redirect_url = ecommerce_service.get_checkout_page_url(
professional_mode.sku, course_run_keys=[course_id]
)
if purchase_workflow == "bulk" and professional_mode.bulk_sku:
redirect_url = ecommerce_service.get_checkout_page_url(professional_mode.bulk_sku)
redirect_url = ecommerce_service.get_checkout_page_url(
professional_mode.bulk_sku, course_run_keys=[course_id]
)
return redirect(redirect_url)
course = modulestore().get_course(course_key)

Expand Down
9 changes: 7 additions & 2 deletions lms/djangoapps/commerce/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
should_redirect_to_commerce_coordinator_checkout,
should_redirect_to_commerce_coordinator_refunds,
)
from edx_django_utils.plugins import pluggable_override

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -56,6 +57,7 @@ def ecommerce_url_root(self):
""" Retrieve Ecommerce service public url root. """
return configuration_helpers.get_value('ECOMMERCE_PUBLIC_URL_ROOT', settings.ECOMMERCE_PUBLIC_URL_ROOT)

@pluggable_override('OVERRIDE_GET_ABSOLUTE_ECOMMERCE_URL')
def get_absolute_ecommerce_url(self, ecommerce_page_url):
""" Return the absolute URL to the ecommerce page.
Expand Down Expand Up @@ -110,20 +112,21 @@ def payment_page_url(self):

def get_add_to_basket_url(self):
""" Return the URL for the payment page based on the waffle switch.
Example:
http://localhost/enabled_service_api_path
"""
if should_redirect_to_commerce_coordinator_checkout():
return urljoin(settings.COMMERCE_COORDINATOR_URL_ROOT, settings.COORDINATOR_CHECKOUT_REDIRECT_PATH)
return self.payment_page_url()

@pluggable_override('OVERRIDE_GET_CHECKOUT_PAGE_URL')
def get_checkout_page_url(self, *skus, **kwargs):
""" Construct the URL to the ecommerce checkout page and include products.
Args:
skus (list): List of SKUs associated with products to be added to basket
program_uuid (string): The UUID of the program, if applicable
course_run_keys (list): The course run keys of the products to be added to basket.
Returns:
Absolute path to the ecommerce checkout page showing basket that contains specified products.
Expand Down Expand Up @@ -153,10 +156,12 @@ def upgrade_url(self, user, course_key):
"""
Returns the URL for the user to upgrade, or None if not applicable.
"""
course_run_key = str(course_key)

verified_mode = CourseMode.verified_mode_for_course(course_key)
if verified_mode:
if self.is_enabled(user):
return self.get_checkout_page_url(verified_mode.sku)
return self.get_checkout_page_url(verified_mode.sku, course_run_keys=[course_run_key])
else:
return reverse('dashboard')
return None
Expand Down
8 changes: 6 additions & 2 deletions lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,9 +825,13 @@ def course_about(request, course_id): # pylint: disable=too-many-statements
single_paid_mode = modes.get(CourseMode.PROFESSIONAL)

if single_paid_mode and single_paid_mode.sku:
ecommerce_checkout_link = ecomm_service.get_checkout_page_url(single_paid_mode.sku)
ecommerce_checkout_link = ecomm_service.get_checkout_page_url(
single_paid_mode.sku, course_run_keys=[course_id]
)
if single_paid_mode and single_paid_mode.bulk_sku:
ecommerce_bulk_checkout_link = ecomm_service.get_checkout_page_url(single_paid_mode.bulk_sku)
ecommerce_bulk_checkout_link = ecomm_service.get_checkout_page_url(
single_paid_mode.bulk_sku, course_run_keys=[course_id]
)

registration_price, course_price = get_course_prices(course) # lint-amnesty, pylint: disable=unused-variable

Expand Down
3 changes: 2 additions & 1 deletion lms/djangoapps/verify_student/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ def _redirect_if_necessary(
if ecommerce_service.is_enabled(user):
url = ecommerce_service.get_checkout_page_url(
sku,
catalog=self.request.GET.get('catalog')
catalog=self.request.GET.get('catalog'),
course_run_keys=[str(course_key)]
)

# Redirect if necessary, otherwise implicitly return None
Expand Down
4 changes: 3 additions & 1 deletion openedx/core/djangoapps/programs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,9 @@ def _attach_course_run_upgrade_url(self, run_mode):
ecommerce = EcommerceService()
sku = getattr(required_mode, "sku", None)
if ecommerce.is_enabled(self.user) and sku:
run_mode["upgrade_url"] = ecommerce.get_checkout_page_url(required_mode.sku)
run_mode["upgrade_url"] = ecommerce.get_checkout_page_url(
required_mode.sku, course_run_keys=[self.course_run_key]
)
else:
run_mode["upgrade_url"] = None
else:
Expand Down
6 changes: 3 additions & 3 deletions openedx/features/content_type_gating/partitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def access_denied_fragment(self, block, user, user_group, allowed_groups):
if expiration_datetime and expiration_datetime < datetime.datetime.now(pytz.UTC):
ecommerce_checkout_link = None
else:
ecommerce_checkout_link = self._get_checkout_link(user, verified_mode.sku)
ecommerce_checkout_link = self._get_checkout_link(user, verified_mode.sku, str(course_key))

request = crum.get_current_request()

Expand All @@ -118,11 +118,11 @@ def access_denied_message(self, block_key, user, user_group, allowed_groups):
else:
return _("Graded assessments are available to Verified Track learners. Upgrade to Unlock.")

def _get_checkout_link(self, user, sku):
def _get_checkout_link(self, user, sku, course_run_key):
ecomm_service = EcommerceService()
ecommerce_checkout = ecomm_service.is_enabled(user)
if ecommerce_checkout and sku:
return ecomm_service.get_checkout_page_url(sku) or ''
return ecomm_service.get_checkout_page_url(sku, course_run_keys=[course_run_key]) or ''

def _get_course_key_from_course_block(self, block):
"""
Expand Down
2 changes: 2 additions & 0 deletions openedx/features/discounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.conf import settings
from django.utils.translation import get_language
from django.utils.translation import gettext as _
from edx_django_utils.plugins import pluggable_override

from common.djangoapps.course_modes.models import format_course_price, get_course_prices
from lms.djangoapps.experiments.models import ExperimentData
Expand Down Expand Up @@ -73,6 +74,7 @@ def _get_discount_prices(user, course, assume_discount=False):
return format_course_price(base_price), None, None


@pluggable_override("OVERRIDE_GENERATE_OFFER_DATA")
def generate_offer_data(user, course):
"""
Create a dictionary of information about the current discount offer.
Expand Down

0 comments on commit 6a63cfc

Please sign in to comment.