Skip to content

Commit

Permalink
Fix total price (#557)
Browse files Browse the repository at this point in the history
* Fix program banner video
  • Loading branch information
maximst authored and Kyrylo Omelchenko committed Dec 5, 2019
1 parent 6d5df44 commit b62207e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 36 deletions.
1 change: 1 addition & 0 deletions lms/djangoapps/commerce/api/v0/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def post(self, request, *args, **kwargs):
"""
Attempt to enroll the user.
"""
return DetailResponse('Method not allowed', status=HTTP_406_NOT_ACCEPTABLE)
user = request.user
valid, course_key, error = self._is_data_valid(request)
if not valid:
Expand Down
16 changes: 8 additions & 8 deletions lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
from openedx.core.djangoapps.models.course_details import CourseDetails
from openedx.core.djangoapps.monitoring_utils import set_custom_metrics_for_course_key
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
from openedx.core.djangoapps.programs.utils import ProgramMarketingDataExtender, ProgramProgressMeter
from openedx.core.djangoapps.programs.utils import ProgramMarketingDataExtender
from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.util.user_messages import PageLevelMessages
Expand All @@ -103,7 +103,7 @@
from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem
from xmodule.tabs import CourseTabList
from xmodule.x_module import STUDENT_VIEW
from learner_dashboard.programs import courses_count
from learner_dashboard.programs import get_course_ids

from ..entrance_exams import user_can_skip_entrance_exam
from ..module_render import get_module, get_module_by_usage_id, get_module_for_descriptor
Expand Down Expand Up @@ -899,19 +899,19 @@ def program_marketing(request, program_uuid):
if not program_data:
raise Http404

meter = ProgramProgressMeter(request.site, request.user, uuid=program_uuid)
course_data = meter.progress(programs=[program_data], count_only=False)[0]
total_courses_count = courses_count(program_data['courses'])
not_started_courses_count = courses_count(course_data['not_started'])
course_ids = get_course_ids(program_data['courses'])
total_courses_count = len(course_ids)

started_courses_count = CourseEnrollment.enrollments_for_user(request.user).filter(course_id__in=course_ids).count()

program = ProgramMarketingDataExtender(program_data, request.user).extend()
program['type_slug'] = slugify(program['type'])
skus = program.get('skus')
ecommerce_service = EcommerceService()

price = program.get('price', '0.00')
if price != '0.00' and not_started_courses_count < total_courses_count:
program['full_program_price'] = (float(price) / total_courses_count) * not_started_courses_count
if price != '0.00' and started_courses_count:
program['full_program_price'] = (float(price) / total_courses_count) * (total_courses_count - started_courses_count)
elif price != '0.00':
program['full_program_price'] = float(price)

Expand Down
22 changes: 14 additions & 8 deletions lms/djangoapps/learner_dashboard/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
get_program_marketing_url
)
from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences
from opaque_keys.edx.keys import CourseKey
from student.models import CourseEnrollment


def courses_count(courses):
courses_count = 0
def get_course_ids(courses):
course_ids = []
for course in courses:
courses_count += len(set(c['key'] for c in course['course_runs']))
return courses_count
course_ids.extend([CourseKey.from_string(c['key']) for c in course['course_runs']])
return course_ids


class ProgramsFragmentView(EdxFragmentView):
Expand Down Expand Up @@ -109,13 +111,17 @@ def render_to_fragment(self, request, program_uuid, **kwargs):
course_data = meter.progress(programs=[program_data], count_only=False)[0]
certificate_data = get_certificates(request.user, program_data)

total_courses_count = courses_count(program_data.pop('courses'))
course_ids = get_course_ids(program_data.pop('courses'))
total_courses_count = len(course_ids)

not_started_courses_count = courses_count(course_data['not_started'])
started_courses_count = CourseEnrollment.enrollments_for_user(request.user).filter(
course_id__in=course_ids
).count()

if not_started_courses_count < total_courses_count:
if started_courses_count:
program_data['price'] = '%.2f' % (
(float(program_data['price']) / total_courses_count) * not_started_courses_count)
(float(program_data['price']) / total_courses_count * (total_courses_count - started_courses_count))
)

skus = program_data.get('skus')
ecommerce_service = EcommerceService()
Expand Down
8 changes: 6 additions & 2 deletions lms/djangoapps/shoppingcart/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def add_program_to_cart(request, uuid):
if not programs_config.enabled:
raise JsonResponse({'success': False, 'msg': _('The program config you requested does not exist.')})

meter = ProgramProgressMeter(request.user, uuid=uuid)
meter = ProgramProgressMeter(request.site, request.user, uuid=uuid)
program_data = meter.programs[0]

if not program_data:
Expand Down Expand Up @@ -178,7 +178,11 @@ def add_program_to_cart(request, uuid):
paid_course_item.currency = program_data['currency']
paid_course_item.save()

return JsonResponse({'success': True, 'msg': 'Program added to cart.', 'redirect_url': reverse('show_cart')})
return JsonResponse({
'success': True,
'msg': 'Program added to cart.',
'redirect_url': reverse('shoppingcart.views.show_cart')
})


@login_required
Expand Down
17 changes: 10 additions & 7 deletions lms/templates/courseware/program_marketing.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
full_program_price_format = '{0:.0f}' if program['full_program_price'].is_integer() else '{0:.2f}'
full_program_price = full_program_price_format.format(program['full_program_price'])
%>
<h1>${video_url}</h1>
<div id="program-details-hero">
<div class="main-banner"
style="background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5) ), url(${banner_image});">
Expand Down Expand Up @@ -160,6 +161,15 @@ <h2>${program['subtitle']}</h2>
</div>
</div>
</div>
% if video_url:
<section id="video-modal" class="modal modal-custom custom-video-modal">
<div class="inner-wrapper">
<iframe title="${_('YouTube Video')}" width="640" height="360"
src="${video_url}"
frameborder="0" allowfullscreen></iframe>
</div>
</section>
% endif
</%block>

<div id="program-details-page" class="container">
Expand Down Expand Up @@ -475,13 +485,6 @@ <h4 class="hd title">
<span class="pagingInfo"></span>
</div>

<section id="video-modal" class="modal modal-custom custom-video-modal">
<div class="inner-wrapper">
<iframe title="${_('YouTube Video')}" width="640" height="360"
src="${video_url}"
frameborder="0" allowfullscreen></iframe>
</div>
</section>
</div>
<div id="shoppingcart-popup">
<p id='msg'></p>
Expand Down
11 changes: 0 additions & 11 deletions lms/templates/learner_dashboard/course_enroll.underscore
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,6 @@
</select>
</div>
<% } %>
<div class="enroll-button">
<% if (typeof is_mobile_only != 'undefined' && is_mobile_only === true) { %>
<a href="edxapp://enroll?course_id=<%- course_run_key %>&email_opt_in=true" class="enroll-course-button btn-brand btn cta-primary">
<%- gettext('Enroll Now') %>
</a>
<% } else { %>
<button type="button" class="btn-brand btn cta-primary">
<%- gettext('Enroll Now') %>
</button>
<% } %>
</div>
<% } else if (upcoming_course_runs.length > 0) {%>
<div class="no-action-message">
<%- gettext('Coming Soon') %>
Expand Down

0 comments on commit b62207e

Please sign in to comment.