Skip to content

Commit 52a63b6

Browse files
Tenzin ChoeyingTenzin Choeying
authored andcommitted
fix: show course price in its own currency on catalog about sidebar
1 parent a37da75 commit 52a63b6

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

  • common/djangoapps/course_modes
  • openedx/core/djangoapps/courseware_api

common/djangoapps/course_modes/models.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,34 @@ def get_course_prices(course, verified_only=False):
928928
return registration_price, format_course_price(price)
929929

930930

931+
def get_course_display_price(course):
932+
"""
933+
Return the course price using the paid mode's OWN currency (e.g. "₹1000"),
934+
or 'Free' when there is no paid mode.
935+
936+
Unlike get_course_prices(), this does not force PAID_COURSE_REGISTRATION_CURRENCY,
937+
so courses priced in any currency (INR, EUR, ...) display correctly instead of "Free".
938+
"""
939+
from babel.numbers import get_currency_symbol
940+
941+
paid_mode = None
942+
for mode in CourseMode.modes_for_course(course.id):
943+
if mode.min_price and mode.min_price > 0:
944+
if mode.slug == CourseMode.VERIFIED:
945+
paid_mode = mode
946+
break
947+
if paid_mode is None:
948+
paid_mode = mode
949+
950+
if not paid_mode:
951+
# No paid mode: keep existing behaviour (handles cosmetic_display_price / "Free").
952+
_, price = get_course_prices(course)
953+
return price
954+
955+
symbol = get_currency_symbol((paid_mode.currency or 'usd').upper())
956+
return f"{symbol}{paid_mode.min_price}"
957+
958+
931959
def format_course_price(price):
932960
"""
933961
Return a formatted price for a course (a string preceded by correct currency, or 'Free').

openedx/core/djangoapps/courseware_api/views.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from xmodule.modulestore.search import path_to_location
2626
from xmodule.x_module import PUBLIC_VIEW, STUDENT_VIEW
2727

28-
from common.djangoapps.course_modes.models import CourseMode, get_course_prices
28+
from common.djangoapps.course_modes.models import CourseMode, get_course_prices, get_course_display_price
2929
from common.djangoapps.util.views import expose_header
3030
from lms.djangoapps.edxnotes.helpers import is_feature_enabled
3131
from lms.djangoapps.certificates.api import get_certificate_url
@@ -499,10 +499,9 @@ def advertised_start(self):
499499
@property
500500
def course_price(self):
501501
"""
502-
Returns the course price, formatted with the currency symbol.
502+
Returns the course price, formatted with the course mode's own currency symbol.
503503
"""
504-
_, course_price = get_course_prices(self.course)
505-
return course_price
504+
return get_course_display_price(self.course)
506505

507506
@property
508507
def pre_requisite_courses(self):

0 commit comments

Comments
 (0)