| Line 26... |
Line 26... |
| 26 |
if privateDealUser is not None and privateDealUser.isActive:
|
26 |
if privateDealUser is not None and privateDealUser.isActive:
|
| 27 |
#Check if user have any order placed successfully
|
27 |
#Check if user have any order placed successfully
|
| 28 |
if cart.lines is not None:
|
28 |
if cart.lines is not None:
|
| 29 |
discounts = []
|
29 |
discounts = []
|
| 30 |
itemIds = []
|
30 |
itemIds = []
|
| 31 |
[itemIds.append(line.itemId) for line in cart.lines]
|
31 |
[itemIds.append(firstLine.itemId) for firstLine in cart.lines]
|
| 32 |
catalog_client = CatalogClient().get_client()
|
32 |
catalog_client = CatalogClient().get_client()
|
| 33 |
privateDeals= catalog_client.getAllActivePrivateDeals(itemIds,0)
|
33 |
privateDeals= catalog_client.getAllActivePrivateDeals(itemIds,0)
|
| 34 |
if(len(privateDeals) == 0):
|
34 |
if(len(privateDeals) != 0):
|
| 35 |
raise PromotionException(115, 'None of the products have valid Private Deal')
|
- |
|
| 36 |
dealItems = privateDeals.keys()
|
35 |
dealItems = privateDeals.keys()
|
| 37 |
total_discounts = 0
|
36 |
total_discounts = 0
|
| - |
|
37 |
discountsMap = {}
|
| 38 |
for line in cart.lines:
|
38 |
for firstLine in cart.lines:
|
| 39 |
if line.itemId in dealItems:
|
39 |
if firstLine.itemId in dealItems:
|
| 40 |
discountAmount = line.actualPrice - privateDeals[line.itemId].dealPrice
|
40 |
discountAmount = firstLine.actualPrice - privateDeals[firstLine.itemId].dealPrice
|
| 41 |
if discountAmount > 0:
|
41 |
if discountAmount > 0:
|
| 42 |
discount = Discount()
|
42 |
discount = Discount()
|
| 43 |
discount.cart_id = cart.id
|
43 |
discount.cart_id = cart.id
|
| 44 |
discount.item_id = line.itemId
|
44 |
discount.item_id = firstLine.itemId
|
| 45 |
discount.quantity = line.quantity
|
45 |
discount.quantity = firstLine.quantity
|
| 46 |
discount.discount = discountAmount
|
46 |
discount.discount = discountAmount
|
| 47 |
discounts.append(discount)
|
47 |
discounts.append(discount)
|
| - |
|
48 |
discountsMap[firstLine.itemId] = discount
|
| 48 |
total_discounts = total_discounts + discountAmount*line.quantity
|
49 |
total_discounts = total_discounts + discountAmount*firstLine.quantity
|
| 49 |
if privateDeals[line.itemId].dealTextOption==0:
|
50 |
if privateDeals[firstLine.itemId].dealTextOption==0:
|
| 50 |
line.dealText = ''
|
51 |
firstLine.dealText = ''
|
| 51 |
cart.message = 'Offer on deal is changed/removed'
|
52 |
cart.message = 'Offer on deal is changed/removed'
|
| 52 |
if privateDeals[line.itemId].dealTextOption==2:
|
53 |
if privateDeals[firstLine.itemId].dealTextOption==2:
|
| 53 |
line.dealText = privateDeals[line.itemId].dealText
|
54 |
firstLine.dealText = privateDeals[firstLine.itemId].dealText
|
| 54 |
cart.message = 'Offer on deal is changed/removed'
|
55 |
cart.message = 'Offer on deal is changed/removed'
|
| - |
|
56 |
|
| - |
|
57 |
if privateDeals[firstLine.itemId].dealFreebieOption==0:
|
| - |
|
58 |
firstLine.freebieId = 0
|
| - |
|
59 |
if privateDeals[firstLine.itemId].dealFreebieOption==2:
|
| - |
|
60 |
firstLine.freebieId = privateDeals[firstLine.itemId].dealFreebieItemId
|
| - |
|
61 |
cart.discountedPrice = cart.totalPrice - round(total_discounts, 0)
|
| - |
|
62 |
if cart.discountedPrice >= 2000:
|
| - |
|
63 |
counter = privateDealUser.counter
|
| - |
|
64 |
if counter is not None:
|
| - |
|
65 |
if datetime.datetime.now() - counter.createdOn < datetime.timedelta(30) and counter.lastPurchasedOn is None:
|
| - |
|
66 |
firstLine = cart.lines[0]
|
| - |
|
67 |
if discountsMap.has_key(firstLine.itemId):
|
| - |
|
68 |
discount1 = discountsMap[firstLine.itemId]
|
| - |
|
69 |
else:
|
| - |
|
70 |
discount1 = Discount()
|
| - |
|
71 |
discount1.cart_id = cart.id
|
| - |
|
72 |
discount1.item_id = firstLine.itemId
|
| - |
|
73 |
discount1.quantity = firstLine.quantity
|
| - |
|
74 |
discount1.discount = 0
|
| - |
|
75 |
discounts.append(discount1)
|
| - |
|
76 |
discount1.discount += round(200/discount1.quantity, 0)
|
| - |
|
77 |
cart.discountedPrice -= round(200/discount1.quantity, 0)*discount1.quantity
|
| - |
|
78 |
else:
|
| - |
|
79 |
if cart.totalPrice >= 2000:
|
| - |
|
80 |
counter = privateDealUser.counter
|
| - |
|
81 |
if counter is not None:
|
| - |
|
82 |
if datetime.datetime.now() - counter.createdOn < datetime.timedelta(30) and counter.lastPurchasedOn is None:
|
| - |
|
83 |
firstLine = cart.lines[0]
|
| - |
|
84 |
discount1 = Discount()
|
| - |
|
85 |
discount1.cart_id = cart.id
|
| - |
|
86 |
discount1.item_id = firstLine.itemId
|
| - |
|
87 |
discount1.quantity = firstLine.quantity
|
| - |
|
88 |
discount1.discount = 0
|
| - |
|
89 |
discounts.append(discount1)
|
| - |
|
90 |
discount1.discount += round(200/discount1.quantity, 0)
|
| - |
|
91 |
cart.discountedPrice = cart.totalPrice - discount1.discount*discount1.quantity
|
| - |
|
92 |
else:
|
| - |
|
93 |
raise PromotionException(115, 'None of the products have valid Private Deal')
|
| 55 |
|
94 |
|
| 56 |
if privateDeals[line.itemId].dealFreebieOption==0:
|
- |
|
| 57 |
line.freebieId = 0
|
- |
|
| 58 |
if privateDeals[line.itemId].dealFreebieOption==2:
|
- |
|
| 59 |
line.freebieId = privateDeals[line.itemId].dealFreebieItemId
|
- |
|
| 60 |
|
- |
|
| 61 |
|
- |
|
| 62 |
cart.discountedPrice = cart.totalPrice - round(total_discounts, 0)
|
- |
|
| 63 |
if cart.discountedPrice > 2000:
|
- |
|
| 64 |
counter = privateDealUser.counter
|
- |
|
| 65 |
if counter is not None:
|
- |
|
| 66 |
if datetime.datetime.now() - counter.createdOn < datetime.timedelta(30) and counter.lastPurchasedOn is None:
|
- |
|
| 67 |
firstTimeDiscount = 200
|
- |
|
| 68 |
return cart, discounts
|
95 |
return cart, discounts
|
| 69 |
else:
|
96 |
else:
|
| 70 |
raise PromotionException(115, 'Invalid Coupon code')
|
97 |
raise PromotionException(115, 'Invalid Coupon code')
|
| 71 |
|
98 |
|