Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix prduct is published filter (#7676)
Filip Owczarek2b848cf8e474
diff --git a/saleor/graphql/product/filters.py b/saleor/graphql/product/filters.pyindex 51762e53b1..7ac3c2ef1e 100644--- a/saleor/graphql/product/filters.py+++ b/saleor/graphql/product/filters.py@@ -329,7 +329,20 @@ def _filter_products_is_published(qs, _, value, channel_slug):product_channel_listings = ProductChannelListing.objects.filter(Exists(channel.filter(pk=OuterRef("channel_id"))), is_published=value).values("product_id")- return qs.filter(Exists(product_channel_listings.filter(product_id=OuterRef("pk"))))++ # Filter out product for which there is no variant with price+ variant_channel_listings = ProductVariantChannelListing.objects.filter(+ Exists(channel.filter(pk=OuterRef("channel_id"))),+ price_amount__isnull=False,+ ).values("id")+ variants = ProductVariant.objects.filter(+ Exists(variant_channel_listings.filter(variant_id=OuterRef("pk")))+ ).values("product_id")++ return qs.filter(+ Exists(product_channel_listings.filter(product_id=OuterRef("pk"))),+ Exists(variants.filter(product_id=OuterRef("pk"))),+ )def _filter_variant_price(qs, _, value, channel_slug):diff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.pyindex ecd83ebecd..4d85d2ce83 100644--- a/saleor/graphql/product/tests/test_product.py+++ b/saleor/graphql/product/tests/test_product.py@@ -2215,6 +2215,52 @@ def test_products_query_with_filter_search_by_sku(assert products[0]["node"]["name"] == product_with_default_variant.name+def test_products_query_with_is_published_filter_variants_without_prices(+ query_products_with_filter,+ staff_api_client,+ variant,+ permission_manage_products,+ channel_USD,+):+ ProductVariantChannelListing.objects.filter(+ variant__product=variant.product+ ).update(price_amount=None)++ variables = {"channel": channel_USD.slug, "filter": {"isPublished": True}}+ response = staff_api_client.post_graphql(+ query_products_with_filter,+ variables,+ permissions=[permission_manage_products],+ check_no_permissions=False,+ )+ content = get_graphql_content(response)+ products = content["data"]["products"]["edges"]++ assert len(products) == 0+++def test_products_query_with_is_published_filter_one_variant_without_price(+ query_products_with_filter,+ staff_api_client,+ variant,+ permission_manage_products,+ channel_USD,+):+ variant.channel_listings.update(price_amount=None)++ variables = {"channel": channel_USD.slug, "filter": {"isPublished": True}}+ response = staff_api_client.post_graphql(+ query_products_with_filter,+ variables,+ permissions=[permission_manage_products],+ check_no_permissions=False,+ )+ content = get_graphql_content(response)+ products = content["data"]["products"]["edges"]++ assert len(products) == 1++def test_products_query_with_filter_stock_availability_as_staff(query_products_with_filter,staff_api_client,