From 80d151b404c3ce3788261e4460ecb02ed6bd0f80 Mon Sep 17 00:00:00 2001 From: Nawfal Ahmed <111358247+NawfalAhmed@users.noreply.github.com> Date: Fri, 23 Jun 2023 17:54:15 +0500 Subject: [PATCH] feat: add marketing url to subscription upsell (#32560) --- lms/djangoapps/learner_dashboard/programs.py | 13 ++++++++++++- lms/envs/devstack.py | 1 + .../js/learner_dashboard/spec/sidebar_view_spec.js | 5 +++-- .../views/subscription_upsell_view.js | 6 +++--- .../learner_dashboard/programs_fragment.html | 1 + .../subscription_upsell_view.underscore | 2 +- openedx/core/djangoapps/programs/utils.py | 9 +++++++++ 7 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/learner_dashboard/programs.py b/lms/djangoapps/learner_dashboard/programs.py index de74b25305..5db6bc9688 100644 --- a/lms/djangoapps/learner_dashboard/programs.py +++ b/lms/djangoapps/learner_dashboard/programs.py @@ -31,6 +31,7 @@ from openedx.core.djangoapps.programs.utils import ( get_industry_and_credit_pathways, get_program_and_course_data, get_program_marketing_url, + get_program_subscriptions_marketing_url, get_program_urls, get_programs_subscription_data ) @@ -59,10 +60,20 @@ class ProgramsFragmentView(EdxFragmentView): meter = ProgramProgressMeter(request.site, user, mobile_only=mobile_only) is_user_b2c_subscriptions_enabled = b2c_subscriptions_enabled(mobile_only) - programs_subscription_data = get_programs_subscription_data(user) if is_user_b2c_subscriptions_enabled else [] + programs_subscription_data = ( + get_programs_subscription_data(user) + if is_user_b2c_subscriptions_enabled + else [] + ) + subscriptions_marketing_url = ( + get_program_subscriptions_marketing_url() + if is_user_b2c_subscriptions_enabled + else '' + ) context = { 'marketing_url': get_program_marketing_url(programs_config, mobile_only), + 'subscriptions_marketing_url': subscriptions_marketing_url, 'programs': meter.engaged_programs, 'progress': meter.progress(), 'programs_subscription_data': programs_subscription_data, diff --git a/lms/envs/devstack.py b/lms/envs/devstack.py index 88aba2fd9a..f6c812ad3b 100644 --- a/lms/envs/devstack.py +++ b/lms/envs/devstack.py @@ -431,6 +431,7 @@ MKTG_URLS = { 'TOS': '/edx-terms-service', 'TOS_AND_HONOR': '/edx-terms-service', 'WHAT_IS_VERIFIED_CERT': '/verified-certificate', + 'PROGRAM_SUBSCRIPTIONS': '/program-subscriptions', } ENTERPRISE_MARKETING_FOOTER_QUERY_PARAMS = {} diff --git a/lms/static/js/learner_dashboard/spec/sidebar_view_spec.js b/lms/static/js/learner_dashboard/spec/sidebar_view_spec.js index 8812221cc6..c3714b2f7a 100644 --- a/lms/static/js/learner_dashboard/spec/sidebar_view_spec.js +++ b/lms/static/js/learner_dashboard/spec/sidebar_view_spec.js @@ -6,6 +6,7 @@ describe('Sidebar View', () => { let view = null; const context = { marketingUrl: 'https://www.example.org/programs', + subscriptionsMarketingUrl: 'https://www.example.org/program-subscriptions', isUserB2CSubscriptionsEnabled: true, }; @@ -53,8 +54,7 @@ describe('Sidebar View', () => { expect(view.$('.js-subscription-upsell a span:last').html().trim()) .toEqual('Explore subscription options'); expect(view.$('.js-subscription-upsell a').attr('href')) - .not - .toEqual(context.marketingUrl); + .toEqual('https://www.example.org/program-subscriptions'); }); it('should load the exploration panel given a marketing URL', () => { @@ -72,6 +72,7 @@ describe('Sidebar View', () => { el: '.sidebar', context: { isUserB2CSubscriptionsEnabled: true, + subscriptionsMarketingUrl: '', }, }); view.render(); diff --git a/lms/static/js/learner_dashboard/views/subscription_upsell_view.js b/lms/static/js/learner_dashboard/views/subscription_upsell_view.js index d629792aa0..06235c2a47 100644 --- a/lms/static/js/learner_dashboard/views/subscription_upsell_view.js +++ b/lms/static/js/learner_dashboard/views/subscription_upsell_view.js @@ -12,14 +12,14 @@ class SubscriptionUpsellView extends Backbone.View { super(Object.assign({}, defaults, options)); } - initialize(options) { + initialize({ context }) { this.tpl = HtmlUtils.template(subscriptionUpsellTpl); - this.data = options.context; + this.context = context; this.render(); } render() { - const data = $.extend(this.context, { + const data = $.extend({}, this.context, { minSubscriptionPrice: '$39', trialLength: 7, }); diff --git a/lms/templates/learner_dashboard/programs_fragment.html b/lms/templates/learner_dashboard/programs_fragment.html index 329217bf4e..74aa49054f 100644 --- a/lms/templates/learner_dashboard/programs_fragment.html +++ b/lms/templates/learner_dashboard/programs_fragment.html @@ -21,6 +21,7 @@ from openedx.core.djangolib.js_utils import ( <%static:webpack entry="ProgramListFactory"> ProgramListFactory({ marketingUrl: '${marketing_url | n, js_escaped_string}', + subscriptionsMarketingUrl: '${subscriptions_marketing_url | n, js_escaped_string}', programsData: ${programs | n, dump_js_escaped_json}, programsSubscriptionData: ${programs_subscription_data | n, dump_js_escaped_json}, userProgress: ${progress | n, dump_js_escaped_json}, diff --git a/lms/templates/learner_dashboard/subscription_upsell_view.underscore b/lms/templates/learner_dashboard/subscription_upsell_view.underscore index d3bc274284..ef765da17b 100644 --- a/lms/templates/learner_dashboard/subscription_upsell_view.underscore +++ b/lms/templates/learner_dashboard/subscription_upsell_view.underscore @@ -11,7 +11,7 @@ { minSubscriptionPrice, trialLength } ) %>
- + <%- gettext('Explore subscription options') %> diff --git a/openedx/core/djangoapps/programs/utils.py b/openedx/core/djangoapps/programs/utils.py index 8a9b861f49..c9858a7bd2 100644 --- a/openedx/core/djangoapps/programs/utils.py +++ b/openedx/core/djangoapps/programs/utils.py @@ -131,6 +131,15 @@ def get_program_marketing_url(programs_config, mobile_only=False): return marketing_url +def get_program_subscriptions_marketing_url(): + """Build a URL used to link to subscription eligible programs on the marketing site.""" + marketing_urls = settings.MKTG_URLS + return urljoin( + marketing_urls.get('ROOT'), + marketing_urls.get('PROGRAM_SUBSCRIPTIONS'), + ) + + def attach_program_detail_url(programs, mobile_only=False): """Extend program representations by attaching a URL to be used when linking to program details.