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?
Asked
Active
Viewed 320 times
1
-
1what the.. why does this not have to do with programming? do you even know what satchmo and django are? – Lacrymology Oct 05 '11 at 13:49
-
1What does your code look like now? – random Oct 05 '11 at 14:00
-
I've ended up hooking into a satchmo signal and adding a customly created Discount code to the order. – Lacrymology Oct 05 '11 at 14:10
-
But by the by.. when I asked this question, there was _no_ code.. unless you wanted me to paste and comment on all the related satchmo code I'd read so far in order to figure out how to do this, which is not a good idea – Lacrymology Oct 05 '11 at 14:11
1 Answers
0
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

Lacrymology
- 2,269
- 2
- 20
- 28
-
1Wouldn’t this override any discount code actually entered by the user? Also, I don’t know if the auto discount code would end up being displayed in email, etc., and could then be reused by the user for other orders. – merwok Dec 04 '14 at 21:56
-
Good point. I.. don't really know either, to be honest. This code is over three years old, and I don't remember if and how I tested for these things – Lacrymology Dec 05 '14 at 11:27
-
I understand :‑) In the end I did not use discount objects, but put custom code in the cost method of shipper objects to return 0 when needed. – merwok Dec 08 '14 at 23:40