Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Fix/hardcoded currency 135 #3891

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ecommerce/core/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@


from babel.numbers import get_currency_symbol
from django.conf import settings

from ecommerce.core.url_utils import get_favicon_url, get_lms_dashboard_url, get_lms_url, get_logo_url


Expand All @@ -16,3 +19,20 @@ def core(request):
'favicon_url': get_favicon_url(),
'optimizely_snippet_src': site_configuration.optimizely_snippet_src,
}


def localization(_request):
defaults = getattr(settings, "COURSE_MODE_DEFAULTS", {})
default_currency = defaults.get("currency")
registration_currency = getattr(settings, "PAID_COURSE_REGISTRATION_CURRENCY", None)
currency_code = registration_currency or default_currency or "USD"

if not isinstance(currency_code, str):
raise ValueError(f"Currency code must be a string; currently: {currency_code}")

return {
# Note: babel returns code if not found
# get_currency_symbol("XYZ") => "XYZ"
"currency_symbol_": get_currency_symbol(currency_code),
"currency_code_": currency_code,
}
19 changes: 19 additions & 0 deletions ecommerce/courses/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ def test_credit_providers_in_context(self):
json.loads(provider_json),
)

@responses.activate
def test_currency_localization(self):
"""Verify the currency symbol is localized based on settings"""
self._create_and_login_staff_user()
self.mock_access_token_response()
__ = self.mock_credit_api_providers()

response = self.client.get(self.path)
self.assertEqual(response.status_code, 200)
# default is USD
self.assertEqual(response.context["currency_symbol_"], "$")
self.assertEqual(response.context["currency_code_"], "USD")

with self.settings(PAID_COURSE_REGISTRATION_CURRENCY="GBP"):
response = self.client.get(self.path)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context["currency_symbol_"], "£")
self.assertEqual(response.context["currency_code_"], "GBP")

@responses.activate
def test_credit_providers_in_context_cached(self):
""" Verify the cached context data includes a list of credit providers. """
Expand Down
1 change: 1 addition & 0 deletions ecommerce/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
'oscar.apps.communication.notifications.context_processors.notifications',
'oscar.core.context_processors.metadata',
'ecommerce.core.context_processors.core',
"ecommerce.core.context_processors.localization",
'ecommerce.extensions.analytics.context_processors.analytics',
),
'debug': True, # Django will only display debug pages if the global DEBUG setting is set to True.
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/static/templates/_course_credit_seats.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<% _.each(creditSeats, function (seat) { %>
<tr class="course-seat">
<td class="seat-credit-provider"><%= seat.get('credit_provider_display_name') %></td>
<td class="seat-price"><%= '$' + Number(seat.get('price')).toLocaleString() %></td>
<td class="seat-price"><%= currencySymbol + Number(seat.get('price')).toLocaleString() %></td>
<td class="seat-credit-hours"><%= seat.get('credit_hours') %></td>
<td class="seat-expires"><% var expires = seat.get('expires');
if (expires) {
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/static/templates/_course_seat.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="seat-type"><%= seat.getSeatTypeDisplayName() %></div>
</div>
<div class="col-sm-4">
<div class="seat-price"><%= gettext('Price:') + ' $' + Number(seat.get('price')).toLocaleString() %></div>
<div class="seat-price"><%= gettext('Price:') + ' ' + currencySymbol + Number(seat.get('price')).toLocaleString() %></div>
<% var expires = seat.get('expires');
if(expires) {
print(gettext('Upgrade Deadline:') + ' ' + moment.utc(expires).format('lll z'));
Expand Down
4 changes: 2 additions & 2 deletions ecommerce/static/templates/_offer_course_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ <h4 class="pagination-range pull-right hidden-xs">Showing <%= (courses.lowerLimi
<% } else { %>
<div class="pull-left">
<p class="course-price">
<span>$<%= course.attributes.stockrecords.price_excl_tax %></span>
<span>{{ currency_symbol_ }}<%= course.attributes.stockrecords.price_excl_tax %></span>
</p>
</div>
<div class="pull-left">
<p class="course-new-price">
<span><%- gettext('Now') %> $<%= course.attributes.new_price %></span>
<span><%- gettext('Now') %> {{ currency_symbol_ }}<%= course.attributes.new_price %></span>
</p>
</div>
<% } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="seat-type"><%= gettext('Audit') %></div>
</div>
<div class="col-sm-4">
<span class="price-label"><%= gettext('Price (in USD)') %>:</span> <span class="seat-price">$0.00</span>
<span class="price-label"><%= gettext('Price (in USD)') %>:</span> <span class="seat-price">{{ currency_symbol_ }}0.00</span>
<input type="hidden" name="price" value="0">
<input type="hidden" name="certificate_type">
<input type="hidden" name="id_verification_required" value="false">
Expand Down
Loading