Subversion Repositories SmartDukaan

Rev

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

Rev 11612 Rev 11653
Line 221... Line 221...
221
        raise ShoppingCartException(101, "no cart attached to this id")
221
        raise ShoppingCartException(101, "no cart attached to this id")
222
    
222
    
223
    #Resetting discounted price of each line in cart to Null
223
    #Resetting discounted price of each line in cart to Null
224
    for line in cart.lines:
224
    for line in cart.lines:
225
        line.discounted_price = None
225
        line.discounted_price = None
-
 
226
        line.dealText = None
-
 
227
        line.freebieId = None
226
    
228
    
227
    delete_discounts_from_cart(cart.id, cart=cart)
229
    delete_discounts_from_cart(cart.id, cart=cart)
228
    cart.discounted_price = None
230
    cart.discounted_price = None
229
    cart.coupon_code = None
231
    cart.coupon_code = None
230
    session.commit()
232
    session.commit()
Line 555... Line 557...
555
    datas = []
557
    datas = []
556
    for line in lines:
558
    for line in lines:
557
        datas.append(line[0])
559
        datas.append(line[0])
558
    return datas
560
    return datas
559
 
561
 
560
def insure_item(itemId, cartId, toInsure, insurerType):
562
def insure_item_common(cart, line, toInsure, insurerType):
561
    cart = Cart.get_by(id = cartId)
-
 
562
    line = None
-
 
563
    for cartLine in cart.lines:
-
 
564
        if(cartLine.item_id == itemId):
-
 
565
            line = cartLine
-
 
566
            break
-
 
567
        
-
 
568
    if not line:
-
 
569
        print("Error : No line found for cartId : " + cartId + " and itemId : " + itemId)
-
 
570
        return False
-
 
571
    
-
 
572
    try:
563
    try:
573
        if toInsure:
564
        if toInsure:
574
            csc = CatalogClient().get_client()
565
            csc = CatalogClient().get_client()
575
            item = csc.getItem(itemId)
566
            item = csc.getItem(itemId)
576
            insurerId = csc.getPrefferedInsurerForItem(itemId,insurerType)
567
            insurerId = csc.getPrefferedInsurerForItem(itemId,insurerType)
Line 606... Line 597...
606
        print("Error : Unable to insure")
597
        print("Error : Unable to insure")
607
        print("insurerId : " + str(insurerId) + " ItemId : " + str(itemId) + " CartId : " + str(cartId))
598
        print("insurerId : " + str(insurerId) + " ItemId : " + str(itemId) + " CartId : " + str(cartId))
608
        return False
599
        return False
609
    
600
    
610
    return True
601
    return True
-
 
602
    
-
 
603
def insure_item(itemId, cartId, toInsure, insurerType):
-
 
604
    cart = Cart.get_by(id = cartId)
-
 
605
    line = None
-
 
606
    for cartLine in cart.lines:
-
 
607
        if(cartLine.item_id == itemId):
-
 
608
            line = cartLine
-
 
609
            break
-
 
610
        
-
 
611
    if not line:
-
 
612
        print("Error : No line found for cartId : " + cartId + " and itemId : " + itemId)
-
 
613
        return False
-
 
614
    
611
 
615
 
612
def cancel_insurance(cartId):
616
def cancel_insurance(cartId):
613
    try:
617
    try:
614
        cart = Cart.get_by(id = cartId)
618
        cart = Cart.get_by(id = cartId)
615
        for cartLine in cart.lines:
619
        for cartLine in cart.lines:
Line 649... Line 653...
649
    except:
653
    except:
650
        print("Error : Unable to get insurance details for addressId : " + str(addressId))
654
        print("Error : Unable to get insurance details for addressId : " + str(addressId))
651
        return False
655
        return False
652
    return True
656
    return True
653
 
657
 
654
def validate_cart_plus(cart_id, source_id):
658
def validate_cart_plus(cartId, source_id):
-
 
659
    inventory_client = CatalogClient().get_client()
-
 
660
    logistics_client = LogisticsClient().get_client()
-
 
661
    promotion_client = PromotionClient().get_client()
-
 
662
    retval = ""
-
 
663
    emival = ""
-
 
664
    # No need to validate duplicate items since there are only two ways
-
 
665
    # to add items to a cart and both of them check whether the item being
-
 
666
    # added is a duplicate of an already existing item.
-
 
