VAWT (Vertical Axis Wind Turbine) - uge v-air wind turbine
Selecting the appropriate stockrecord to use for fulfilment. If a product can be fulfilled by several fulfilment partners, then each will have their own stockrecord.
Allow a product to be bought while there is stock. This policy is instantiated with a stock number (num_available). It ensures that the product is only available to buy while there is stock available.
Pricing policy mixin for use with the Structured base strategy. This mixin specifies zero tax and uses the price from the stockrecord.
Always picks the first stockrecord (this is backwards compatible with Oscar<0.6 where a product could only have one stockrecord).
For most projects, subclassing and overriding the Structured base class should be sufficient. However, Oscar also provides mixins to easily compose the appropriate strategy class for your domain.
Oscar allows you to define a currency code for each stock - a text field that defaults to settings.OSCAR_DEFAULT_CURRENCY.
This might be appropriate for digital products where stock doesnât need to be tracked and the product is always available to buy.
Elegantly handle different tax models. A strategy can return prices including tax for a UK or European visitor, but without tax for US visitors where tax is only determined once shipping details are confirmed.
Charge different prices to different customers. A strategy can return a different pricing policy depending on the user/session.
Passing just the user. This is for offline processes that donât have a request instance but do know which user to determine prices for.
This method is provided to allow purchase info to be determined using a basket lineâs attributes. For instance, âbundleâ products often use basket line attributes to store SKUs of contained products. For such products, we need to look at the availability of each contained product to determine overall availability.
The normal first step is provide your own Selector class which returns a custom strategy class. Your custom strategy class can be composed of the above mixins or your own custom logic.
By default, Oscar expects all products added to a single basket to have the same currency. It does not however do any logic to select the appropriate stock record to achieve this - you must implement this yourself in the select_stockrecord() method. Oscar does not determine or store user currency and uses it only for formatting product price. More complex logic, like currency switch or conversion can be implemented additionally.
Like pricing policies, availability policies are simple classes with several properties and methods. The job of an availability policy is to provide availability messaging to show to the customer as well as methods to determine if the product is available to buy.
Also, basket instances have a strategy instance assigned so they can calculate prices including taxes. This is done automatically in the basket middleware.
Passing nothing. This is for offline processes that donât correspond to a specific user, e.g., determining a price to store in a search index.
Note that this price class uses the tax-exclusive price for offers, even if the tax is known. This may not be what you want. Use the TaxInclusiveFixedPrice class if you want offers to use tax-inclusive prices.
Price and availabilitysubject to change
A strategy class which provides separate, overridable methods for determining the 3 things that a PurchaseInfo instance requires:
Hereâs an example strategy.py module which is suitable for use in the US where taxes canât be calculated until the shipping address is known. You normally need to use a 3rd party service to determine taxes - details omitted here.
The strategy class is used in several places in Oscar, for example, the purchase_info_for_product template tag which is used to load the price and availability information into the template context:
Cookies: To give our customers the best shopping experience, our website uses cookies. By clicking continue, you acknowledge our use of cookies. Learn MoreContinue
A description of the availability of a product. This is shown on the product detail page, e.g., âIn stockâ, âOut of stockâ etc
A pricing policy is a simple class with several properties Its job is to contain all price and tax information about a product.
Oscar also provides a âstructuredâ strategy class which provides overridable methods for selecting the stockrecord, and determining pricing and availability policies:
The Product model captures the core data about the product (title, description, images) while the StockRecord model represents fulfilment information for one particular partner (number in stock, base price). A product can have multiple stockrecords although only one is selected by the strategy to determine pricing and availability.
Oscar uses a âstrategyâ object to determine product availability and pricing. A new strategy instance is assigned to the request by the basket middleware. A Selector class determines the appropriate strategy for the request. By modifying the Selector class, itâs possible to return different strategies for different customers.
Transact in multiple currencies. The strategy class can use the customerâs location to select a stockrecord from a local distribution partner which will be in the local currency of the customer.
Selecting an âavailability policyâ, an object responsible for availability logic (i.e. is the product available to buy) and customer messaging.
This page explains how prices and availability are determined in Oscar. In short, it seems quite complicated at first as there are several parts to it, but what this buys is flexibility: buckets of it.
These three entities are wrapped up in a PurchaseInfo object, which is a simple named tuple. The strategy class provides fetch_for_product and fetch_for_parent methods which takes a product and returns a PurchaseInfo instance:
Oscar, on the other hand, distinguishes products from stockrecords and provides a swappable âstrategyâ component for selecting the appropriate stockrecord, calculating prices and availability information.
Pricing policy mixin for use with the Structured base strategy. This mixin applies a fixed rate tax to the base price from the productâs stockrecord. The price_incl_tax is quantized to two decimal places. Rounding behaviour is Decimalâs default
While this probably seems like quite an involved way of looking up a productâs price, it gives the developer an immense amount of flexibility. Hereâs a few examples of things you can do with a strategy class:
Price and availabilitymeaning
This is suitable for physical products where back orders (e.g. allowing purchases when there isnât stock available) are not permitted.
Stockrecord selection mixin for use with the Structured base strategy. This mixin picks the first (normally only) stockrecord to fulfil a product.
Use a chain of preferred partners for fulfilment. A site could have many stockrecords for the same product, each from a different fulfilment partner. The strategy class could select the partner with the best margin and stock available. When stock runs out with that partner, the strategy could seamlessly switch to the next best partner.
Pricing policy mixin for use with the Structured base strategy. This mixin does not specify the product tax and is suitable to territories where tax isnât known until late in the checkout process.
Availability policy mixin for use with the Structured base strategy. This mixin ensures that a product can only be bought if it has stock available (if stock is being tracked).
Oscar also ships with several mixins which implement one method of the Structured strategy. These allow strategies to be easily composed from re-usable parts: