Subversion Repositories SmartDukaan

Rev

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

Rev 576 Rev 612
Line 283... Line 283...
283
    retval = True
283
    retval = True
284
    # No need to validate duplicate items since there are only two ways
284
    # No need to validate duplicate items since there are only two ways
285
    # to add items to a cart and both of them check whether the item being
285
    # to add items to a cart and both of them check whether the item being
286
    # added is a duplicate of an already existing item.
286
    # added is a duplicate of an already existing item.
287
    cart = Cart.get_by(id=cartId)
287
    cart = Cart.get_by(id=cartId)
288
    old_estimate = cart.estimate
-
 
289
    new_estimate = 0
-
 
290
    cart_lines = cart.lines
288
    cart_lines = cart.lines
291
    customer_pincode = ""
289
    customer_pincode = ""
292
    if cart.address_id:
290
    if cart.address_id:
293
        address = Address.get_by(id=cart.address_id)
291
        address = Address.get_by(id=cart.address_id)
294
        customer_pincode = address.pin
292
        customer_pincode = address.pin
295
    for line in cart_lines:
293
    for line in cart_lines:
-
 
294
        old_estimate = line.estimate
296
        catalog_item_id = line.item_id
295
        catalog_item_id = line.item_id
297
        if inventory_client.isActive(catalog_item_id):
296
        if inventory_client.isActive(catalog_item_id):
298
            if customer_pincode:
297
            if customer_pincode:
299
                #FIXME: Provider ID should be returned by the same call and shouldn't be hard-coded as 1
298
                #FIXME: Provider ID should be returned by the same call and shouldn't be hard-coded as 1
-
 
299
                try:
300
                item_delivery_estimate = logistics_client.getLogisticsEstimation(catalog_item_id, customer_pincode, 1).shippingTime 
300
                    item_delivery_estimate = logistics_client.getLogisticsEstimation(catalog_item_id, customer_pincode, 1).shippingTime
-
 
301
                except:
-
 
302
                    item_delivery_estimate = 72
301
                if new_estimate < item_delivery_estimate:
303
                if old_estimate != item_delivery_estimate:
302
                    new_estimate = item_delivery_estimate
304
                    line.estimate = item_delivery_estimate
-
 
305
                    retval = False
303
        else:
306
        else:
304
            line.delete()
307
            line.delete()
305
            retval = False
308
            retval = False
306
 
309
    
307
    if new_estimate != old_estimate:
-
 
308
        cart.estimate = new_estimate
-
 
309
        session.commit()
310
    session.commit()
310
        retval = False
-
 
311
    return retval
311
    return retval
312
 
312
 
313
def merge_cart(fromCartId, toCartId):
313
def merge_cart(fromCartId, toCartId):
314
    fromCart = Cart.get_by(id=fromCartId)
314
    fromCart = Cart.get_by(id=fromCartId)
315
    toCart = Cart.get_by(id=toCartId)
315
    toCart = Cart.get_by(id=toCartId)