667
    found_cart = cart = Cart.get_by(id=cartId)
-
 
668
    cart_lines = cart.lines
-
 
669
    customer_pincode = None
-
 
670
    current_time = datetime.datetime.now()
-
 
671
    if cart.pickupStoreId :
-
 
672
        store = logistics_client.getPickupStore(cart.pickupStoreId)
-
 
673
        customer_pincode = store.pin
-
 
674
    if cart.address_id != None and customer_pincode == None:
-
 
675
        address = Address.get_by(id=cart.address_id)
-
 
676
        customer_pincode = address.pin
-
 
677
    if not customer_pincode:
-
 
678
        user = User.get_by(active_cart_id = cartId)
-
 
679
        default_address_id = user.default_address_id
-
 
680
        if default_address_id:
-
 
681
            address = Address.get_by(id = default_address_id)
-
 
682
            customer_pincode = address.pin
-
 
683
    if not customer_pincode:
-
 
684
        #FIXME should not be hard coded. May be we can pick from config server.
-
 
685
        customer_pincode = "110001"
-
 
686
    cart.total_price = 0
-
 
687
    for line in cart_lines:
-
 
688
        old_estimate = line.estimate
-
 
689
        item_id = line.item_id
-
 
690
        item = inventory_client.getItemForSource(item_id, source_id)
-
 
691
        item_shipping_info = inventory_client.isActive(item_id) 
-
 
692
        if item_shipping_info.isActive:
-
 
693
            if item_shipping_info.isRisky and item_shipping_info.quantity < line.quantity:
-
 
694
                line.quantity = 1
-
 
695
                retval = "Try adding a smaller quantity of " + item.brand + " " + item.modelNumber + " (" + item.color + ")"
-
 
696
            
-
 
697
            line.actual_price = item.sellingPrice 
-
 
698
            cart.total_price = cart.total_price + (line.actual_price * line.quantity)
-
 
699
            try:
-
 
700
                item_delivery_estimate = logistics_client.getLogisticsEstimation(item_id, customer_pincode, DeliveryType.PREPAID).deliveryTime
-
 
701
            except LogisticsServiceException:
-
 
702
                item_delivery_estimate = -1
-
 
703
                #TODO Use the exception clause to set the retval appropriately
-
 
704
            except :
-
 
705
                item_delivery_estimate = -1
-
 
706
            if old_estimate != item_delivery_estimate:
-
 
707
                line.estimate = item_delivery_estimate
-
 
708
                cart.updated_on = current_time
-
 
709
        else:
-
 
710
            line.delete()
-
 
711
    if cart.checked_out_on is not None:
-
 
712
        if cart.updated_on > cart.checked_out_on:
-
 
713
            cart.checked_out_on = None
-
 
714
    session.commit()
-
 
715
    
-
 
716
    cart = Cart.get_by(id=cartId)
-
 
717
    cart_lines = cart.lines
-
 
718
    for line in cart_lines :
-
 
719
        if line.insurer > 0 :
-
 
720
            insure_item(line.item_id, cartId, True, InsurerType._NAMES_TO_VALUES.get("DEVICE"))
-
 
721
        if line.dataProtectionInsurer > 0:
-
 
722
            insure_item(line.item_id, cartId, True, InsurerType._NAMES_TO_VALUES.get("DATA"))
-
 
723
    if cart.coupon_code is not None:
655
    try:
724
        try:
-
 
725
            updated_cart = promotion_client.applyCoupon(cart.coupon_code, cart.id)
-
 
726
            if updated_cart.message is not None:
656
        cart_messages = validate_cart(cart_id, source_id)
727
                emival = updated_cart.message
-
 
728
        except PromotionException as ex:
-
 
729
            remove_coupon(cart.id)
-
 
730
            retval = ex.message
-
 
731
    
-
 
732
    return [retval, emival]
657
        found_cart = Cart.get_by(id=cart_id)
733
        found_cart = Cart.get_by(id=cartId)
658
        pincode = "110001"
734
        pincode = "110001"
659
        default_address_id = User.get_by(active_cart_id = cart_id).default_address_id
735
        default_address_id = User.get_by(active_cart_id = cart_id).default_address_id
660
        
736
        
661
        default_address = None
737
        default_address = None
662
        if found_cart.address_id is not None and found_cart.address_id > 0:
738
        if found_cart.address_id is not None and found_cart.address_id > 0: