From b53a12bf02e02f7b34c42bacfa048fda40f4bc35 Mon Sep 17 00:00:00 2001 From: "E. Kolpakov" Date: Mon, 28 Mar 2016 14:04:41 +0300 Subject: [PATCH 1/2] Enabling Otto checkout for themed/microsite sites --- lms/djangoapps/commerce/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lms/djangoapps/commerce/utils.py b/lms/djangoapps/commerce/utils.py index a4e775c395c7..7520f6411ea5 100644 --- a/lms/djangoapps/commerce/utils.py +++ b/lms/djangoapps/commerce/utils.py @@ -46,8 +46,7 @@ def __init__(self): def is_enabled(self, user): """ Check if the user is activated, if the service is enabled and that the site is not a microsite. """ - return (user.is_active and self.config.checkout_on_ecommerce_service and not - helpers.is_request_in_themed_site()) + return user.is_active and self.config.checkout_on_ecommerce_service def payment_page_url(self): """ Return the URL for the checkout page. From 150ced39eb7a872cbba03baac64a09fb95deb806 Mon Sep 17 00:00:00 2001 From: "E. Kolpakov" Date: Mon, 28 Mar 2016 14:05:10 +0300 Subject: [PATCH 2/2] Fixing ecommerce_api+client to use themed/microsite config --- lms/djangoapps/commerce/tests/test_utils.py | 8 +++++++- openedx/core/djangoapps/commerce/utils.py | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/commerce/tests/test_utils.py b/lms/djangoapps/commerce/tests/test_utils.py index ae979a39027c..6e098dbda1b8 100644 --- a/lms/djangoapps/commerce/tests/test_utils.py +++ b/lms/djangoapps/commerce/tests/test_utils.py @@ -54,8 +54,14 @@ def test_is_enabled(self): @patch('openedx.core.djangoapps.theming.helpers.is_request_in_themed_site') def test_is_enabled_for_microsites(self, is_microsite): - """Verify that is_enabled() returns False if used for a microsite.""" + """Verify that is_enabled() returns True when ecomm checkout is enabled for microsite """ is_microsite.return_value = True + is_enabled = EcommerceService().is_enabled(self.user) + self.assertTrue(is_enabled) + + config = CommerceConfiguration.current() + config.checkout_on_ecommerce_service = False + config.save() is_not_enabled = EcommerceService().is_enabled(self.user) self.assertFalse(is_not_enabled) diff --git a/openedx/core/djangoapps/commerce/utils.py b/openedx/core/djangoapps/commerce/utils.py index 676793a5e1b7..ef39cd72a3c8 100644 --- a/openedx/core/djangoapps/commerce/utils.py +++ b/openedx/core/djangoapps/commerce/utils.py @@ -3,6 +3,8 @@ from edx_rest_api_client.client import EdxRestApiClient from eventtracking import tracker +from openedx.core.djangoapps.theming.helpers import get_value + ECOMMERCE_DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ" @@ -23,14 +25,17 @@ def is_commerce_service_configured(): Return a Boolean indicating whether or not configuration is present to use the external commerce service. """ - return bool(settings.ECOMMERCE_API_URL and settings.ECOMMERCE_API_SIGNING_KEY) + return bool( + get_value('ECOMMERCE_API_URL', settings.ECOMMERCE_API_URL) and + get_value('ECOMMERCE_API_SIGNING_KEY', settings.ECOMMERCE_API_SIGNING_KEY) + ) def ecommerce_api_client(user): """ Returns an E-Commerce API client setup with authentication for the specified user. """ return EdxRestApiClient( - settings.ECOMMERCE_API_URL, - settings.ECOMMERCE_API_SIGNING_KEY, + get_value('ECOMMERCE_API_URL', settings.ECOMMERCE_API_URL), + get_value('ECOMMERCE_API_SIGNING_KEY', settings.ECOMMERCE_API_SIGNING_KEY), user.username, user.profile.name if hasattr(user, 'profile') else None, user.email,