Subversion Repositories SmartDukaan

Rev

Rev 685 | Rev 691 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 685 Rev 690
Line 96... Line 96...
96
    cart = get_cart_by_id(id)
96
    cart = get_cart_by_id(id)
97
    if not cart:
97
    if not cart:
98
        raise ShoppingCartException(101, "no cart attached to this id")
98
        raise ShoppingCartException(101, "no cart attached to this id")
99
    if not status:
99
    if not status:
100
        raise ShoppingCartException(101, "invalid status")
100
        raise ShoppingCartException(101, "invalid status")
101
    cart.cart_status = status     
101
    cart.cart_status = status
102
    session.commit()
102
    session.commit()
103
    
103
    
104
def add_item_to_cart(cart_id, item_id, quantity):
104
def add_item_to_cart(cart_id, item_id, quantity):
105
    if not item_id:
105
    if not item_id:
106
        raise ShoppingCartException(101, "item_id cannot be null")
106
        raise ShoppingCartException(101, "item_id cannot be null")
Line 173... Line 173...
173
    current_time = datetime.datetime.now()
173
    current_time = datetime.datetime.now()
174
    cart.updated_on = current_time
174
    cart.updated_on = current_time
175
    session.commit()
175
    session.commit()
176
    
176
    
177
def commit_cart(cart_id):   
177
def commit_cart(cart_id):   
178
    cart = get_cart_by_id(cart_id)
178
    cart = get_cart_by_id(cart_id)   
179
    #cart.cart_status = CartStatus.COMMITTED
-
 
180
    #cart.committed_on = datetime.datetime.now()
-
 
181
    
-
 
182
    #now we have a cart. Need to create a transaction with it
179
    #now we have a cart. Need to create a transaction with it
183
    txn = TTransaction()
180
    txn = TTransaction()
184
    txn.shoppingCartid = cart_id
181
    txn.shoppingCartid = cart_id
185
    txn.customer_id = cart.user_id
182
    txn.customer_id = cart.user_id
186
    txn.createdOn = to_java_date(datetime.datetime.now())
183
    txn.createdOn = to_java_date(datetime.datetime.now())
Line 230... Line 227...
230
    
227
    
231
    t_order.total_amount = t_line_item.total_price
228
    t_order.total_amount = t_line_item.total_price
232
    t_order.total_weight = t_line_item.total_weight
229
    t_order.total_weight = t_line_item.total_weight
233
    t_order.lineitems = [t_line_item]
230
    t_order.lineitems = [t_line_item]
234
    
231
    
235
    t_order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
232
    t_order.status = OrderStatus.PAYMENT_PENDING
236
    t_order.statusDescription = "Submitted to warehouse"
233
    t_order.statusDescription = "Submitted to warehouse"
237
    t_order.created_timestamp = to_java_date(datetime.datetime.now())
234
    t_order.created_timestamp = to_java_date(datetime.datetime.now())
238
    
235
    
239
    logistics_client = LogisticsClient().get_client()
236
    logistics_client = LogisticsClient().get_client()
240
    logistics_info = logistics_client.getLogisticsInfo(t_order.customer_pincode, t_line_item.sku_id)
237
    logistics_info = logistics_client.getLogisticsInfo(t_order.customer_pincode, t_line_item.sku_id)
Line 278... Line 275...
278
    # to add items to a cart and both of them check whether the item being
275
    # to add items to a cart and both of them check whether the item being
279
    # added is a duplicate of an already existing item.
276
    # added is a duplicate of an already existing item.
280
    cart = Cart.get_by(id=cartId)
277
    cart = Cart.get_by(id=cartId)
281
    cart_lines = cart.lines
278
    cart_lines = cart.lines
282
    customer_pincode = ""
279
    customer_pincode = ""
-
 
280
    current_time = datetime.datetime.now()
283
    if cart.address_id:
281
    if cart.address_id:
284
        address = Address.get_by(id=cart.address_id)
282
        address = Address.get_by(id=cart.address_id)
285
        customer_pincode = address.pin
283
        customer_pincode = address.pin
286
    for line in cart_lines:
284
    for line in cart_lines:
287
        old_estimate = line.estimate
285
        old_estimate = line.estimate
Line 292... Line 290...
292
                    item_delivery_estimate = logistics_client.getLogisticsEstimation(item_id, customer_pincode).deliveryTime
290
                    item_delivery_estimate = logistics_client.getLogisticsEstimation(item_id, customer_pincode).deliveryTime
293
                except:
291
                except:
294
                    item_delivery_estimate = 3
292
                    item_delivery_estimate = 3
295
                if old_estimate != item_delivery_estimate:
293
                if old_estimate != item_delivery_estimate:
296
                    line.estimate = item_delivery_estimate
294
                    line.estimate = item_delivery_estimate
-
 
295
                    cart.updated_on = current_time
297
                    retval = False
296
                    retval = False
298
        else:
297
        else:
299
            line.delete()
298
            line.delete()
300
            retval = False
299
            retval = False
-
 
300
    if cart.updated_on > cart.checked_out_on:
301
    
301
        retval = False
302
    session.commit()
302
    session.commit()
303
    return retval
303
    return retval
304
 
304
 
305
def merge_cart(fromCartId, toCartId):
305
def merge_cart(fromCartId, toCartId):
306
    fromCart = Cart.get_by(id=fromCartId)
306
    fromCart = Cart.get_by(id=fromCartId)