| Line 240... |
Line 240... |
| 240 |
def commit_cart(cart_id, sessionSource, sessionTime, firstSource, firstSourceTime, userId, schemeId, orderSource):
|
240 |
def commit_cart(cart_id, sessionSource, sessionTime, firstSource, firstSourceTime, userId, schemeId, orderSource):
|
| 241 |
cart = get_cart_by_id(cart_id)
|
241 |
cart = get_cart_by_id(cart_id)
|
| 242 |
#now we have a cart. Need to create a transaction with it
|
242 |
#now we have a cart. Need to create a transaction with it
|
| 243 |
totalCartVal = 0
|
243 |
totalCartVal = 0
|
| 244 |
totalshippingCost = 0
|
244 |
totalshippingCost = 0
|
| - |
|
245 |
totalQty = 0
|
| 245 |
for lineObj in cart.lines:
|
246 |
for lineObj in cart.lines:
|
| 246 |
totalCartVal += lineObj.actual_price * lineObj.quantity
|
247 |
totalCartVal += lineObj.actual_price * lineObj.quantity
|
| - |
|
248 |
totalQty += lineObj.quantity
|
| 247 |
txn = TTransaction()
|
249 |
txn = TTransaction()
|
| 248 |
txn.shoppingCartid = cart_id
|
250 |
txn.shoppingCartid = cart_id
|
| 249 |
txn.customer_id = userId
|
251 |
txn.customer_id = userId
|
| 250 |
txn.createdOn = to_java_date(datetime.datetime.now())
|
252 |
txn.createdOn = to_java_date(datetime.datetime.now())
|
| 251 |
txn.transactionStatus = TTransactionStatus.INIT
|
253 |
txn.transactionStatus = TTransactionStatus.INIT
|
| Line 255... |
Line 257... |
| 255 |
txn.sessionStartTime = sessionTime
|
257 |
txn.sessionStartTime = sessionTime
|
| 256 |
txn.firstSource = firstSource
|
258 |
txn.firstSource = firstSource
|
| 257 |
txn.firstSourceTime = firstSourceTime
|
259 |
txn.firstSourceTime = firstSourceTime
|
| 258 |
txn.payment_option = schemeId
|
260 |
txn.payment_option = schemeId
|
| 259 |
privateDealUser = PrivateDealUser.query.filter(PrivateDealUser.id == userId).filter(PrivateDealUser.isActive==True).first()
|
261 |
privateDealUser = PrivateDealUser.query.filter(PrivateDealUser.id == userId).filter(PrivateDealUser.isActive==True).first()
|
| - |
|
262 |
perUnitShippingCost = 0
|
| 260 |
if privateDealUser is not None:
|
263 |
if privateDealUser is not None:
|
| 261 |
if totalCartVal < 500:
|
264 |
if totalQty >= 5:
|
| 262 |
totalshippingCost = 100
|
265 |
perUnitShippingCost = 30
|
| 263 |
elif totalCartVal >=500 and totalCartVal<1000:
|
266 |
else:
|
| 264 |
totalshippingCost = 50
|
267 |
perUnitShippingCost = 60
|
| 265 |
txn.totalShippingCost = totalshippingCost
|
268 |
|
| 266 |
|
269 |
|
| - |
|
270 |
txn.totalShippingCost = perUnitShippingCost * totalQty
|
| - |
|
271 |
|
| 267 |
txnOrders = create_orders(cart, userId, orderSource, totalshippingCost, totalCartVal)
|
272 |
txnOrders = create_orders(cart, userId, orderSource, perUnitShippingCost, totalCartVal)
|
| 268 |
shippingCostInOrders = 0
|
273 |
shippingCostInOrders = 0
|
| 269 |
for order in txnOrders:
|
274 |
for order in txnOrders:
|
| 270 |
shippingCostInOrders = shippingCostInOrders + order.shippingCost
|
275 |
shippingCostInOrders = shippingCostInOrders + order.shippingCost
|
| 271 |
|
276 |
|
| 272 |
diff = totalshippingCost - shippingCostInOrders
|
277 |
diff = totalshippingCost - shippingCostInOrders
|
| Line 283... |
Line 288... |
| 283 |
privateDealUser.counter.lastPurchasedOn = datetime.datetime.now()
|
288 |
privateDealUser.counter.lastPurchasedOn = datetime.datetime.now()
|
| 284 |
session.commit()
|
289 |
session.commit()
|
| 285 |
|
290 |
|
| 286 |
return txn_id
|
291 |
return txn_id
|
| 287 |
|
292 |
|
| 288 |
def create_orders(cart, userId, orderSource, totalshippingCost, totalCartVal):
|
293 |
def create_orders(cart, userId, orderSource, perUnitShippingCost, totalCartVal):
|
| 289 |
cart_lines = cart.lines
|
294 |
cart_lines = cart.lines
|
| 290 |
orders = []
|
295 |
orders = []
|
| 291 |
isGv = False
|
296 |
isGv = False
|
| 292 |
if cart.coupon_code:
|
297 |
if cart.coupon_code:
|
| 293 |
try:
|
298 |
try:
|
| Line 308... |
Line 313... |
| 308 |
|
313 |
|
| 309 |
for discount in line.discounts:
|
314 |
for discount in line.discounts:
|
| 310 |
#i = 0
|
315 |
#i = 0
|
| 311 |
#while i < discount.quantity:
|
316 |
#while i < discount.quantity:
|
| 312 |
t_line_item = create_line_item(line, line.actual_price if isGv else (line.actual_price - discount.discount), line.quantity, itemsMap.get(line.item_id))
|
317 |
t_line_item = create_line_item(line, line.actual_price if isGv else (line.actual_price - discount.discount), line.quantity, itemsMap.get(line.item_id))
|
| 313 |
t_order = create_order(userId, cart.address_id, t_line_item, cart.pickupStoreId, discount.discount if isGv else 0, line.insurer, (line.insuranceAmount/line.quantity), insuranceDetails,line.dataProtectionInsurer,(line.dataProtectionAmount)/line.quantity, orderSource, line.freebieId, totalshippingCost, totalCartVal)
|
318 |
t_order = create_order(userId, cart.address_id, t_line_item, cart.pickupStoreId, discount.discount if isGv else 0, line.insurer, (line.insuranceAmount/line.quantity), insuranceDetails,line.dataProtectionInsurer,(line.dataProtectionAmount)/line.quantity, orderSource, line.freebieId, perUnitShippingCost, totalCartVal)
|
| 314 |
orders.append(t_order)
|
319 |
orders.append(t_order)
|
| 315 |
#i += 1
|
320 |
#i += 1
|
| 316 |
quantity_remaining_for_order -= discount.quantity
|
321 |
quantity_remaining_for_order -= discount.quantity
|
| 317 |
|
322 |
|
| 318 |
if quantity_remaining_for_order > 0:
|
323 |
if quantity_remaining_for_order > 0:
|
| Line 327... |
Line 332... |
| 327 |
orders.append(t_order)
|
332 |
orders.append(t_order)
|
| 328 |
i += 1
|
333 |
i += 1
|
| 329 |
'''
|
334 |
'''
|
| 330 |
return orders
|
335 |
return orders
|
| 331 |
|
336 |
|
| 332 |
def create_order(userId, address_id, t_line_item, pickupStoreId, gvAmount, insurer, insuranceAmount, insuranceDetails, dataProtectionInsurer, dataProtectionAmount, orderSource, freebieId, totalshippingCost, totalCartVal):
|
337 |
def create_order(userId, address_id, t_line_item, pickupStoreId, gvAmount, insurer, insuranceAmount, insuranceDetails, dataProtectionInsurer, dataProtectionAmount, orderSource, freebieId, perUnitShippingCost, totalCartVal):
|
| 333 |
user = User.get_by(id=userId)
|
338 |
user = User.get_by(id=userId)
|
| 334 |
address = Address.get_by(id=address_id)
|
339 |
address = Address.get_by(id=address_id)
|
| 335 |
t_order = TOrder()
|
340 |
t_order = TOrder()
|
| 336 |
|
341 |
|
| 337 |
t_order.customer_id = user.id
|
342 |
t_order.customer_id = user.id
|
| Line 371... |
Line 376... |
| 371 |
else:
|
376 |
else:
|
| 372 |
freebie_item_id = None if freebieId == 0 else freebieId
|
377 |
freebie_item_id = None if freebieId == 0 else freebieId
|
| 373 |
t_order.source = orderSource
|
378 |
t_order.source = orderSource
|
| 374 |
t_order.dataProtectionInsurer = dataProtectionInsurer
|
379 |
t_order.dataProtectionInsurer = dataProtectionInsurer
|
| 375 |
t_order.dataProtectionAmount = dataProtectionAmount
|
380 |
t_order.dataProtectionAmount = dataProtectionAmount
|
| 376 |
t_order.shippingCost = round((t_line_item.total_price*totalshippingCost)/totalCartVal, 0)
|
381 |
#t_order.shippingCost = round((t_line_item.total_price*totalshippingCost)/totalCartVal, 0)
|
| - |
|
382 |
t_order.shippingCost = perUnitShippingCost*t_line_item.quantity
|
| 377 |
return t_order
|
383 |
return t_order
|
| 378 |
|
384 |
|
| 379 |
def create_line_item(line, final_price, quantity=1, item=None):
|
385 |
def create_line_item(line, final_price, quantity=1, item=None):
|
| 380 |
if item is None:
|
386 |
if item is None:
|
| 381 |
inventory_client = CatalogClient().get_client()
|
387 |
inventory_client = CatalogClient().get_client()
|
| Line 1073... |
Line 1079... |
| 1073 |
cart.updated_on = datetime.datetime.now()
|
1079 |
cart.updated_on = datetime.datetime.now()
|
| 1074 |
session.commit()
|
1080 |
session.commit()
|
| 1075 |
session.close()
|
1081 |
session.close()
|
| 1076 |
responseMap['totalQty']= totalQty
|
1082 |
responseMap['totalQty']= totalQty
|
| 1077 |
responseMap['totalAmount']= totalAmount
|
1083 |
responseMap['totalAmount']= totalAmount
|
| 1078 |
if totalAmount > 0 and totalAmount < 500:
|
1084 |
if totalQty >= 5:
|
| 1079 |
shippingCharges = 100
|
1085 |
shippingCharges = totalQty*30
|
| 1080 |
elif totalAmount < 1000:
|
1086 |
else:
|
| 1081 |
shippingCharges = 50
|
1087 |
shippingCharges = totalQty*60
|
| 1082 |
responseMap['shippingCharge']=shippingCharges
|
1088 |
responseMap['shippingCharge']=shippingCharges
|
| 1083 |
responseMap['cartMessageChanged'] = cartMessageChanged
|
1089 |
responseMap['cartMessageChanged'] = cartMessageChanged
|
| 1084 |
responseMap['cartMessageOOS'] = cartMessageOOS
|
1090 |
responseMap['cartMessageOOS'] = cartMessageOOS
|
| 1085 |
responseMap['cartMessageUndeliverable'] = cartMessageUndeliverable
|
1091 |
responseMap['cartMessageUndeliverable'] = cartMessageUndeliverable
|
| 1086 |
return json.dumps(responseMap)
|
1092 |
return json.dumps(responseMap)
|