Add strike-out price in LMS courseware
This commit is contained in:
@@ -17,9 +17,11 @@ from web_fragments.fragment import Fragment
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
from lms.djangoapps.commerce.utils import EcommerceService
|
||||
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
|
||||
from openedx.core.lib.mobile_utils import is_request_from_mobile_app
|
||||
from openedx.features.content_type_gating.helpers import CONTENT_GATING_PARTITION_ID, FULL_ACCESS, LIMITED_ACCESS
|
||||
from openedx.features.content_type_gating.models import ContentTypeGatingConfig
|
||||
from openedx.features.discounts.applicability import discount_percentage, can_receive_discount
|
||||
from xmodule.partitions.partitions import UserPartition, UserPartitionError
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@@ -76,7 +78,8 @@ class ContentTypeGatingPartition(UserPartition):
|
||||
"""
|
||||
def access_denied_fragment(self, block, user, user_group, allowed_groups):
|
||||
course_key = self._get_course_key_from_course_block(block)
|
||||
modes = CourseMode.modes_for_course_dict(course_key)
|
||||
course = CourseOverview.get_from_id(course_key)
|
||||
modes = CourseMode.modes_for_course_dict(course=course)
|
||||
verified_mode = modes.get(CourseMode.VERIFIED)
|
||||
if (verified_mode is None or user_group == FULL_ACCESS or
|
||||
user_group in allowed_groups):
|
||||
@@ -84,10 +87,19 @@ class ContentTypeGatingPartition(UserPartition):
|
||||
|
||||
ecommerce_checkout_link = self._get_checkout_link(user, verified_mode.sku)
|
||||
request = crum.get_current_request()
|
||||
|
||||
if can_receive_discount(user, course):
|
||||
price_before_discount = verified_mode.min_price
|
||||
upgrade_price = "{:0.2f}".format(price_before_discount * ((100.0 - discount_percentage()) / 100))
|
||||
else:
|
||||
price_before_discount = None
|
||||
upgrade_price = verified_mode.min_price
|
||||
|
||||
frag = Fragment(render_to_string('content_type_gating/access_denied_message.html', {
|
||||
'mobile_app': request and is_request_from_mobile_app(request),
|
||||
'ecommerce_checkout_link': ecommerce_checkout_link,
|
||||
'min_price': str(verified_mode.min_price)
|
||||
'min_price': upgrade_price,
|
||||
'price_before_discount': price_before_discount,
|
||||
}))
|
||||
return frag
|
||||
|
||||
|
||||
@@ -12,7 +12,12 @@
|
||||
{% if not mobile_app and ecommerce_checkout_link %}
|
||||
<span class="certDIV_1" style="">
|
||||
<a href="{{ecommerce_checkout_link}}" class="certA_1">
|
||||
{% trans "Upgrade to unlock" %} (${{min_price}} USD)
|
||||
{% trans "Upgrade to unlock" %}
|
||||
{% if price_before_discount %}
|
||||
(${{min_price}} USD <del>${{price_before_discount}} USD</del>)
|
||||
{% else %}
|
||||
(${{min_price}} USD)
|
||||
{% endif %}
|
||||
</a>
|
||||
</span>
|
||||
{% endif %}
|
||||
|
||||
@@ -20,6 +20,7 @@ from pyquery import PyQuery as pq
|
||||
|
||||
from six.moves.html_parser import HTMLParser
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
from course_api.blocks.api import get_blocks
|
||||
from course_modes.tests.factories import CourseModeFactory
|
||||
from experiments.models import ExperimentData, ExperimentKeyValue
|
||||
@@ -43,6 +44,7 @@ from openedx.core.djangoapps.django_comment_common.models import (
|
||||
from openedx.core.djangoapps.user_api.tests.factories import UserCourseTagFactory
|
||||
from openedx.core.djangoapps.util.testing import TestConditionalContent
|
||||
from openedx.core.lib.url_utils import quote_slashes
|
||||
from openedx.features.discounts.applicability import DISCOUNT_APPLICABILITY_FLAG
|
||||
from openedx.features.content_type_gating.helpers import CONTENT_GATING_PARTITION_ID, CONTENT_TYPE_GATE_GROUP_IDS
|
||||
from openedx.features.content_type_gating.models import ContentTypeGatingConfig
|
||||
from openedx.features.content_type_gating.partitions import ContentTypeGatingPartition
|
||||
@@ -780,6 +782,33 @@ class TestProblemTypeAccess(SharedModuleStoreTestCase):
|
||||
request_factory=self.factory,
|
||||
)
|
||||
|
||||
@ddt.data(True, False)
|
||||
def test_discount_display(self, has_discount):
|
||||
verified_mode = CourseMode.objects.get(course_id=self.course.id, mode_slug=CourseMode.VERIFIED)
|
||||
verified_mode.min_price = 100
|
||||
verified_mode.save()
|
||||
|
||||
with DISCOUNT_APPLICABILITY_FLAG.override(has_discount):
|
||||
with patch.object(ContentTypeGatingPartition, '_get_checkout_link', return_value='#'):
|
||||
block_content = _get_content_from_lms_index(
|
||||
block=self.blocks_dict['problem'],
|
||||
user_id=self.audit_user.id,
|
||||
course=self.course,
|
||||
request_factory=self.factory,
|
||||
)
|
||||
|
||||
assert 'content-paywall' in block_content
|
||||
assert 'certA_1' in block_content
|
||||
|
||||
if has_discount:
|
||||
assert '<del>$100</del>' in block_content
|
||||
assert '$85' in block_content
|
||||
else:
|
||||
assert '<del>' not in block_content
|
||||
assert '$85' not in block_content
|
||||
assert '$100' in block_content
|
||||
|
||||
|
||||
|
||||
@override_settings(FIELD_OVERRIDE_PROVIDERS=(
|
||||
'openedx.features.content_type_gating.field_override.ContentTypeGatingFieldOverride',
|
||||
|
||||
Reference in New Issue
Block a user