Skip to content

Commit befce34

Browse files
authored
fix: Use SENTINEL as default value for cart_update (#168)
Otherwise discount will be removed
1 parent 91dd369 commit befce34

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/viur/shop/modules/api.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ def cart_add(
155155
self,
156156
*,
157157
parent_cart_key: str | db.Key = None,
158-
cart_type: CartType = None,
159-
name: str = None,
160-
customer_comment: str = None,
161-
shipping_address_key: str | db.Key = None,
162-
shipping_key: str | db.Key = None,
163-
discount_key: str | db.Key = None,
158+
cart_type: CartType = SENTINEL,
159+
name: str = SENTINEL,
160+
customer_comment: str = SENTINEL,
161+
shipping_address_key: str | db.Key = SENTINEL,
162+
shipping_key: str | db.Key = SENTINEL,
163+
discount_key: str | db.Key = SENTINEL,
164164
**kwargs,
165165
):
166166
"""
@@ -206,12 +206,12 @@ def cart_update(
206206
self,
207207
*,
208208
cart_key: str | db.Key,
209-
cart_type: CartType = None, # TODO: necessary?
209+
cart_type: CartType = SENTINEL, # TODO: necessary?
210210
name: str = None,
211-
customer_comment: str = None,
212-
shipping_address_key: str | db.Key = None,
211+
customer_comment: str = SENTINEL,
212+
shipping_address_key: str | db.Key = SENTINEL,
213213
shipping_key: str | db.Key = SENTINEL,
214-
discount_key: str | db.Key = None, # TODO: use sentinel?
214+
discount_key: str | db.Key = SENTINEL,
215215
**kwargs,
216216
):
217217
"""

src/viur/shop/modules/cart.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from ..services import EVENT_SERVICE, Event
1616
from ..skeletons.article import ArticleAbstractSkel
1717
from ..skeletons.cart import CartItemSkel, CartNodeSkel
18+
from ..types.response import make_json_dumpable
1819

1920
logger = SHOP_LOGGER.getChild(__name__)
2021

@@ -438,7 +439,7 @@ def cart_update(
438439
) -> SkeletonInstance_T[CartNodeSkel] | None:
439440
if not isinstance(cart_key, db.Key):
440441
raise TypeError(f"cart_key must be an instance of db.Key")
441-
if not isinstance(cart_type, (CartType, type(None))):
442+
if cart_type is not SENTINEL and not isinstance(cart_type, (CartType, type(None))):
442443
raise TypeError(f"cart_type must be an instance of CartType")
443444
if parent_cart_key is not SENTINEL and not isinstance(parent_cart_key, (db.Key, type(None))):
444445
raise TypeError(f"parent_cart_key must be an instance of db.Key")
@@ -654,6 +655,7 @@ def freeze_cart(
654655
"vat": cart_skel["vat"],
655656
"total_quantity": cart_skel["total_quantity"],
656657
"shipping": cart_skel["shipping"],
658+
"discount": make_json_dumpable(cart_skel["discount"]),
657659
}
658660
cart_skel["is_frozen"] = True
659661
cart_skel.write()

0 commit comments

Comments
 (0)