|
@@ -43,6 +43,10 @@ class CheckoutSessionData(object):
|
43
|
43
|
del self.request.session[self.SESSION_KEY][namespace][key]
|
44
|
44
|
self.request.session.modified = True
|
45
|
45
|
|
|
46
|
+ def _flush_namespace(self, namespace):
|
|
47
|
+ self.request.session[self.SESSION_KEY][namespace] = {}
|
|
48
|
+ self.request.session.modified = True
|
|
49
|
+
|
46
|
50
|
def flush(self):
|
47
|
51
|
"""
|
48
|
52
|
Delete session key
|
|
@@ -57,12 +61,15 @@ class CheckoutSessionData(object):
|
57
|
61
|
def get_guest_email(self):
|
58
|
62
|
return self._get('guest', 'email')
|
59
|
63
|
|
60
|
|
- # Shipping addresses
|
|
64
|
+ # Shipping address
|
|
65
|
+ # ================
|
|
66
|
+ # Options:
|
|
67
|
+ # 1. No shipping required (eg digital products)
|
|
68
|
+ # 2. Ship to new address (entered in a form)
|
|
69
|
+ # 3. Ship to an addressbook address (address chosen from list)
|
61
|
70
|
|
62
|
71
|
def reset_shipping_data(self):
|
63
|
|
- self._unset('shipping', 'not_required')
|
64
|
|
- self._unset('shipping', 'new_address_fields')
|
65
|
|
- self._unset('shipping', 'user_address_id')
|
|
72
|
+ self._flush_namespace('shipping')
|
66
|
73
|
|
67
|
74
|
def no_shipping_required(self):
|
68
|
75
|
"""
|
|
@@ -98,11 +105,12 @@ class CheckoutSessionData(object):
|
98
|
105
|
"""
|
99
|
106
|
return self._get('shipping', 'new_address_fields')
|
100
|
107
|
|
101
|
|
- def user_address_id(self):
|
|
108
|
+ def shipping_user_address_id(self):
|
102
|
109
|
"""
|
103
|
110
|
Get user address id from session
|
104
|
111
|
"""
|
105
|
112
|
return self._get('shipping', 'user_address_id')
|
|
113
|
+ user_address_id = shipping_user_address_id
|
106
|
114
|
|
107
|
115
|
def is_shipping_required(self):
|
108
|
116
|
return self._get('shipping', 'is_required', True)
|
|
@@ -113,7 +121,8 @@ class CheckoutSessionData(object):
|
113
|
121
|
has_old_address = self.user_address_id() > 0
|
114
|
122
|
return has_new_address or has_old_address
|
115
|
123
|
|
116
|
|
- # Shipping methods
|
|
124
|
+ # Shipping method
|
|
125
|
+ # ===============
|
117
|
126
|
|
118
|
127
|
def use_free_shipping(self):
|
119
|
128
|
"""
|
|
@@ -141,30 +150,57 @@ class CheckoutSessionData(object):
|
141
|
150
|
return bool(self._get('shipping', 'method_code'))
|
142
|
151
|
|
143
|
152
|
# Billing address fields
|
|
153
|
+ # ======================
|
|
154
|
+ #
|
|
155
|
+ # There are 3 common options:
|
|
156
|
+ # 1. Billing address is entered manually through a form
|
|
157
|
+ # 2. Billing address is selected from address book
|
|
158
|
+ # 3. Billing address is the same as the shipping address
|
144
|
159
|
|
145
|
160
|
def bill_to_new_address(self, address_fields):
|
146
|
161
|
"""
|
147
|
162
|
Store address fields for a billing address.
|
148
|
163
|
"""
|
|
164
|
+ self._flush_namespace('billing')
|
149
|
165
|
self._set('billing', 'new_address_fields', address_fields)
|
150
|
166
|
|
151
|
|
- def new_billing_address_fields(self):
|
|
167
|
+ def bill_to_user_address(self, address):
|
152
|
168
|
"""
|
153
|
|
- Return fields for a billing address
|
|
169
|
+ Set an address from a user's address book as the billing address
|
|
170
|
+
|
|
171
|
+ :address: The address object
|
154
|
172
|
"""
|
155
|
|
- return self._get('billing', 'new_address_fields')
|
|
173
|
+ self._flush_namespace('billing')
|
|
174
|
+ self._set('billing', 'user_address_id', address.id)
|
156
|
175
|
|
157
|
|
- def billing_address_same_as_shipping(self):
|
|
176
|
+ def bill_to_shipping_address(self):
|
158
|
177
|
"""
|
159
|
178
|
Record fact that the billing address is to be the same as
|
160
|
179
|
the shipping address.
|
161
|
180
|
"""
|
162
|
|
- self._set('payment', 'billing_address_same_as_shipping', True)
|
|
181
|
+ self._flush_namespace('billing')
|
|
182
|
+ self._set('billing', 'billing_address_same_as_shipping', True)
|
|
183
|
+
|
|
184
|
+ # Legacy method name
|
|
185
|
+ billing_address_same_as_shipping = bill_to_shipping_address
|
163
|
186
|
|
164
|
187
|
def is_billing_address_same_as_shipping(self):
|
165
|
|
- return self._get('payment', 'billing_address_same_as_shipping', False)
|
|
188
|
+ return self._get('billing', 'billing_address_same_as_shipping', False)
|
|
189
|
+
|
|
190
|
+ def billing_user_address_id(self):
|
|
191
|
+ """
|
|
192
|
+ Return the ID of the user address being used for billing
|
|
193
|
+ """
|
|
194
|
+ return self._get('billing', 'user_address_id')
|
|
195
|
+
|
|
196
|
+ def new_billing_address_fields(self):
|
|
197
|
+ """
|
|
198
|
+ Return fields for a billing address
|
|
199
|
+ """
|
|
200
|
+ return self._get('billing', 'new_address_fields')
|
166
|
201
|
|
167
|
202
|
# Payment methods
|
|
203
|
+ # ===============
|
168
|
204
|
|
169
|
205
|
def pay_by(self, method):
|
170
|
206
|
self._set('payment', 'method', method)
|