Skip to content

Commit

Permalink
feat: ecommerce Basket Page -> micro-frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
UvgenGen committed May 4, 2022
1 parent 45ec01a commit ced48e8
Show file tree
Hide file tree
Showing 22 changed files with 19 additions and 1,666 deletions.
13 changes: 1 addition & 12 deletions ecommerce/core/management/commands/create_or_update_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,6 @@ def add_arguments(self, parser):
type=str,
required=True,
help='URL for Discovery service API calls.')
parser.add_argument('--enable-microfrontend-for-basket-page',
action='store',
dest='enable_microfrontend_for_basket_page',
type=bool,
required=False,
help='Use the microfrontend implementation of the '
'basket page instead of the server-side template')
parser.add_argument('--payment-microfrontend-url',
action='store',
dest='payment_microfrontend_url',
Expand Down Expand Up @@ -179,10 +172,7 @@ def handle(self, *args, **options): # pylint: disable=too-many-statements
base_cookie_domain = options.get('base_cookie_domain', '')
discovery_api_url = options.get('discovery_api_url')

enable_microfrontend_for_basket_page = bool(options.get('enable_microfrontend_for_basket_page', False))
payment_microfrontend_url = options.get(
'payment_microfrontend_url'
) if enable_microfrontend_for_basket_page else None
payment_microfrontend_url = options.get('payment_microfrontend_url')

try:
site = Site.objects.get(id=site_id)
Expand Down Expand Up @@ -240,7 +230,6 @@ def handle(self, *args, **options): # pylint: disable=too-many-statements
'oauth_settings': oauth_settings,
'base_cookie_domain': base_cookie_domain,
'discovery_api_url': discovery_api_url,
'enable_microfrontend_for_basket_page': enable_microfrontend_for_basket_page,
'payment_microfrontend_url': payment_microfrontend_url,
}
if payment_support_email:
Expand Down
7 changes: 1 addition & 6 deletions ecommerce/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,6 @@ class SiteConfiguration(models.Model):
max_length=255,
blank=True
)
enable_microfrontend_for_basket_page = models.BooleanField(
verbose_name=_('Enable Microfrontend for Basket Page'),
help_text=_('Use the microfrontend implementation of the basket page instead of the server-side template'),
blank=True,
default=False
)
payment_microfrontend_url = models.URLField(
verbose_name=_('Payment Microfrontend URL'),
help_text=_('URL for the Payment Microfrontend (used if Enable Microfrontend for Basket Page is set)'),
Expand Down Expand Up @@ -376,6 +370,7 @@ def enterprise_grant_data_sharing_url(self):

@property
def payment_domain_name(self):
# TODO: update it
if self.enable_microfrontend_for_basket_page:
return urlsplit(self.payment_microfrontend_url).netloc
return self.site.domain
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/coupons/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def test_inactive_user_email_domain_restricted_coupon_redemption(self):
self.assert_redirected_to_email_confirmation(response)

def get_coupon_redeem_success_expected_redirect_url(self):
return self.get_full_url(path=reverse('basket:summary')) + '?coupon_redeem_redirect=1'
return self.site_configuration.payment_microfrontend_url + '?coupon_redeem_redirect=1'


@ddt.ddt
Expand Down
4 changes: 2 additions & 2 deletions ecommerce/coupons/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
parse_consent_params
)
from ecommerce.extensions.api import exceptions
from ecommerce.extensions.basket.utils import get_payment_microfrontend_or_basket_url, prepare_basket
from ecommerce.extensions.basket.utils import get_payment_microfrontend, prepare_basket
from ecommerce.extensions.checkout.mixins import EdxOrderPlacementMixin
from ecommerce.extensions.checkout.utils import get_receipt_page_url
from ecommerce.extensions.offer.utils import get_redirect_to_email_confirmation_if_required
Expand Down Expand Up @@ -297,7 +297,7 @@ def get(self, request): # pylint: disable=too-many-statements
# The coupon_redeem_redirect query param is used to communicate to the Payment MFE that it may redirect
# and should not display the payment form before making that determination.
# TODO: It would be cleaner if the user could be redirected to their final destination up front.
redirect_url = get_payment_microfrontend_or_basket_url(self.request) + "?coupon_redeem_redirect=1"
redirect_url = get_payment_microfrontend(self.request) + "?coupon_redeem_redirect=1"
return HttpResponseRedirect(redirect_url)


