Subversion Repositories SmartDukaan

Rev

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

Rev 6550 Rev 6736
Line 341... Line 341...
341
def validate_cart(cartId, sourceId):
341
def validate_cart(cartId, sourceId):
342
    inventory_client = CatalogClient().get_client()
342
    inventory_client = CatalogClient().get_client()
343
    logistics_client = LogisticsClient().get_client()
343
    logistics_client = LogisticsClient().get_client()
344
    promotion_client = PromotionClient().get_client()
344
    promotion_client = PromotionClient().get_client()
345
    retval = ""
345
    retval = ""
-
 
346
    emival = ""
346
    # No need to validate duplicate items since there are only two ways
347
    # No need to validate duplicate items since there are only two ways
347
    # to add items to a cart and both of them check whether the item being
348
    # to add items to a cart and both of them check whether the item being
348
    # added is a duplicate of an already existing item.
349
    # added is a duplicate of an already existing item.
349
    cart = Cart.get_by(id=cartId)
350
    cart = Cart.get_by(id=cartId)
350
    cart_lines = cart.lines
351
    cart_lines = cart.lines
Line 386... Line 387...
386
            except :
387
            except :
387
                item_delivery_estimate = -1
388
                item_delivery_estimate = -1
388
            if old_estimate != item_delivery_estimate:
389
            if old_estimate != item_delivery_estimate:
389
                line.estimate = item_delivery_estimate
390
                line.estimate = item_delivery_estimate
390
                cart.updated_on = current_time
391
                cart.updated_on = current_time
391
                if old_estimate != None:
-
 
392
                    retval = "Delivery Estimates updated."
-
 
393
        else:
392
        else:
394
            line.delete()
393
            line.delete()
395
            retval = "Some items have been removed from the cart."
-
 
396
    if cart.checked_out_on is not None:
394
    if cart.checked_out_on is not None:
397
        if cart.updated_on > cart.checked_out_on:
395
        if cart.updated_on > cart.checked_out_on:
398
            cart.checked_out_on = None
396
            cart.checked_out_on = None
399
            if retval == "":
-
 
400
                retval = "Your cart has been updated after the last checkout."
-
 
401
    session.commit()
397
    session.commit()
402
    
398
    
403
    if cart.coupon_code is not None:
399
    if cart.coupon_code is not None:
404
        try:
400
        try:
405
            updated_cart = promotion_client.applyCoupon(cart.coupon_code, cart.id)
401
            updated_cart = promotion_client.applyCoupon(cart.coupon_code, cart.id)
Line 408... Line 404...
408
                line = Line.query.filter_by(cart = cart).filter_by(item_id = t_line.itemId).one()
404
                line = Line.query.filter_by(cart = cart).filter_by(item_id = t_line.itemId).one()
409
            #Update its discounted price.
405
            #Update its discounted price.
410
                line.discounted_price = t_line.discountedPrice
406
                line.discounted_price = t_line.discountedPrice
411
            cart.discounted_price = updated_cart.discountedPrice
407
            cart.discounted_price = updated_cart.discountedPrice
412
            session.commit()
408
            session.commit()
-
 
409
            emival = updated_cart.message
413
        except PromotionException as ex:
410
        except PromotionException as ex:
414
            remove_coupon(cart.id)
411
            remove_coupon(cart.id)
415
            retval = ex.message
412
            retval = ex.message
416
    return retval
413
    return [retval, emival]
417
 
414
 
418
def merge_cart(fromCartId, toCartId):
415
def merge_cart(fromCartId, toCartId):
419
    fromCart = Cart.get_by(id=fromCartId)
416
    fromCart = Cart.get_by(id=fromCartId)
420
    toCart = Cart.get_by(id=toCartId)
417
    toCart = Cart.get_by(id=toCartId)
421
    
418