Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Merge pull request #2062 from mirumee/1927_product_type_endpoints
Marcin Gębalab624d9f2ec6a
diff --cc saleor/graphql/product/types.pyindex f0fcfbcda4,d102582025..831f2b04be--- a/saleor/graphql/product/types.py+++ b/saleor/graphql/product/types.py@@@ -149,23 -154,12 +154,28 @@@ class ProductType(CountableDjangoObjectinterfaces = [relay.Node]model = models.ProductType+ def resolve_products(self, info):+ user = info.context.user+ return products_visible_to_user(+ user=user).filter(product_type=self).distinct()++class Collection(CountableDjangoObjectType):+ products = DjangoFilterConnectionField(+ Product, filterset_class=ProductFilterSet,+ description='List of collection products.')++ class Meta:+ description = "Represents a collection of products."+ interfaces = [relay.Node]+ model = models.Collection++ def resolve_products(self, info, **kwargs):+ user = info.context.user+ return products_visible_to_user(+ user=user).filter(collections=self).distinct()++class Category(CountableDjangoObjectType):products = DjangoFilterConnectionField(Product, filterset_class=ProductFilterSet,diff --cc tests/test_graphql.pyindex 02b4985d6a,824ec9d743..ebd128ce3c--- a/tests/test_graphql.py+++ b/tests/test_graphql.py@@@ -195,40 -185,8 +185,36 @@@ def test_product_query(admin_client, pr'purchaseCost']['stop']['gross']['amount']assert gross_margin[0] == product_data['grossMargin'][0]['start']assert gross_margin[1] == product_data['grossMargin'][0]['stop']- assert price_range.start.gross.amount == product_data[- 'priceRange']['start']['gross']['amount']- assert price_range.stop.gross.amount == product_data[- 'priceRange']['stop']['gross']['amount']+def test_product_with_collections(admin_client, product, collection):+ query = '''+ query getProduct($productID: ID!) {+ product(id: $productID) {+ collections(first: 1) {+ edges {+ node {+ name+ }+ }+ }+ }+ }+ '''+ product.collections.add(collection)+ product.save()+ product_id = graphene.Node.to_global_id('Product', product.id)++ variables = json.dumps({'productID': product_id})+ response = admin_client.post(+ reverse('api'), {'query': query, 'variables': variables})+ content = get_graphql_content(response)+ assert 'errors' not in content+ data = content['data']['product']+ assert data['collections']['edges'][0]['node']['name'] == collection.name+ assert len(data['collections']['edges']) == 1++def test_filter_product_by_category(client, product):category = product.categoryquery = '''