選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

shipping.rst 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ========
  2. Shipping
  3. ========
  4. Shipping can be very complicated. Depending on the domain, a wide variety of shipping
  5. scenarios are found in the wild. For instance, calculation of shipping costs can depend on:
  6. * Shipping method (eg standard, courier)
  7. * Shipping address
  8. * Time of day of order (eg if requesting next-day delivery)
  9. * Weight of items in basket
  10. * Customer type (eg business accounts get discounted shipping rates)
  11. * Offers and vouchers that give free or discounted shipping
  12. Further complications can arise such as:
  13. * Only making certain shipping methods available to certain customers
  14. * Tax is only applicable in certain situations
  15. Oscar can handle all of these shipping scenarios.
  16. Shipping in oscar
  17. -----------------
  18. Shipping is handled using "method" objects which represent a means of shipping
  19. an order (eg "standard" or "next-day" delivery). Each method is essentially a
  20. named calculator that takes a basket and is able to calculate the shipping
  21. costs with and without tax.
  22. For example, you may model "standard" delivery by having a calculator object
  23. that charges a fixed price for each item in the basket. The method object
  24. could be configured by passing the fixed price to be used for calculation.
  25. Shipping within checkout
  26. ------------------------
  27. Shipping is first encountered by customers within the checkout flow, on the "shipping
  28. method" view.
  29. It is the responsibility of this class to either:
  30. 1. Offer an a set of delivery methods for the customer to choose from, displaying
  31. the cost of each.
  32. 2. If there is only one method available, to construct the appropriate shipping method
  33. and set it within the checkout session context.
  34. The ``ShippingMethodView`` class handles this behaviour. Its core
  35. implementation looks up a list of available shipping methods using the
  36. ``oscar.shipping.repository.Repository`` class. If there is only one, then
  37. this is written out to the session and a redirect is issued to the next step of
  38. the checkout. If more than one, then each available method is displayed so the
  39. customer can choose.
  40. Default behaviour
  41. -----------------
  42. Oscar ships with a simple model for calculating shipping based on a charge per
  43. order, and a charge per item. This is the ``OrderAndItemLevelChargeMethod``
  44. class and is configured by setting the two charges used for the calculation.
  45. You can use this model to provide multiple methods - each identified by a code.
  46. The core ``Repository`` class will load all defined
  47. ``OrderAndItemLevelChargeMethod`` models and make them available to the
  48. customer. If none are set, then a `FreeShipping` method object will be
  49. returned.
  50. Shipping method classes
  51. -----------------------
  52. Each method object must subclass ``ShippingMethod`` from
  53. ``oscar.shipping.methods`` which provides the required interface. Note that the interface
  54. does not depend on the many other factors that can affect shipping (eg shipping address). The
  55. way to handle this is within your "factory" method which returns availables shipping methods.
  56. Writing your own shipping method
  57. --------------------------------
  58. Simple really - follow these steps:
  59. 1. Subclass ``oscar.shipping.methods.ShippingMethod`` and implement
  60. the methods ``basket_charge_incl_tax`` and ``basket_charge_excl_tax`` for calculating shipping costs.
  61. 2. Override the default ``shipping.repository.Repository`` class and implement your domain logic
  62. for determining which shipping methods are returned based on the user, basket and shipping address
  63. passed in.