update local currency code

This commit is contained in:
Matthew Piatetsky
2019-06-03 17:06:23 -04:00
parent ad77392f8d
commit ce5b976f5e
8 changed files with 88 additions and 64 deletions

View File

@@ -422,9 +422,10 @@ class CourseModeViewTest(CatalogIntegrationMixin, UrlResetMixin, ModuleStoreTest
bannerText = u'''<div class="first-purchase-offer-banner"><span class="first-purchase-offer-banner-bold">
15% off your first upgrade.</span> Discount automatically applied.</div>'''
button = u'''<button type="submit" name="verified_mode">
Pursue a Verified Certificate ($8.50 USD
<del>$10 USD</del>)
</button>'''
<span>Pursue a Verified Certificate</span>
(<span class="upgrade-price-string">$8.50 USD</span>
<del> <span class="upgrade-price-string">$10 USD</span></del>)
</button>'''
self.assertContains(response, bannerText, html=True)
self.assertContains(response, button, html=True)

View File

@@ -0,0 +1,25 @@
<%page args="content_gating_enabled, course_duration_limit_enabled, min_price, price_before_discount" expression_filter="h"/>
<%!
from django.utils.translation import ugettext as _
from openedx.core.djangolib.markup import HTML, Text
%>
<%namespace name='static' file='../static_content.html'/>
<li class="action action-select">
<input type="hidden" name="contribution" value="${price_before_discount or min_price}" />
% if content_gating_enabled or course_duration_limit_enabled:
<button type="submit" name="verified_mode">
<span>${_('Pursue the Verified Track')}</span>
% else:
<button type="submit" name="verified_mode">
<span>${_('Pursue a Verified Certificate')}</span>
% endif
% if price_before_discount:
(<span class="upgrade-price-string">$${min_price} USD</span> <del> <span class="upgrade-price-string">${Text('${price} USD').format(price=price_before_discount)}</span></del>)
% else:
(<span class="upgrade-price-string">$${min_price} USD</span>)
% endif
</button>
</li>

View File

@@ -124,14 +124,7 @@ from openedx.core.djangolib.markup import HTML, Text
</div>
<div class="copy-inline list-actions">
<ul class="list-actions">
<li class="action action-select">
<input type="hidden" name="contribution" value="${price_before_discount or min_price}" />
<button type="submit" name="verified_mode">
${_('Pursue a Verified Certificate')} ($${min_price} USD${Text(' {open}${price} USD{close})').format(price=price_before_discount,
open=HTML('<del>'),
close=HTML('</del>')) if price_before_discount else ')'}
</button>
</li>
<%include file='_upgrade_button.html' args='content_gating_enabled=content_gating_enabled, course_duration_limit_enabled=course_duration_limit_enabled, min_price=min_price, price_before_discount=price_before_discount' />
</ul>
</div>
</div>
@@ -172,22 +165,7 @@ from openedx.core.djangolib.markup import HTML, Text
</div>
<div class="copy-inline list-actions">
<ul class="list-actions">
<li class="action action-select">
<input type="hidden" name="contribution" value="${price_before_discount or min_price}" />
% if content_gating_enabled or course_duration_limit_enabled:
<button type="submit" name="verified_mode">
${_('Pursue the Verified Track')} ($${min_price} USD${Text(' {open}${price} USD{close})').format(price=price_before_discount,
open=HTML('<del>'),
close=HTML('</del>')) if price_before_discount else ')'}
</button>
% else:
<button type="submit" name="verified_mode">
${_('Pursue a Verified Certificate')} ($${min_price} USD${Text(' {open}${price} USD{close})').format(price=price_before_discount,
open=HTML('<del>'),
close=HTML('</del>')) if price_before_discount else ')'}
</button>
% endif
</li>
<%include file='_upgrade_button.html' args='content_gating_enabled=content_gating_enabled, course_duration_limit_enabled=course_duration_limit_enabled, min_price=min_price, price_before_discount=price_before_discount' />
</ul>
</div>
</div>

View File

@@ -1,2 +1,3 @@
<div id="currency_data" value='{"CAN": {"rate": 2.2, "code": "CAD", "symbol": "$"}}'></div>
<input type="submit" name="verified_mode" value="Pursue a Verified Certificate ($100 USD)">
<button type="submit" class="no-discount" name="verified_mode"><span>Pursue a Verified Certificate</span>(<span class="upgrade-price-string">$100 USD</span>)</button>
<button type="submit" class="discount" name="verified_mode"><span>Pursue a Verified Certificate</span>(<span class="upgrade-price-string">$90 USD</span> <del><span class="upgrade-price-string">$100 USD</span></del>)</button>

View File

@@ -4,17 +4,28 @@ import $ from 'jquery'; // eslint-disable-line import/extensions
export class Currency { // eslint-disable-line import/prefer-default-export
setPrice() {
editText(price) {
const l10nCookie = this.countryL10nData;
const lmsregex = /(\$)(\d*)( USD)/g;
const price = $('input[name="verified_mode"]').filter(':visible')[0];
const regexMatch = lmsregex.exec(price.value);
const dollars = parseFloat(regexMatch[2]);
const converted = dollars * l10nCookie.rate;
const string = `${l10nCookie.symbol}${Math.round(converted)} ${l10nCookie.code}`;
// Use regex to change displayed price on track selection
// based on edx-price-l10n cookie currency_data
price.value = price.value.replace(regexMatch[0], string);
const lmsregex = /(\$)([\d|.]*)( USD)/g;
const priceText = price.text();
const regexMatch = lmsregex.exec(priceText);
if (regexMatch) {
const currentPrice = regexMatch[2];
const dollars = parseFloat(currentPrice);
const newPrice = dollars * l10nCookie.rate;
const newPriceString = `${l10nCookie.symbol}${Math.round(newPrice)} ${l10nCookie.code}`;
// Change displayed price based on edx-price-l10n cookie currency_data
price.text(newPriceString);
}
}
setPrice() {
$('.upgrade-price-string').each((i, price) => {
// When the button includes two prices (discounted and previous)
// we call the method twice, since it modifies one price at a time.
// Could also be used to modify all prices on any page
this.editText($(price));
});
}
getCountry() {

View File

@@ -36,12 +36,17 @@ describe('Currency factory', () => {
it('when location is the default (US)', () => {
$.cookie('edx-price-l10n', '{"rate":1,"code":"USD","symbol":"$","countryCode":"US"}', { path: '/' });
currency = new Currency();
expect($('input[name="verified_mode"]').filter(':visible')[0].value).toEqual('Pursue a Verified Certificate ($100 USD)');
expect($('[name="verified_mode"].no-discount').filter(':visible').text()).toEqual('Pursue a Verified Certificate($100 USD)');
});
it('when cookie is set to a different country', () => {
$.cookie('edx-price-l10n', '{"rate":2.2,"code":"CAD","symbol":"$","countryCode":"CAN"}', { expires: 1 });
currency = new Currency();
expect($('input[name="verified_mode"]').filter(':visible')[0].value).toEqual('Pursue a Verified Certificate ($220 CAD)');
expect($('[name="verified_mode"].no-discount').filter(':visible').text()).toEqual('Pursue a Verified Certificate($220 CAD)');
});
it('when cookie is set to a different country with a discount', () => {
$.cookie('edx-price-l10n', '{"rate":2.2,"code":"CAD","symbol":"$","countryCode":"CAN"}', { expires: 1 });
currency = new Currency();
expect($('[name="verified_mode"].discount').filter(':visible').text()).toEqual('Pursue a Verified Certificate($198 CAD $220 CAD)');
});
});
});

View File

@@ -0,0 +1,25 @@
<%page args="content_gating_enabled, course_duration_limit_enabled, min_price, price_before_discount" expression_filter="h"/>
<%!
from django.utils.translation import ugettext as _
from openedx.core.djangolib.markup import HTML, Text
%>
<%namespace name='static' file='../static_content.html'/>
<li class="action action-select">
<input type="hidden" name="contribution" value="${price_before_discount or min_price}" />
% if content_gating_enabled or course_duration_limit_enabled:
<button type="submit" name="verified_mode">
<span>${_('Pursue the Verified Track')}</span>
% else:
<button type="submit" name="verified_mode">
<span>${_('Pursue a Verified Certificate')}</span>
% endif
% if price_before_discount:
(<span class="upgrade-price-string">$${min_price} USD</span> <del> <span class="upgrade-price-string">${Text('${price} USD').format(price=price_before_discount)}</span></del>)
% else:
(<span class="upgrade-price-string">$${min_price} USD</span>)
% endif
</button>
</li>

View File

@@ -137,14 +137,7 @@ from openedx.core.djangolib.markup import HTML, Text
</div>
<div class="copy-inline list-actions">
<ul class="list-actions">
<li class="action action-select">
<input type="hidden" name="contribution" value="${price_before_discount or min_price}" />
<button type="submit" name="verified_mode">
${_('Pursue a Verified Certificate')} ($${min_price} USD${Text(' {open}${price} USD{close})').format(price=price_before_discount,
open=HTML('<del>'),
close=HTML('</del>')) if price_before_discount else ')'}
</button>
</li>
<%include file='_upgrade_button.html' args='content_gating_enabled=content_gating_enabled, course_duration_limit_enabled=course_duration_limit_enabled, min_price=min_price, price_before_discount=price_before_discount' />
</ul>
</div>
</div>
@@ -187,22 +180,7 @@ from openedx.core.djangolib.markup import HTML, Text
</div>
<div class="copy-inline list-actions">
<ul class="list-actions">
<li class="action action-select">
<input type="hidden" name="contribution" value="${price_before_discount or min_price}" />
% if content_gating_enabled or course_duration_limit_enabled:
<button type="submit" name="verified_mode">
${_('Pursue the Verified Track')} ($${min_price} USD${Text(' {open}${price} USD{close})').format(price=price_before_discount,
open=HTML('<del>'),
close=HTML('</del>')) if price_before_discount else ')'}
</button>
% else:
<button type="submit" name="verified_mode">
${_('Pursue a Verified Certificate')} ($${min_price} USD${Text(' {open}${price} USD{close})').format(price=price_before_discount,
open=HTML('<del>'),
close=HTML('</del>')) if price_before_discount else ')'}
</button>
% endif
</li>
<%include file='_upgrade_button.html' args='content_gating_enabled=content_gating_enabled, course_duration_limit_enabled=course_duration_limit_enabled, min_price=min_price, price_before_discount=price_before_discount' />
</ul>
</div>
</div>