Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add Vouchers for shipping with orders over limit
Krzysztof Wolskie3ff25c09f0a
diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.pyindex 5c9ec2e3b9..5dc284191a 100644--- a/saleor/dashboard/discount/forms.py+++ b/saleor/dashboard/discount/forms.py@@ -62,7 +62,7 @@ class ShippingVoucherForm(forms.ModelForm):limit = PriceField(min_value=0, required=False, currency=settings.DEFAULT_CURRENCY,label=pgettext_lazy(- 'voucher', 'Only if shipping cost is less than or equal to'))+ 'voucher', 'Only if order is over or equal to'))apply_to = forms.ChoiceField(label=pgettext_lazy('voucher', 'Country'), choices=country_choices,required=False)diff --git a/saleor/discount/models.py b/saleor/discount/models.pyindex 77d58642e2..c1d8488b46 100644--- a/saleor/discount/models.py+++ b/saleor/discount/models.py@@ -158,15 +158,18 @@ class Voucher(models.Model):else:return discount+ def validate_limit(self, value):+ limit = self.limit if self.limit is not None else value+ if value < limit:+ msg = pgettext(+ 'voucher',+ 'This offer is only valid for orders over %(amount)s.')+ raise NotApplicable(msg % {'amount': net(limit)})+def get_discount_for_checkout(self, checkout):if self.type == Voucher.VALUE_TYPE:cart_total = checkout.cart.get_total()- limit = self.limit if self.limit is not None else cart_total- if cart_total < limit:- msg = pgettext(- 'voucher',- 'This offer is only valid for orders over %(amount)s.')- raise NotApplicable(msg % {'amount': net(limit)})+ self.validate_limit(cart_total)return self.get_fixed_discount_for(cart_total)elif self.type == Voucher.SHIPPING_TYPE:@@ -185,11 +188,8 @@ class Voucher(models.Model):'voucher', 'This offer is only valid in %(country)s.')raise NotApplicable(msg % {'country': self.get_apply_to_display()})- if self.limit is not None and shipping_method.price > self.limit:- msg = pgettext(- 'voucher',- 'This offer is only valid for shipping over %(amount)s.')- raise NotApplicable(msg % {'amount': net(self.limit)})+ cart_total = checkout.cart.get_total()+ self.validate_limit(cart_total)return self.get_fixed_discount_for(shipping_method.price)elif self.type in (Voucher.PRODUCT_TYPE, Voucher.CATEGORY_TYPE):