Hi,

I have a working app that restricts the x number of uses per discount.
It can be easily extended to do the other two. Would the satchmo wiki a good 
place to paste the code?
Here is the signal I am connecting to
product.signals.discount_validate.send(sender=Discount, discount=self, 
cart=cart, contact=contact, shipping_choices=shipping_choices, 
shipping=shipping, success=success)

And here is my signal

def veto_discount(sender, discount, contact, success, **kwargs):
    """
    vetos the discount if the user already used it
    """
    disc = DiscountUse.objects.filter(discount=discount, 
active=True).exclude(expire__lt=datetime.date.today())
    if disc:
        try:
            disuse = DiscountUserUse.objects.filter(discount=disc[0], 
custid=contact.id)
            if len(disuse) >= disc[0].maxuse:
                success["valid"] = False
                success["message"] = "Discount Code reached the maximum limit"
            else:
                du = DiscountUserUse()
                du.discount = disc[0]
                du.custid = contact.id
                du.save()
        except Exception, e:
            pass

It stores the uses in a simple table where you can also set expire so you only 
restrict it for the launch day etc.
Also I have a product qty which does the same but with product, so only 2 per 
customer.

lzantal


On Oct 23, 2011, at 8:52 PM, Bruce Kroeze wrote:

> Actually, I'm thinking that a lot of the discount code needs to be rewritten 
> and made more flexible.  Having end dates be required is just the least of it.
> 
> For some of my clients, I've implemented things like:
> - Single-use or x-number of uses discounts
> - Discounts which can only be used by a client or a group of clients 
> (user.group)
> - Discounts which can only be used by existing clients
> 
> But these all required forking the built-in discount code.  I'd much rather 
> see it modularized via signals in a better-thought-out way.  At least, I hope 
> it could all be done with signals.  Some magical day when I have time, I'll 
> do that, if some other kind soul doesn't beat me to it.
> 
> On Fri, Oct 21, 2011 at 8:45 AM, Stuart Laughlin <[email protected]> 
> wrote:
> On Thu, Oct 20, 2011 at 1:56 PM, Joshua J. Kugler <[email protected]> 
> wrote:
> > On Thursday, October 20, 2011, Tomas Neme elucidated thus:
> >> startDate and endDate are not optional.. isn't there a way I can make
> >> a discount that never expires?
> >
> > Is there a reason you can't just set it to expire 10 or 20 years from
> > now?
> >
> 
> Precisely.
> 
> "never expires" == how_long_I_foresee_myself_working_on_this_project +
> five_years ;)
> 
> 
> --Stuart
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Satchmo users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/satchmo-users?hl=en.
> 
> 
> 
> 
> -- 
> Bruce Kroeze
> http://www.ecomsmith.com
> It's time to hammer your site into shape.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Satchmo users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/satchmo-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Satchmo users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/satchmo-users?hl=en.

Reply via email to