Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
ecommerce
Commits
2e666819
Commit
2e666819
authored
Jun 08, 2016
by
Matt Drayer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mattdrayer/WL-511: Repair invalid SKU publishing/selection workflows
parent
f5508179
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
12 deletions
+45
-12
ecommerce/courses/publishers.py
+8
-5
ecommerce/extensions/basket/tests/test_views.py
+15
-0
ecommerce/extensions/basket/utils.py
+22
-7
No files found.
ecommerce/courses/publishers.py
View file @
2e666819
...
...
@@ -9,6 +9,7 @@ from edx_rest_api_client.exceptions import SlumberHttpBaseException
from
oscar.core.loading
import
get_model
import
requests
from
ecommerce.core.constants
import
ENROLLMENT_CODE_SEAT_TYPES
from
ecommerce.core.url_utils
import
get_lms_url
,
get_lms_commerce_api_url
from
ecommerce.courses.utils
import
mode_for_seat
...
...
@@ -32,11 +33,13 @@ class LMSPublisher(object):
def
serialize_seat_for_commerce_api
(
self
,
seat
):
""" Serializes a course seat product to a dict that can be further serialized to JSON. """
stock_record
=
seat
.
stockrecords
.
first
()
try
:
enrollment_code
=
seat
.
course
.
enrollment_code_product
bulk_sku
=
enrollment_code
.
stockrecords
.
first
()
.
partner_sku
except
Product
.
DoesNotExist
:
bulk_sku
=
None
bulk_sku
=
None
if
seat
.
attr
.
certificate_type
in
ENROLLMENT_CODE_SEAT_TYPES
:
try
:
enrollment_code
=
seat
.
course
.
enrollment_code_product
bulk_sku
=
enrollment_code
.
stockrecords
.
first
()
.
partner_sku
except
Product
.
DoesNotExist
:
pass
return
{
'name'
:
mode_for_seat
(
seat
),
'currency'
:
stock_record
.
price_currency
,
...
...
ecommerce/extensions/basket/tests/test_views.py
View file @
2e666819
...
...
@@ -23,6 +23,7 @@ from ecommerce.core.url_utils import get_lms_enrollment_api_url
from
ecommerce.core.url_utils
import
get_lms_url
from
ecommerce.coupons.tests.mixins
import
CouponMixin
from
ecommerce.courses.tests.factories
import
CourseFactory
from
ecommerce.extensions.basket.utils
import
get_basket_switch_data
from
ecommerce.extensions.catalogue.tests.mixins
import
CourseCatalogTestMixin
from
ecommerce.extensions.offer.utils
import
format_benefit_value
from
ecommerce.extensions.payment.tests.processors
import
DummyProcessor
...
...
@@ -291,6 +292,20 @@ class BasketSummaryViewTests(CourseCatalogTestMixin, LmsApiMockMixin, ApiMockMix
line_data
=
response
.
context
[
'formset_lines_data'
][
0
][
1
]
self
.
assertEqual
(
line_data
[
'seat_type'
],
_
(
enrollment_code
.
attr
.
seat_type
.
capitalize
()))
def
test_basket_switch_data
(
self
):
"""Verify the correct basket switch data (single vs. multi quantity) is retrieved."""
course
=
CourseFactory
()
toggle_switch
(
ENROLLMENT_CODE_SWITCH
,
True
)
course
.
create_or_update_seat
(
'invalid'
,
False
,
10
,
self
.
partner
)
seat
=
course
.
create_or_update_seat
(
'verified'
,
False
,
10
,
self
.
partner
)
seat_sku
=
StockRecord
.
objects
.
get
(
product
=
seat
)
.
partner_sku
enrollment_code
=
Product
.
objects
.
get
(
product_class__name
=
ENROLLMENT_CODE_PRODUCT_CLASS_NAME
)
ec_sku
=
StockRecord
.
objects
.
get
(
product
=
enrollment_code
)
.
partner_sku
__
,
partner_sku
=
get_basket_switch_data
(
seat
)
self
.
assertEqual
(
partner_sku
,
ec_sku
)
__
,
partner_sku
=
get_basket_switch_data
(
enrollment_code
)
self
.
assertEqual
(
partner_sku
,
seat_sku
)
@ddt.data
(
(
Benefit
.
PERCENTAGE
,
100
),
(
Benefit
.
PERCENTAGE
,
50
),
...
...
ecommerce/extensions/basket/utils.py
View file @
2e666819
...
...
@@ -77,11 +77,26 @@ def get_basket_switch_data(product):
switch_link_text
=
_
(
'Click here to purchase multiple seats in this course'
)
structure
=
'standalone'
try
:
partner_sku
=
StockRecord
.
objects
.
get
(
product__course_id
=
product
.
course_id
,
product__structure
=
structure
)
.
partner_sku
except
StockRecord
.
DoesNotExist
:
partner_sku
=
None
stock_records
=
StockRecord
.
objects
.
filter
(
product__course_id
=
product
.
course_id
,
product__structure
=
structure
)
# Determine the proper partner SKU to embed in the single/multiple basket switch link
# The logic here is a little confusing. "Seat" products have "certificate_type" attributes, and
# "Enrollment Code" products have "seat_type" attributes. If the basket is in single-purchase
# mode, we are working with a Seat product and must present the 'buy multiple' switch link and
# SKU from the corresponding Enrollment Code product. If the basket is in multi-purchase mode,
# we are working with an Enrollment Code product and must present the 'buy single' switch link
# and SKU from the corresponding Seat product.
partner_sku
=
None
product_cert_type
=
getattr
(
product
.
attr
,
'certificate_type'
,
None
)
product_seat_type
=
getattr
(
product
.
attr
,
'seat_type'
,
None
)
for
stock_record
in
stock_records
:
stock_record_cert_type
=
getattr
(
stock_record
.
product
.
attr
,
'certificate_type'
,
None
)
stock_record_seat_type
=
getattr
(
stock_record
.
product
.
attr
,
'seat_type'
,
None
)
if
(
product_seat_type
and
product_seat_type
==
stock_record_cert_type
)
or
\
(
product_cert_type
and
product_cert_type
==
stock_record_seat_type
):
partner_sku
=
stock_record
.
partner_sku
break
return
switch_link_text
,
partner_sku
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment