Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Item with doubled discount category shouldn't be clone
Maciek Jabłoński27e8f35f4057
diff --git a/saleor/cart/utils.py b/saleor/cart/utils.pyindex 22b5e9e70b..5726fdf0bb 100644--- a/saleor/cart/utils.py+++ b/saleor/cart/utils.py@@ -62,13 +62,13 @@ def get_product_variants_and_prices(cart, product):def get_category_variants_and_prices(cart, discounted_category):products = {cart_line.variant.product for cart_line in cart.lines.all()}- discounted_products = []+ discounted_products = set()for product in products:for category in product.categories.all():is_descendant = category.is_descendant_of(discounted_category, include_self=True)if is_descendant:- discounted_products.append(product)+ discounted_products.add(product)for product in discounted_products:for line in get_product_variants_and_prices(cart, product):yield linediff --git a/tests/test_discounts.py b/tests/test_discounts.pyindex 3ae3fdb3e8..8b32d1906a 100644--- a/tests/test_discounts.py+++ b/tests/test_discounts.py@@ -6,8 +6,10 @@ from prices import FixedDiscount, FractionalDiscount, Pricefrom django_prices.templatetags.prices_i18n import net+from saleor.cart.utils import get_category_variants_and_pricesfrom saleor.discount.forms import CheckoutDiscountFormfrom saleor.discount.models import NotApplicable, Sale, Voucher+from saleor.product.models import Categoryfrom saleor.product.models import Product, ProductVariant@@ -246,3 +248,14 @@ def test_sale_applies_to_correct_products(product_class):net=5, currency='USD')with pytest.raises(NotApplicable):sale.modifier_for_product(sec_variant.product)+++def test_get_category_variants_and_prices_product_with_many_categories(cart, default_category, product_in_stock):+ category = Category.objects.create(name='Foobar', slug='foo', parent=default_category)+ product_in_stock.categories.add(category)+ variant = product_in_stock.variants.first()+ cart.add(variant, check_quantity=False)++ discounted_products = list(get_category_variants_and_prices(cart, default_category))+ assert len(discounted_products) == 1