Skip to content

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

Fix validating product without category (#7489)

Damian Wysocki142bbfb5f76a
diff --git a/saleor/graphql/product/mutations/channels.py b/saleor/graphql/product/mutations/channels.py
index 7067ff5969..37d8da3905 100644
--- a/saleor/graphql/product/mutations/channels.py
+++ b/saleor/graphql/product/mutations/channels.py
@@ -137,7 +137,11 @@ class ProductChannelListingUpdate(BaseChannelListingMutation):
def validate_product_without_category(cls, cleaned_input, errors: ErrorType):
channels_with_published_product_without_category = []
for update_channel in cleaned_input.get("update_channels", []):
- if update_channel.get("is_published") is True:
+ is_published = update_channel.get("is_published") is True
+ is_available_for_purchase = (
+ update_channel.get("is_available_for_purchase") is True
+ )
+ if is_published or is_available_for_purchase:
channels_with_published_product_without_category.append(
update_channel["channel_id"]
)
diff --git a/saleor/graphql/product/tests/test_product_channel_listing_update.py b/saleor/graphql/product/tests/test_product_channel_listing_update.py
index cb1076e3a1..7bc1e66ab5 100644
--- a/saleor/graphql/product/tests/test_product_channel_listing_update.py
+++ b/saleor/graphql/product/tests/test_product_channel_listing_update.py
@@ -1034,6 +1034,43 @@ def test_product_channel_listing_update_publish_product_without_category(
assert len(errors) == 1
+def test_product_channel_listing_update_available_for_purchase_product_without_category(
+ staff_api_client, product, permission_manage_products, channel_USD, channel_PLN
+):
+ # given
+ product.channel_listings.all().delete()
+ product.category = None
+ product.save()
+ product_id = graphene.Node.to_global_id("Product", product.pk)
+ channel_usd_id = graphene.Node.to_global_id("Channel", channel_USD.id)
+ channel_pln_id = graphene.Node.to_global_id("Channel", channel_PLN.id)
+ variables = {
+ "id": product_id,
+ "input": {
+ "updateChannels": [
+ {"channelId": channel_usd_id, "isAvailableForPurchase": True},
+ {"channelId": channel_pln_id, "isAvailableForPurchase": False},
+ ]
+ },
+ }
+
+ # when
+ response = staff_api_client.post_graphql(
+ PRODUCT_CHANNEL_LISTING_UPDATE_MUTATION,
+ variables=variables,
+ permissions=(permission_manage_products,),
+ )
+ content = get_graphql_content(response)
+
+ # then
+ data = content["data"]["productChannelListingUpdate"]
+ errors = data["errors"]
+ assert errors[0]["field"] == "isPublished"
+ assert errors[0]["code"] == ProductErrorCode.PRODUCT_WITHOUT_CATEGORY.name
+ assert errors[0]["channels"] == [channel_usd_id]
+ assert len(errors) == 1
+
+
def test_product_channel_listing_add_variant_as_staff_user(
staff_api_client, product, permission_manage_products, channel_USD
):