I need to add a "free shipping if purchased more than $100" functionality for the Canada Post module in satchmo. Can this be done out of the box, or will I need to make a new shipping module?
OK, to do this I did the following:
from product.models import Discount
class AutoDiscount(Discount):
pass
This allows me to define the different discounts in the admin area, and then do this:
def check_automatic_discounts(sender, form=None, **kwargs):
"""
"""
if sender in (CreditPayShipForm, SimplePayShipForm,
PaymentContactInfoForm):
# I probably need to sort these in some specific order
for discount in AutoDiscount.objects.all():
if discount.isValid(cart=form.cart,)[0]:
form.order.discount_code = discount.code
form.order.save()
return
signals.form_postsave.connect(check_automatic_discounts)
I can add fields to the AutoDiscount
model and override the isValid
method if I need more detailed control over which discounts are applied