Creating a custom offer condition to give X% discount if basket.total_excl_tax > Y - where to place the files, how to name the files, etc.

444 views
Skip to first unread message

shafiqu...@gmail.com

unread,
Sep 3, 2014, 11:12:06 PM9/3/14
to django...@googlegroups.com
Hello all,

I've been looking through the google group mails and the documentation, and I'm having trouble figuring this one how. Here's what I want to do:

Give a 10% discount for purchases over $400
Replace that with a 15% discount for orders over $500
Replace that with a 20% discount for orders over $650

The documentation tells how to create a custom offer condition:


And here is one example of an implementation of a custom offer condition:


So I'm starting with the example they give. But I need more info:

1. Do I fork the offer app? I have done so and placed the new files in folder oscaroverrides/offer/
2. What do I name the files, and what code to I put in there? Here's what I have so far:

# oscaroverrides/offer/my_custom_discount.py

from oscar.apps.offer import models

class TenPercentForOver400(models.Condition):
    name = "Save 10 percent orders over $400"

    class Meta:
        proxy = True

    def is_satisfied(self, offer, basket):
        if basket.total_excl_tax < 500:
            return False
        return True

from oscar.apps.offer.custom import create_condition

create_condition(TenPercentForOverTJS400)

Did I name the file correctly? How do I let django-oscar know that it exists and to execute it?

3. I need to do more, as per the instructions in the documentation. For example the documentation says to implement "consume_items method that marks basket items as consumed once the condition has been met". Is this simply a matter of using the following code:

def consume_items(self, offer, basket, affected_lines):
        return 

Shouldn't the items be consumed only when they have been purchased?

4. How do I apply the discount? 

Thanks,

David Winterbottom

unread,
Sep 9, 2014, 5:42:56 AM9/9/14
to django-oscar
I'm not sure you need a custom condition for your requirements.

You could create 3 offers for your 3 discounts, where the condition is a "value" condition across a range of the whole site, and the benefit/incentive is a normal % discount. The only thing you'd need to ensure is that the $650 offer is applied first, then the $500 then $400 as otherwise the $400 would match first and be applied when a better offer may be applicable.

To resolve the ordering issue, I think you'll need to override the 'get_site_offers' method on the 'Applicator' class:

There is already a 'priority' field on the offer model that you can use to specify application order:

--
https://github.com/tangentlabs/django-oscar
http://django-oscar.readthedocs.org/en/latest/
https://twitter.com/django_oscar
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-oscar.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-oscar/3288f171-3ae3-4332-be09-69ade54b3161%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
David Winterbottom
Technical Director

Tangent Snowball
84-86 Great Portland Street
London W1W 7NR
England, UK

Reply all
Reply to author
Forward
0 new messages