Bläddra i källkod

Update v0.8 release notes with more shipping details

master
David Winterbottom 11 år sedan
förälder
incheckning
a4a211bd2c
1 ändrade filer med 47 tillägg och 3 borttagningar
  1. 47
    3
      docs/source/releases/v0.8.rst

+ 47
- 3
docs/source/releases/v0.8.rst Visa fil

176
 The shipping method API has been altered to avoid potential thread-safety
176
 The shipping method API has been altered to avoid potential thread-safety
177
 issues. Prior to v0.8, shipping methods had a ``set_basket`` method which
177
 issues. Prior to v0.8, shipping methods had a ``set_basket`` method which
178
 allowed a basket instance to be assigned. This was really a crutch to allow
178
 allowed a basket instance to be assigned. This was really a crutch to allow
179
-templates to have easy access to shipping charges. However, it was also a
179
+templates to have easy access to shipping charges (as they could be read
180
+straight off the shipping method instance). However, it was also a
180
 design problem as shipping methods could be instantiated at compile-time
181
 design problem as shipping methods could be instantiated at compile-time
181
 leading to a thread safety issue where multiple threads could assign a basket
182
 leading to a thread safety issue where multiple threads could assign a basket
182
 to the same shipping method instance.
183
 to the same shipping method instance.
183
 
184
 
184
 In Oscar 0.8, shipping methods are stateless services that have a method
185
 In Oscar 0.8, shipping methods are stateless services that have a method
185
 :func:`~oscar.apps.shipping.methods.Base.calculate` that takes a basket and
186
 :func:`~oscar.apps.shipping.methods.Base.calculate` that takes a basket and
186
-returns a ``Price`` instance.  New template tags are provided that allow these
187
-shipping charges to be accessed from templates.
187
+returns a ``Price`` instance.  New :doc:`template tags </ref/templatetags/>` are
188
+provided that allow these shipping charges to be accessed from templates.
188
 
189
 
189
 This API change does require quite a few changes as both the shipping method
190
 This API change does require quite a few changes as both the shipping method
190
 and shipping charge now need to be passed around separately:
191
 and shipping charge now need to be passed around separately:
204
   method has changed to accept the ``shipping_charge`` rather than a
205
   method has changed to accept the ``shipping_charge`` rather than a
205
   ``shipping_method`` instance.
206
   ``shipping_method`` instance.
206
 
207
 
208
+Another key change is in the shipping repository object. The
209
+``get_shipping_methods`` method has been split in two to simplify the exercise
210
+of providing new shipping methods. The best practice for Oscar 0.8 is to 
211
+override the ``methods`` attribute if the same set of shipping methods is
212
+available to everyone:
213
+
214
+.. code-block:: python
215
+
216
+    from oscar.apps.shipping import repository, methods
217
+
218
+    class Standard(methods.FixedPrice):
219
+        code = "standard"
220
+        name = "Standard"
221
+        charge_excl_tax = D('10.00')
222
+
223
+
224
+    class Express(methods.FixedPrice):
225
+        code = "express"
226
+        name = "Express"
227
+        charge_excl_tax = D('20.00')
228
+
229
+    class Repository(repository.Repository):
230
+        methods = [Standard(), Express()]
231
+        
232
+or to override ``get_available_shipping_methods`` if the available shipping
233
+methods if only available conditionally:
234
+
235
+.. code-block:: python
236
+
237
+    from oscar.apps.shipping import repository
238
+
239
+    class Repository(repository.Repository):
240
+        
241
+        def get_available_shipping_methods(
242
+                self, basket, shipping_addr=None, **kwargs):
243
+            methods = [Standard()]
244
+            if shipping_addr.country.code == 'US':
245
+                # Express only available in the US
246
+                methods.append(Express())
247
+            return methods
248
+
249
+Note that shipping address should be passed around as instances not classes.
250
+
207
 Other potentially breaking changes related to shipping include:
251
 Other potentially breaking changes related to shipping include:
208
 
252
 
209
 * The :class:`~oscar.apps.order.utils.OrderCreator` class no longer defaults to
253
 * The :class:`~oscar.apps.order.utils.OrderCreator` class no longer defaults to

Laddar…
Avbryt
Spara