Skip to content

Commit ac5372b

Browse files
author
Chris Glass
committed
Adapted cart modifiers to API in latest django-shop version (0.0.9)
1 parent a87a959 commit ac5372b

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

shop_simplevariations/cart_modifier.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,34 @@ class ProductOptionsModifier(BaseCartModifier):
77
This modifier adds an extra field to the cart to let the lineitem "know"
88
about product options and their respective price.
99
'''
10-
def add_extra_cart_item_price_field(self, cart_item):
10+
def process_cart_item(self, cart_item):
1111
'''
12-
This adds a list of price modifiers dependeing on the product options
12+
This adds a list of price modifiers depending on the product options
1313
the client selected for the current cart_item (if any)
1414
'''
1515
selected_options = CartItemOption.objects.filter(cartitem=cart_item)
16-
1716
for selected_opt in selected_options:
1817
option_obj = selected_opt.option
19-
data = (option_obj.name, option_obj.price * cart_item.quantity)
18+
price = option_obj.price * cart_item.quantity
19+
data = (option_obj.name, price)
20+
# Don't forget to update the running total!
21+
cart_item.current_total = cart_item.current_total + price
2022
cart_item.extra_price_fields.append(data)
21-
2223
return cart_item
2324

2425

2526
class TextOptionsModifier(BaseCartModifier):
2627
"""
27-
THis price modifier appends all the text options it finds in the database for
28+
This price modifier appends all the text options it finds in the database for
2829
a given cart item to the item's extra_price_fields.
2930
"""
30-
def add_extra_cart_item_price_field(self, cart_item):
31+
def process_cart_item(self, cart_item):
3132
text_options = CartItemTextOption.objects.filter(cartitem=cart_item)
3233
for text_opt in text_options:
33-
data = ('Text: "%s"', text_opt.text_option.price)
34+
price = text_opt.text_option.price
35+
data = ('Text: "%s"', price)
36+
# Don't forget to update the running total!
37+
cart_item.current_total = cart_item.current_total + price
38+
#Append to the cart_item's list now.
3439
cart_item.extra_price_fields.append(data)
40+
return cart_item

0 commit comments

Comments
 (0)