Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix fetching variants for default channel by not authenticated user

IKarbowiak03c5a9916858
diff --git a/saleor/graphql/menu/tests/deprecated/test_menu.py b/saleor/graphql/menu/tests/deprecated/test_menu.py
index 6f491cfa6b..5bb4ef20a3 100644
--- a/saleor/graphql/menu/tests/deprecated/test_menu.py
+++ b/saleor/graphql/menu/tests/deprecated/test_menu.py
@@ -26,6 +26,9 @@ def test_menu_items_collection_without_providing_channel(
page {
id
}
+ menu {
+ id
+ }
url
}
}
diff --git a/saleor/graphql/product/tests/deprecated/test_product.py b/saleor/graphql/product/tests/deprecated/test_product.py
index ffb4b95aa4..73767fc9ef 100644
--- a/saleor/graphql/product/tests/deprecated/test_product.py
+++ b/saleor/graphql/product/tests/deprecated/test_product.py
@@ -28,6 +28,9 @@ QUERY_FETCH_ALL_PRODUCTS = """
isAvailable
availableForPurchase
isAvailableForPurchase
+ variants{
+ id
+ }
}
}
}
@@ -146,3 +149,46 @@ def test_get_collections_from_product_as_anonymous(
assert any(
[str(warning.message) == DEPRECATION_WARNING_MESSAGE for warning in warns]
)
+
+
+QUERY_FETCH_ALL_VARIANTS = """
+ query fetchAllVariants {
+ productVariants(first: 10) {
+ totalCount
+ edges {
+ node {
+ id
+ trackInventory
+ quantityAvailable
+ sku
+ pricing {
+ price {
+ net {
+ amount
+ }
+ gross {
+ amount
+ }
+ }
+ }
+ product {
+ id
+ }
+ }
+ }
+ }
+ }
+"""
+
+
+def test_fetch_all_variants(api_client, product_variant_list, channel_PLN):
+ channel_PLN.delete()
+ with warnings.catch_warnings(record=True) as warns:
+ response = api_client.post_graphql(QUERY_FETCH_ALL_VARIANTS)
+
+ content = get_graphql_content(response)
+ data = content["data"]["productVariants"]
+ assert data["totalCount"] == len(product_variant_list)
+ assert any(
+ [str(warning.message) == DEPRECATION_WARNING_MESSAGE for warning in warns]
+ )
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index 0927691f73..302696685b 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -297,7 +297,7 @@ class ProductVariant(ChannelContextTypeWithMetadata, CountableDjangoObjectType):
return AvailableQuantityByProductVariantIdCountryCodeAndChannelSlugLoader(
info.context
- ).load((root.node.id, country_code, root.channel_slug))
+ ).load((root.node.id, country_code, str(root.channel_slug)))
@staticmethod
@permission_required(ProductPermissions.MANAGE_PRODUCTS)
diff --git a/saleor/product/models.py b/saleor/product/models.py
index fa8c468952..4b036a741f 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -446,7 +446,7 @@ class ProductVariantQueryset(models.QuerySet):
def available_in_channel(self, channel_slug):
return self.filter(
channel_listings__price_amount__isnull=False,
- channel_listings__channel__slug=channel_slug,
+ channel_listings__channel__slug=str(channel_slug),
)
def prefetched_for_webhook(self):