Subversion Repositories SmartDukaan

Rev

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

Rev 6921 Rev 6922
Line 192... Line 192...
192
    else:
192
    else:
193
        cart.pickupStoreId = None
193
        cart.pickupStoreId = None
194
        
194
        
195
    session.commit()
195
    session.commit()
196
    
196
    
197
def apply_coupon_to_cart(cart_id, coupon_code, total_price, discounted_price):
197
def apply_coupon_to_cart(t_cart, coupon_code):
198
    cart = get_cart_by_id(cart_id)
198
    cart = get_cart_by_id(t_cart.id)
199
    if not cart:
199
    if not cart:
200
        raise ShoppingCartException(101, "no cart attached to this id")
200
        raise ShoppingCartException(101, "no cart attached to this id")
-
 
201
    pc = PromotionClient().get_client()
-
 
202
    if not pc.isGiftVoucher(coupon_code):
-
 
203
        for t_line in t_cart.lines:
-
 
204
            line = Line.query.filter_by(cart = cart).filter_by(item_id = t_line.itemId).one()
-
 
205
        #Update its discounted price.
-
 
206
            line.discounted_price = t_line.discountedPrice
-
 
207
    
201
    cart.total_price = total_price
208
    cart.total_price = t_cart.totalPrice
202
    cart.discounted_price = discounted_price
209
    cart.discounted_price = t_cart.discountedPrice
203
    cart.coupon_code = coupon_code
210
    cart.coupon_code = coupon_code
204
    session.commit()
211
    session.commit()
205
 
212
 
206
def remove_coupon(cart_id):
213
def remove_coupon(cart_id):
207
    cart = get_cart_by_id(cart_id)
214
    cart = get_cart_by_id(cart_id)
Line 416... Line 423...
416
            insure_item(line.item_id, cartId, True)
423
            insure_item(line.item_id, cartId, True)
417
    
424
    
418
    if cart.coupon_code is not None:
425
    if cart.coupon_code is not None:
419
        try:
426
        try:
420
            updated_cart = promotion_client.applyCoupon(cart.coupon_code, cart.id)
427
            updated_cart = promotion_client.applyCoupon(cart.coupon_code, cart.id)
421
            totalInsuranceAmt = 0
428
#            totalInsuranceAmt = 0
422
            for t_line in updated_cart.lines:
429
#            for t_line in updated_cart.lines:
423
            #Find the line in the database which corresponds to this line
430
#            #Find the line in the database which corresponds to this line
424
                line = Line.query.filter_by(cart = cart).filter_by(item_id = t_line.itemId).one()
431
#                line = Line.query.filter_by(cart = cart).filter_by(item_id = t_line.itemId).one()
425
            #Update its discounted price.
432
#            #Update its discounted price.
426
                line.discounted_price = t_line.discountedPrice
433
#                line.discounted_price = t_line.discountedPrice
427
            #If discounted price of line is set and this coupon is not a gift voucher that means
434
#            #If discounted price of line is set and this coupon is not a gift voucher that means
428
            # we will need to correct the insurance price accordingly.
435
#            # we will need to correct the insurance price accordingly.
429
#                if line.insurer > 0 and line.discounted_price and not promotion_client.isGiftVoucher(cart.coupon_code) :
436
##                if line.insurer > 0 and line.discounted_price and not promotion_client.isGiftVoucher(cart.coupon_code) :
430
#                    cc = CatalogClient().get_client()
437
##                    cc = CatalogClient().get_client()
431
#                    insuranceAmt = cc.getInsuranceAmount(line.item_id, line.discounted_price, line.insurer, line.quantity)
438
##                    insuranceAmt = cc.getInsuranceAmount(line.item_id, line.discounted_price, line.insurer, line.quantity)
432
#                    line.insuranceAmount = insuranceAmt
439
##                    line.insuranceAmount = insuranceAmt
433
#                    totalInsuranceAmt += insuranceAmt
440
##                    totalInsuranceAmt += insuranceAmt
-
 
441
#            cart.total_price = updated_cart.totalPrice
434
            cart.discounted_price = updated_cart.discountedPrice
442
#            cart.discounted_price = updated_cart.discountedPrice
435
            session.commit()
443
#            session.commit()
436
            if updated_cart.message is not None:
444
            if updated_cart.message is not None:
437
                emival = updated_cart.message
445
                emival = updated_cart.message
438
        except PromotionException as ex:
446
        except PromotionException as ex:
439
            remove_coupon(cart.id)
447
            remove_coupon(cart.id)
440
            retval = ex.message
448
            retval = ex.message