Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
FixedDiscounts now are using ProductVariants instead of Products
Artur Smęt63e846c53a3c
diff --git a/saleor/product/forms.py b/saleor/product/forms.pyindex 3e0c5010ec..350da206fd 100644--- a/saleor/product/forms.py+++ b/saleor/product/forms.py@@ -18,7 +18,7 @@ class ShirtForm(AddToCartForm):def __init__(self, *args, **kwargs):super(ShirtForm, self).__init__(*args, **kwargs)available_sizes = [- (p.size, p.get_size_display) for p in self.product.variants.all()+ (p.size, p.get_size_display()) for p in self.product.variants.all()]self.fields['size'].choices = available_sizesdiff --git a/saleor/product/models.py b/saleor/product/models.pyindex b279c37f9b..8e3b0ae6bc 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -136,9 +136,9 @@ class ProductImage(Image):class ProductDiscountManager(models.Manager):- def for_product(self, product):+ def for_product(self, variant):# Add a caching layer here to reduce the number of queries- return self.get_query_set().filter(products=product)+ return self.get_query_set().filter(products=variant.product)class FixedProductDiscount(models.Model):@@ -151,10 +151,10 @@ class FixedProductDiscount(models.Model):objects = ProductDiscountManager()- def modifier_for_product(self, product):- if not self.products.filter(pk=product.pk).exists():+ def modifier_for_product(self, variant):+ if not self.products.filter(pk=variant.product.pk).exists():raise NotApplicable('Discount not applicable for this product')- if self.discount > product.get_price(discounted=False):+ if self.discount > variant.get_price(discounted=False):raise NotApplicable('Discount too high for this product')return FixedDiscount(self.discount, name=self.name)@@ -166,10 +166,10 @@ class FixedProductDiscount(models.Model):str(self.discount), self.name)-def get_product_discounts(product, **kwargs):- for discount in FixedProductDiscount.objects.for_product(product):+def get_product_discounts(variant, **kwargs):+ for discount in FixedProductDiscount.objects.for_product(variant):try:- yield discount.modifier_for_product(product, **kwargs)+ yield discount.modifier_for_product(variant, **kwargs)except NotApplicable:pass