Expand Down
20 changes: 0 additions & 20 deletions ecommerce/extensions/basket/apps.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@


from django.conf.urls import url
from django.contrib.auth.decorators import login_required
from oscar.apps.basket import apps
from oscar.core.loading import get_class


class BasketConfig(apps.BasketConfig):
name = 'ecommerce.extensions.basket'

# pylint: disable=attribute-defined-outside-init
def ready(self):
super().ready()
self.basket_add_items_view = get_class('basket.views', 'BasketAddItemsView')
self.summary_view = get_class('basket.views', 'BasketSummaryView')

def get_urls(self):
urls = [
url(r'^$', login_required(self.summary_view.as_view()), name='summary'),
url(r'^add/(?P<pk>\d+)/$', self.add_view.as_view(), name='add'),
url(r'^vouchers/add/$', self.add_voucher_view.as_view(), name='vouchers-add'),
url(r'^vouchers/(?P<pk>\d+)/remove/$', self.remove_voucher_view.as_view(), name='vouchers-remove'),
url(r'^saved/$', login_required(self.saved_view.as_view()), name='saved'),
url(r'^add/$', self.basket_add_items_view.as_view(), name='basket-add'),
]
return self.post_process_urls(urls)
22 changes: 0 additions & 22 deletions ecommerce/extensions/basket/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
apply_voucher_on_basket_and_check_discount,
attribute_cookie_data,
get_basket_switch_data,
get_payment_microfrontend_url_if_configured,
is_duplicate_seat_attempt,
prepare_basket
)
Expand All @@ -35,7 +34,6 @@
from ecommerce.extensions.order.exceptions import AlreadyPlacedOrderException
from ecommerce.extensions.order.utils import UserAlreadyPlacedOrder
from ecommerce.extensions.partner.models import StockRecord
from ecommerce.extensions.payment.constants import DISABLE_MICROFRONTEND_FOR_BASKET_PAGE_FLAG_NAME
from ecommerce.extensions.test.factories import create_order, prepare_voucher
from ecommerce.referrals.models import Referral
from ecommerce.tests.testcases import TestCase, TransactionTestCase
Expand Down Expand Up @@ -688,26 +686,6 @@ def test_apply_voucher_on_basket_and_check_discount_with_multiple_vouchers(self)
self.assertEqual(applied, False)
self.assertEqual(msg, 'Basket does not qualify for coupon code {code}.'.format(code=invalid_voucher.code))

@ddt.data(
(True, '/payment', False, '/payment'), # Microfrontend not disabled
(True, '/payment', True, None), # Microfrontend disabled
)
@ddt.unpack
def test_disable_microfrontend_for_basket_page_flag(
self,
microfrontend_enabled,
payment_microfrontend_url,
disable_microfrontend_flag_active,
expected_result
):
"""
Verify that the `disable_microfrontend_for_basket_page_flag` correctly disables the microfrontend url retrieval
"""
with override_flag(DISABLE_MICROFRONTEND_FOR_BASKET_PAGE_FLAG_NAME, active=disable_microfrontend_flag_active):
self.site_configuration.enable_microfrontend_for_basket_page = microfrontend_enabled
self.site_configuration.payment_microfrontend_url = payment_microfrontend_url
self.assertEqual(get_payment_microfrontend_url_if_configured(self.request), expected_result)

def test_prepare_basket_with_duplicate_seat(self):
""" Verify a basket fixes the case where flush doesn't work and we attempt adding duplicate seat. """
with mock.patch('ecommerce.extensions.basket.utils.Basket.flush'):
Expand Down
Loading

0 comments on commit ced48e8

Please sign in to comment.