Subversion Repositories SmartDukaan

Rev

Rev 2121 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1976 varun.gupt 1
'''
2
Created on: May 24, 2011
3
@author: Varun Gupta
4
'''
5
 
6
from shop2020.model.v1.user.impl.PromotionDataAccessors import initialize, create_promotion,\
7
    generate_coupons_for_promotion, apply_coupon, track_coupon_usage,\
8
    get_coupon_usage_count_by_user
9
from shop2020.model.v1.user.impl import PromotionDataAccessors
10
 
11
class PromotionServiceHandler:
12
 
13
    def __init__(self, dbname='user'):
14
        initialize(dbname)
15
 
16
    def createPromotion(self, name, ruleExecutionSrc, startOn, endOn):
17
        '''
18
        Parameters:
19
        - name
20
        - ruleExecutionSrc
21
        - startOn
22
        - endOn
23
        '''
24
        try:
25
            create_promotion(name, ruleExecutionSrc, startOn, endOn)
26
        finally:
27
            PromotionDataAccessors.close_session()
28
 
29
    def getAllPromotions(self):
30
        try:
31
            pass
32
        finally:
33
            PromotionDataAccessors.close_session()
34
 
35
    def getPromotionById(self, promotionId):
36
        '''
37
        Parameters:
38
        - promotionId
39
        '''
40
        try:
41
            pass
42
        finally:
43
            PromotionDataAccessors.close_session()
44
 
45
    def generateCouponsForPromotion(self, promotionId, couponCode):
46
        '''
47
        Parameters:
48
        - promotionId
49
        - couponCode
50
        '''
51
        try:
52
            generate_coupons_for_promotion(promotionId, couponCode)
53
        finally:
54
            PromotionDataAccessors.close_session()
55
 
56
    def applyCoupon(self, couponCode, cartId):
57
        '''
58
        Parameters:
59
        - couponCode
60
        - cartId
61
        '''
62
        try:
63
            print 'Calling apply_coupon'
64
            return apply_coupon(couponCode, cartId)
65
        finally:
66
            PromotionDataAccessors.close_session()
67
 
68
    def trackCouponUsage(self, couponCode, transactionId, userId):
69
        '''
70
        Parameters:
71
        - couponCode
72
        - transactionId
73
        - userId
74
        '''
75
        try:
76
            track_coupon_usage(couponCode, transactionId, userId)
77
        finally:
78
            PromotionDataAccessors.close_session()
79
 
80
    def getCouponUsageCountByUser(self, couponCode, userId):
81
        '''
82
        Parameters:
83
        - couponCode
84
        - userId
85
        '''
86
        try:
87
            return get_coupon_usage_count_by_user(couponCode, userId)
88
        finally:
89
            PromotionDataAccessors.close_session()