| Line 239... |
Line 239... |
| 239 |
|
239 |
|
| 240 |
def commit_cart(cart_id, sessionSource, sessionTime, firstSource, firstSourceTime, userId, schemeId, orderSource, selfPickup):
|
240 |
def commit_cart(cart_id, sessionSource, sessionTime, firstSource, firstSourceTime, userId, schemeId, orderSource, selfPickup):
|
| 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 |
totalQty = 0
|
244 |
totalshippingCost = 0
|
| 245 |
itemIds = []
|
- |
|
| 246 |
for line in cart.lines:
|
- |
|
| 247 |
itemIds.append(line.item_id)
|
- |
|
| 248 |
inventory_client = CatalogClient().get_client()
|
- |
|
| 249 |
itemsMap = inventory_client.getItems(itemIds)
|
- |
|
| 250 |
for lineObj in cart.lines:
|
245 |
for lineObj in cart.lines:
|
| 251 |
item = itemsMap.get(lineObj.item_id)
|
- |
|
| 252 |
totalCartVal += lineObj.actual_price * lineObj.quantity
|
246 |
totalCartVal += lineObj.actual_price * lineObj.quantity
|
| 253 |
#if item.category in [10006, 10010]:
|
- |
|
| 254 |
totalQty += lineObj.quantity
|
- |
|
| 255 |
txn = TTransaction()
|
247 |
txn = TTransaction()
|
| 256 |
txn.shoppingCartid = cart_id
|
248 |
txn.shoppingCartid = cart_id
|
| 257 |
txn.customer_id = userId
|
249 |
txn.customer_id = userId
|
| 258 |
txn.createdOn = to_java_date(datetime.datetime.now())
|
250 |
txn.createdOn = to_java_date(datetime.datetime.now())
|
| 259 |
txn.transactionStatus = TTransactionStatus.INIT
|
251 |
txn.transactionStatus = TTransactionStatus.INIT
|
| Line 262... |
Line 254... |
| 262 |
txn.sessionSource = sessionSource
|
254 |
txn.sessionSource = sessionSource
|
| 263 |
txn.sessionStartTime = sessionTime
|
255 |
txn.sessionStartTime = sessionTime
|
| 264 |
txn.firstSource = firstSource
|
256 |
txn.firstSource = firstSource
|
| 265 |
txn.firstSourceTime = firstSourceTime
|
257 |
txn.firstSourceTime = firstSourceTime
|
| 266 |
txn.payment_option = schemeId
|
258 |
txn.payment_option = schemeId
|
| 267 |
|
- |
|
| - |
|
259 |
privateDealUser = PrivateDealUser.query.filter(PrivateDealUser.id == userId).filter(PrivateDealUser.isActive==True).first()
|
| 268 |
perUnitShippingCost = 0
|
260 |
if privateDealUser is not None:
|
| 269 |
if totalQty >= 5:
|
261 |
if totalCartVal <1000:
|
| 270 |
perUnitShippingCost = 30
|
262 |
totalshippingCost = 50
|
| - |
|
263 |
txn.totalShippingCost = totalshippingCost
|
| 271 |
else:
|
264 |
|
| - |
|
265 |
txnOrders = create_orders(cart, userId, orderSource, totalshippingCost, totalCartVal, selfPickup)
|
| 272 |
perUnitShippingCost = 60
|
266 |
shippingCostInOrders = 0
|
| 273 |
|
267 |
for order in txnOrders:
|
| - |
|
268 |
shippingCostInOrders = shippingCostInOrders + order.shippingCost
|
| 274 |
|
269 |
|
| 275 |
txn.totalShippingCost = perUnitShippingCost * totalQty
|
270 |
diff = totalshippingCost - shippingCostInOrders
|
| 276 |
txnOrders = create_orders(cart, userId, orderSource, perUnitShippingCost, totalCartVal, itemsMap, selfPickup)
|
271 |
txnOrders[0].shippingCost = txnOrders[0].shippingCost + diff
|
| - |
|
272 |
|
| - |
|
273 |
|
| - |
|
274 |
txn.orders = txnOrders
|
| 277 |
|
275 |
|
| 278 |
txn.orders = txnOrders
|
- |
|
| 279 |
transaction_client = TransactionClient().get_client()
|
276 |
transaction_client = TransactionClient().get_client()
|
| 280 |
txn_id = transaction_client.createTransaction(txn)
|
277 |
txn_id = transaction_client.createTransaction(txn)
|
| 281 |
|
278 |
|
| 282 |
session.commit()
|
279 |
session.commit()
|
| 283 |
|
280 |
|
| 284 |
return txn_id
|
281 |
return txn_id
|
| 285 |
|
282 |
|
| 286 |
def create_orders(cart, userId, orderSource, perUnitShippingCost, totalCartVal, itemsMap, selfPickup):
|
283 |
def create_orders(cart, userId, orderSource, totalshippingCost, totalCartVal, selfPickup):
|
| 287 |
cart_lines = cart.lines
|
284 |
cart_lines = cart.lines
|
| 288 |
orders = []
|
285 |
orders = []
|
| 289 |
isGv = False
|
286 |
isGv = False
|
| 290 |
if cart.coupon_code:
|
287 |
if cart.coupon_code:
|
| 291 |
try:
|
288 |
try:
|
| Line 293... |
Line 290... |
| 293 |
isGv = pc.isGiftVoucher(cart.coupon_code)
|
290 |
isGv = pc.isGiftVoucher(cart.coupon_code)
|
| 294 |
except:
|
291 |
except:
|
| 295 |
isGv = False
|
292 |
isGv = False
|
| 296 |
|
293 |
|
| 297 |
insuranceDetails = InsuranceDetails.get_by(addressId = cart.address_id)
|
294 |
insuranceDetails = InsuranceDetails.get_by(addressId = cart.address_id)
|
| 298 |
|
- |
|
| - |
|
295 |
itemIds = []
|
| - |
|
296 |
for line in cart_lines:
|
| - |
|
297 |
itemIds.append(line.item_id)
|
| - |
|
298 |
inventory_client = CatalogClient().get_client()
|
| - |
|
299 |
itemsMap = inventory_client.getItems(itemIds)
|
| 299 |
for line in cart_lines:
|
300 |
for line in cart_lines:
|
| 300 |
if line.line_status == LineStatus.LINE_ACTIVE:
|
301 |
if line.line_status == LineStatus.LINE_ACTIVE:
|
| 301 |
quantity_remaining_for_order = line.quantity
|
302 |
quantity_remaining_for_order = line.quantity
|
| 302 |
|
303 |
|
| 303 |
for discount in line.discounts:
|
304 |
for discount in line.discounts:
|
| 304 |
#i = 0
|
305 |
#i = 0
|
| 305 |
#while i < discount.quantity:
|
306 |
#while i < discount.quantity:
|
| 306 |
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))
|
307 |
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))
|
| 307 |
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, itemsMap.get(line.item_id))
|
308 |
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, selfPickup)
|
| 308 |
orders.append(t_order)
|
309 |
orders.append(t_order)
|
| 309 |
#i += 1
|
310 |
#i += 1
|
| 310 |
quantity_remaining_for_order -= discount.quantity
|
311 |
quantity_remaining_for_order -= discount.quantity
|
| 311 |
|
312 |
|
| 312 |
if quantity_remaining_for_order > 0:
|
313 |
if quantity_remaining_for_order > 0:
|
| 313 |
t_line_item = create_line_item(line, line.actual_price, quantity_remaining_for_order, itemsMap.get(line.item_id))
|
314 |
t_line_item = create_line_item(line, line.actual_price, quantity_remaining_for_order, itemsMap.get(line.item_id))
|
| 314 |
t_order = create_order(userId, cart.address_id, t_line_item, cart.pickupStoreId, 0, line.insurer, (line.insuranceAmount/line.quantity), insuranceDetails, line.dataProtectionInsurer,(line.dataProtectionAmount)/line.quantity, orderSource, line.freebieId, perUnitShippingCost, itemsMap.get(line.item_id), selfPickup)
|
315 |
t_order = create_order(userId, cart.address_id, t_line_item, cart.pickupStoreId, 0, line.insurer, (line.insuranceAmount/line.quantity), insuranceDetails, line.dataProtectionInsurer,(line.dataProtectionAmount)/line.quantity, orderSource, line.freebieId, totalshippingCost, totalCartVal, selfPickup)
|
| 315 |
orders.append(t_order)
|
316 |
orders.append(t_order)
|
| 316 |
|
317 |
|
| 317 |
|
318 |
|
| 318 |
wallet_amount = cart.wallet_amount
|
319 |
wallet_amount = cart.wallet_amount
|
| 319 |
if wallet_amount is None:
|
320 |
if wallet_amount is None:
|
| Line 327... |
Line 328... |
| 327 |
|
328 |
|
| 328 |
order.net_payable_amount = order.total_amount+ order.shippingCost - order.gvAmount - order.wallet_amount
|
329 |
order.net_payable_amount = order.total_amount+ order.shippingCost - order.gvAmount - order.wallet_amount
|
| 329 |
wallet_amount = wallet_amount - order.wallet_amount
|
330 |
wallet_amount = wallet_amount - order.wallet_amount
|
| 330 |
return orders
|
331 |
return orders
|
| 331 |
|
332 |
|
| 332 |
def create_order(userId, address_id, t_line_item, pickupStoreId, gvAmount, insurer, insuranceAmount, insuranceDetails, dataProtectionInsurer, dataProtectionAmount, orderSource, freebieId, perUnitShippingCost, item, selfPickup):
|
333 |
def create_order(userId, address_id, t_line_item, pickupStoreId, gvAmount, insurer, insuranceAmount, insuranceDetails, dataProtectionInsurer, dataProtectionAmount, orderSource, freebieId, totalshippingCost, totalCartVal, selfPickup):
|
| 333 |
user = User.get_by(id=userId)
|
334 |
user = User.get_by(id=userId)
|
| 334 |
address = Address.get_by(id=address_id)
|
335 |
address = Address.get_by(id=address_id)
|
| 335 |
t_order = TOrder()
|
336 |
t_order = TOrder()
|
| 336 |
|
337 |
|
| 337 |
t_order.customer_id = user.id
|
338 |
t_order.customer_id = user.id
|
| Line 356... |
Line 357... |
| 356 |
t_order.created_timestamp = to_java_date(datetime.datetime.now())
|
357 |
t_order.created_timestamp = to_java_date(datetime.datetime.now())
|
| 357 |
|
358 |
|
| 358 |
t_order.pickupStoreId = pickupStoreId
|
359 |
t_order.pickupStoreId = pickupStoreId
|
| 359 |
t_order.insuranceAmount = insuranceAmount
|
360 |
t_order.insuranceAmount = insuranceAmount
|
| 360 |
t_order.insurer = insurer
|
361 |
t_order.insurer = insurer
|
| 361 |
|
- |
|
| 362 |
if insuranceDetails:
|
362 |
if insuranceDetails:
|
| 363 |
t_order.dob = insuranceDetails.dob
|
363 |
t_order.dob = insuranceDetails.dob
|
| 364 |
t_order.guardianName = insuranceDetails.guardianName
|
364 |
t_order.guardianName = insuranceDetails.guardianName
|
| 365 |
|
365 |
|
| 366 |
catalog_client = CatalogClient().get_client()
|
366 |
catalog_client = CatalogClient().get_client()
|
| Line 377... |
Line 377... |
| 377 |
#if item.category in [10006, 10010]:
|
377 |
#if item.category in [10006, 10010]:
|
| 378 |
if selfPickup:
|
378 |
if selfPickup:
|
| 379 |
t_order.logistics_provider_id = 4
|
379 |
t_order.logistics_provider_id = 4
|
| 380 |
t_order.shippingCost = 0
|
380 |
t_order.shippingCost = 0
|
| 381 |
else:
|
381 |
else:
|
| - |
|
382 |
t_order.shippingCost = round((t_line_item.total_price*totalshippingCost)/totalCartVal, 0)
|
| 382 |
t_order.shippingCost = perUnitShippingCost*t_line_item.quantity
|
383 |
#t_order.shippingCost = perUnitShippingCost*t_line_item.quantity
|
| 383 |
#else:
|
384 |
#else:
|
| 384 |
# t_order.shippingCost = 0
|
385 |
# t_order.shippingCost = 0
|
| 385 |
return t_order
|
386 |
return t_order
|
| 386 |
|
387 |
|
| 387 |
def create_line_item(line, final_price, quantity=1, item=None):
|
388 |
def create_line_item(line, final_price, quantity=1, item=None):
|
| Line 395... |
Line 396... |
| 395 |
if item.color is None or item.color == "NA":
|
396 |
if item.color is None or item.color == "NA":
|
| 396 |
t_line_item.color = ""
|
397 |
t_line_item.color = ""
|
| 397 |
else:
|
398 |
else:
|
| 398 |
t_line_item.color = item.color
|
399 |
t_line_item.color = item.color
|
| 399 |
t_line_item.model_name = item.modelName
|
400 |
t_line_item.model_name = item.modelName
|
| 400 |
t_line_item.model_name = item.modelName
|
- |
|
| 401 |
t_line_item.mrp = item.mrp
|
401 |
t_line_item.mrp = item.mrp
|
| 402 |
t_line_item.extra_info = item.featureDescription
|
402 |
t_line_item.extra_info = item.featureDescription
|
| 403 |
t_line_item.item_id = item.id
|
403 |
t_line_item.item_id = item.id
|
| 404 |
t_line_item.quantity = quantity
|
404 |
t_line_item.quantity = quantity
|
| 405 |
|
405 |
|
| Line 958... |
Line 958... |
| 958 |
itemQuantityChanged=True
|
958 |
itemQuantityChanged=True
|
| 959 |
line.quantity = cartItem['maxQuantity']
|
959 |
line.quantity = cartItem['maxQuantity']
|
| 960 |
|
960 |
|
| 961 |
cartItem['quantity'] = line.quantity
|
961 |
cartItem['quantity'] = line.quantity
|
| 962 |
|
962 |
|
| 963 |
print "at : 961"
|
- |
|
| 964 |
|
- |
|
| 965 |
bulkPrice = None
|
963 |
bulkPrice = None
|
| 966 |
singleUnitPricing = False
|
964 |
singleUnitPricing = False
|
| 967 |
if item_id in bulkPricingItems:
|
965 |
if item_id in bulkPricingItems:
|
| 968 |
#Check quantity qualifies or not
|
966 |
#Check quantity qualifies or not
|
| 969 |
bulkPricingList = bulkPricingMap.get(item_id)
|
967 |
bulkPricingList = bulkPricingMap.get(item_id)
|
| Line 1117... |
Line 1115... |
| 1117 |
cart.updated_on = datetime.datetime.now()
|
1115 |
cart.updated_on = datetime.datetime.now()
|
| 1118 |
session.commit()
|
1116 |
session.commit()
|
| 1119 |
session.close()
|
1117 |
session.close()
|
| 1120 |
responseMap['totalQty']= totalQty
|
1118 |
responseMap['totalQty']= totalQty
|
| 1121 |
responseMap['totalAmount']= totalAmount
|
1119 |
responseMap['totalAmount']= totalAmount
|
| 1122 |
|
- |
|
| 1123 |
#Levy charges for non Accessories
|
- |
|
| 1124 |
if totalQty >= 5:
|
1120 |
if totalAmount < 1000:
|
| 1125 |
shippingCharges = totalQty*30
|
- |
|
| 1126 |
else:
|
- |
|
| 1127 |
shippingCharges = totalQty*60
|
1121 |
shippingCharges = 50
|
| 1128 |
|
- |
|
| 1129 |
hasAccessories = False
|
- |
|
| 1130 |
|
- |
|
| 1131 |
#No charge for accessories
|
- |
|
| 1132 |
if totalQty > nonAccessoryQuantity:
|
- |
|
| 1133 |
hasAccessories = True
|
- |
|
| 1134 |
|
- |
|
| 1135 |
responseMap['cartMessages']= cartMessages
|
- |
|
| 1136 |
responseMap['cartItems']= cartItems
|
- |
|
| 1137 |
responseMap['pincode']= customer_pincode
|
- |
|
| 1138 |
responseMap['hasAccessories']= hasAccessories
|
- |
|
| 1139 |
responseMap['shippingCharge']=shippingCharges
|
1122 |
responseMap['shippingCharge']=shippingCharges
|
| 1140 |
responseMap['cartMessageChanged'] = cartMessageChanged
|
1123 |
responseMap['cartMessageChanged'] = cartMessageChanged
|
| 1141 |
responseMap['cartMessageOOS'] = cartMessageOOS
|
1124 |
responseMap['cartMessageOOS'] = cartMessageOOS
|
| 1142 |
responseMap['cartMessageUndeliverable'] = cartMessageUndeliverable
|
1125 |
responseMap['cartMessageUndeliverable'] = cartMessageUndeliverable
|
| 1143 |
responseMap['nonAccessoryQuantity'] = nonAccessoryQuantity
|
- |
|
| 1144 |
responseMap['codAllowed'] = codAllowed
|
1126 |
responseMap['codAllowed'] = codAllowed
|
| 1145 |
return json.dumps(responseMap)
|
1127 |
return json.dumps(responseMap)
|
| 1146 |
|
1128 |
|
| 1147 |
|
1129 |
|
| 1148 |
def validate_cart_plus(cart_id, source_id, couponCode):
|
1130 |
def validate_cart_plus(cart_id, source_id, couponCode):
|