Discounts
=========

Satchmo allows you to setup multiple types of discount codes:

 * Straight dollar amounts
 * Percentage off
 * Free shipping

Each of these types can be qualified or limited by:

 * Number of uses
 * Minimum order
 * Specific dates
 * Specific products

.. index::
   single: Discounts

Creating Discounts
------------------

A discount code is easy to setup in Satchmo using the following fields:

  :Description:
    A simple characterization of the discount.  For example, "New User Discount"
    or "Repeat Customer Promotion."

  :Code: The unique identifier a user would enter to activate this discount.

  :Amount:
    A straight dollar discount off a product.  You can only have a dollar OR
    percentage.

  :Percentage: A percent discount off the price.

  :Auto Discounts:
    Use this field to advertise the discount on all products to which it
    applies. Generally this is used for site-wide sales. See
    :ref:`auto-discounts` for details.

  :Allowed Uses: The number of times this discount can be applied.

  :Num Uses: The number of times this discount has been used.

  :Minimum Order:
    The minimum amount that must be purchased before this can
    apply.

  :Start Date: The date when this discount becomes effective.

  :End Date: The date when this discount is no longer valid.

  :Active:
    A flag you can set to make it active.  If you want to create a discount in
    advance but hold off on making it available, you can use this flag.

  :Free Shipping:
    Whether or not this discount allows the user to not have to pay shipping
    charges.

  :Include Shipping:
    A flag to determine if shipping costs should be affected by the discount.

  :Valid Products: A list of all the products this discount is valid for.

  :Valid Categories:

    .. versionadded:: 0.9.1

    A list of categories this discount is valid for; the discount will be valid
    for products in these categories, as well as in their child categories.

.. _auto-discounts:

Site-wide Sales via Auto Discounts
----------------------------------

Automatic discounts are how you do side-wide sales.

.. highlight:: html

.. warning::
  Automatic discounts must always be percentage sales, and you can only have one running at a time. You should also ensure that you do not apply auto discounts to gift certificates.

1. In your site's admin interface, create a new discount.

2. Make an "automatic" discount, so that it is available to the automatic discount template tags. Do not enter a new price in the admin for the products.

3. In the template where you want to show the auto discount, load the ``{% satchmo_discounts %}`` (Visit :doc:`templates` documentation for details on Satchmo filters) filter library.

4. You can now add some markup to your template, similar to below::

    {% if sale %}
    <div>
      <div class="saleprices">
        <h3> Regular price: <span class="saleprice" id="price">{{
                           product.unit_price|currency}}</span></h3>
        <h3> {{ sale.percentage_text }} off: <span class="saleprice" id="sale_saved">{{
                           product|discount_saved:"sale"|currency }}</span></h3>
        <h3> Your price: <span class="saleprice" id="sale_price">{{
                           product|discount_price:"sale"|currency }}</span></h3>
    {% else %}
      <h3 id="price">{{product.unit_price|currency}}</h3>
    </div>
    {% endif %}

The key parts of the above markup are the ``{{ product|discount_saved:"sale"|currency }}`` and the ``{{ product|discount_price:"sale"|currency }}`` filtered variables. The former returns the amount saved by the discount while the latter returns the discounted price, all in the correct locale currency.

.. highlight:: python
