Skip to content

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

Add manual filtering and sorting; fix bugs detected by tests

Marcin Gębalacb30d9784a53
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index 4c4df87711..d4213bd5ee 100644
--- a/saleor/graphql/order/types.py
+++ b/saleor/graphql/order/types.py
@@ -107,6 +107,35 @@ class FulfillmentLine(CountableDjangoObjectType):
return self.order_line
+class OrderLine(CountableDjangoObjectType):
+ thumbnail_url = graphene.String(
+ description='The URL of a main thumbnail for the ordered product.',
+ size=graphene.Int(description='Size of the image'))
+ unit_price = graphene.Field(
+ TaxedMoney, description='Price of the single item in the order line.')
+
+ class Meta:
+ description = 'Represents order line of particular order.'
+ model = models.OrderLine
+ interfaces = [relay.Node]
+ exclude_fields = [
+ 'order', 'unit_price_gross', 'unit_price_net', 'variant']
+
+ @gql_optimizer.resolver_hints(
+ prefetch_related=['variant__images', 'variant__product__images'])
+ def resolve_thumbnail_url(self, info, size=None):
+ if not self.variant_id:
+ return None
+ if not size:
+ size = 255
+ return get_thumbnail(
+ self.variant.get_first_image(), size, method='thumbnail')
+
+ @staticmethod
+ def resolve_unit_price(obj, info):
+ return obj.unit_price
+
+
class Order(CountableDjangoObjectType):
fulfillments = gql_optimizer.field(
graphene.List(
@@ -241,32 +270,3 @@ class Order(CountableDjangoObjectType):
@staticmethod
def resolve_lines(obj, info):
return obj.lines.all()
-
-
-class OrderLine(CountableDjangoObjectType):
- thumbnail_url = graphene.String(
- description='The URL of a main thumbnail for the ordered product.',
- size=graphene.Int(description='Size of the image'))
- unit_price = graphene.Field(
- TaxedMoney, description='Price of the single item in the order line.')
-
- class Meta:
- description = 'Represents order line of particular order.'
- model = models.OrderLine
- interfaces = [relay.Node]
- exclude_fields = [
- 'order', 'unit_price_gross', 'unit_price_net', 'variant']
-
- @gql_optimizer.resolver_hints(
- prefetch_related=['variant__images', 'variant__product__images'])
- def resolve_thumbnail_url(self, info, size=None):
- if not self.variant_id:
- return None
- if not size:
- size = 255
- return get_thumbnail(
- self.variant.get_first_image(), size, method='thumbnail')
-
- @staticmethod
- def resolve_unit_price(obj, info):
- return obj.unit_price
diff --git a/saleor/graphql/product/fields.py b/saleor/graphql/product/fields.py
deleted file mode 100644
index abfe0c55cf..0000000000
--- a/saleor/graphql/product/fields.py
+++ /dev/null
@@ -1,14 +0,0 @@
-import graphene
-from django import forms
-from graphene_django.forms.converter import convert_form_field
-
-from .scalars import AttributeScalar
-
-
-class AttributeField(forms.Field):
- pass
-
-
-@convert_form_field.register(AttributeField)
-def convert_form_field_to_list(field):
- return graphene.List(AttributeScalar)
diff --git a/saleor/graphql/product/filters.py b/saleor/graphql/product/filters.py
index 36733a6232..ea760d1086 100644
--- a/saleor/graphql/product/filters.py
+++ b/saleor/graphql/product/filters.py
@@ -3,73 +3,47 @@ import operator
from collections import defaultdict
from django.db.models import Q
-from django_filters import OrderingFilter
-from django_filters.fields import Lookup
-from graphene_django.filter.filterset import Filter, FilterSet
-from ...product.filters import SORT_BY_FIELDS
-from ...product.models import Attribute, Product
-from .fields import AttributeField
-
-
-class AttributeFilter(Filter):
- field_class = AttributeField
-
- def filter(self, qs, value):
- if isinstance(value, Lookup):
- value = value.value
-
- if not value:
- return qs.distinct() if self.distinct else qs
-
- attributes = Attribute.objects.prefetch_related('values')
- attributes_map = {
- attribute.slug: attribute.pk for attribute in attributes}
- values_map = {
- attr.slug: {value.slug: value.pk for value in attr.values.all()}
- for attr in attributes}
- queries = defaultdict(list)
- # Convert attribute:value pairs into a dictionary where
- # attributes are keys and values are grouped in lists
- for attr_name, val_slug in value:
- if attr_name not in attributes_map:
- raise ValueError('Unknown attribute name: %r' % (attr_name, ))
- attr_pk = attributes_map[attr_name]
- attr_val_pk = values_map[attr_name].get(val_slug, val_slug)
- queries[attr_pk].append(attr_val_pk)
- # Combine filters of the same attribute with OR operator
- # and then combine full query with AND operator.
- combine_and = [
- functools.reduce(
- operator.or_, [
- Q(**{'variants__attributes__%s' % (key, ): v}) |
- Q(**{'attributes__%s' % (key, ): v}) for v in values])
- for key, values in queries.items()]
- query = functools.reduce(operator.and_, combine_and)
- qs = self.get_method(qs)(query)
- return qs.distinct() if self.distinct else qs
-
-
-class ProductFilterSet(FilterSet):
- sort_by = OrderingFilter(
- fields=SORT_BY_FIELDS.keys(), field_labels=SORT_BY_FIELDS)
-
- class Meta:
- model = Product
- fields = {
- 'category': ['exact'],
- 'price': ['exact', 'range', 'lte', 'gte'],
- 'attributes': ['exact'],
- 'name': ['exact', 'icontains'],
- 'product_type__name': ['exact'],
- 'is_published': ['exact']}
-
- @classmethod
- def filter_for_field(cls, f, field_name, lookup_expr='exact'):
- if field_name == 'attributes':
- return AttributeFilter(
- field_name=field_name, lookup_expr=lookup_expr, distinct=True)
- # this class method is called during class construction so we can't
- # reference ProductFilterSet here yet
- return FilterSet.filter_for_field(
- f, field_name, lookup_expr)
+from ...product.models import Attribute
+
+
+def filter_products_by_attributes(qs, filter_value):
+ attributes = Attribute.objects.prefetch_related('values')
+ attributes_map = {
+ attribute.slug: attribute.pk for attribute in attributes}
+ values_map = {
+ attr.slug: {value.slug: value.pk for value in attr.values.all()}
+ for attr in attributes}
+ queries = defaultdict(list)
+ # Convert attribute:value pairs into a dictionary where
+ # attributes are keys and values are grouped in lists
+ for attr_name, val_slug in filter_value:
+ if attr_name not in attributes_map:
+ raise ValueError('Unknown attribute name: %r' % (attr_name, ))
+ attr_pk = attributes_map[attr_name]
+ attr_val_pk = values_map[attr_name].get(val_slug, val_slug)
+ queries[attr_pk].append(attr_val_pk)
+ # Combine filters of the same attribute with OR operator
+ # and then combine full query with AND operator.
+ combine_and = [
+ functools.reduce(
+ operator.or_, [
+ Q(**{'variants__attributes__%s' % (key, ): v}) |
+ Q(**{'attributes__%s' % (key, ): v}) for v in values])
+ for key, values in queries.items()]
+ query = functools.reduce(operator.and_, combine_and)
+ return qs.filter(query).distinct()
+
+
+def filter_products_by_price(qs, price_lte=None, price_gte=None):
+ if price_lte:
+ qs = qs.filter(price__lte=price_lte)
+ if price_gte:
+ qs = qs.filter(price__gte=price_gte)
+ return qs
+
+
+def sort_qs(qs, sort_by):
+ if sort_by:
+ qs = qs.order_by(sort_by)
+ return qs
diff --git a/saleor/graphql/product/resolvers.py b/saleor/graphql/product/resolvers.py
index 05afdba8bd..40ee662ad4 100644
--- a/saleor/graphql/product/resolvers.py
+++ b/saleor/graphql/product/resolvers.py
@@ -5,6 +5,8 @@ from django.db.models import Sum, Q
from ...order import OrderStatus
from ...product import models
from ..utils import filter_by_query_param, filter_by_period, get_database_id
+from .filters import (
+ filter_products_by_attributes, filter_products_by_price, sort_qs)
from .types import Category, ProductVariant, StockAvailability
PRODUCT_SEARCH_FIELDS = ('name', 'description', 'category__name')
@@ -28,9 +30,10 @@ def resolve_attributes(info, category_id, query):
obj[0]
for obj in models.Product.objects.filter(
category__in=tree).values_list('product_type_id')}
- queryset = queryset.filter(
+ qs = qs.filter(
Q(product_type__in=product_types)
| Q(product_variant_type__in=product_types))
+ qs = qs.distinct()
return gql_optimizer.query(qs, info)
@@ -49,14 +52,19 @@ def resolve_collections(info, query):
return gql_optimizer.query(qs, info)
-def resolve_products(info, category_id, stock_availability, query):
+def resolve_products(
+ info, attributes=None, category=None, stock_availability=None,
+ query=None, price_lte=None, price_gte=None, sort_by=None):
user = info.context.user
qs = models.Product.objects.visible_to_user(user)
qs = filter_by_query_param(qs, query, PRODUCT_SEARCH_FIELDS)
- if category_id is not None:
+ if attributes:
+ qs = filter_products_by_attributes(qs, attributes)
+
+ if category is not None:
category = graphene.Node.get_node_from_global_id(
- info, category_id, Category)
+ info, category, Category)
if not category:
return qs.none()
qs = qs.filter(category=category)
@@ -68,7 +76,8 @@ def resolve_products(info, category_id, stock_availability, query):
elif stock_availability == StockAvailability.OUT_OF_STOCK:
qs = qs.filter(total_quantity__lte=0)
- qs = qs.distinct()
+ qs = filter_products_by_price(qs, price_lte, price_gte)
+ qs = sort_qs(qs, sort_by)
return gql_optimizer.query(qs, info)
@@ -78,7 +87,7 @@ def resolve_product_types(info):
def resolve_product_variants(info, ids=None):
- # fixme: add visible_to_user for variants
+ # FIXME: add visible_to_user for variants
qs = models.ProductVariant.objects.all()
if ids:
db_ids = [
diff --git a/saleor/graphql/product/schema.py b/saleor/graphql/product/schema.py
index b549870783..ee49d15e10 100644
--- a/saleor/graphql/product/schema.py
+++ b/saleor/graphql/product/schema.py
@@ -1,10 +1,9 @@
import graphene
-from graphene_django.filter import DjangoFilterConnectionField
from graphql_jwt.decorators import permission_required
from ..descriptions import DESCRIPTIONS
+from ..core.fields import PrefetchingConnectionField
from ..core.types import ReportingPeriod
-from .filters import ProductFilterSet
from .mutations.attributes import (
AttributeValueCreate, AttributeValueDelete,
AttributeValueUpdate, AttributeCreate, AttributeDelete,
@@ -23,17 +22,17 @@ from .resolvers import (
resolve_products, resolve_product_types, resolve_product_variants,
resolve_report_product_sales)
from .types import (
- Category, Collection, Product, Attribute, ProductType,
+ Category, Collection, Product, Attribute, AttributeScalar, ProductType,
ProductVariant, StockAvailability)
class ProductQueries(graphene.ObjectType):
- attributes = DjangoFilterConnectionField(
+ attributes = PrefetchingConnectionField(
Attribute,
query=graphene.String(description=DESCRIPTIONS['attributes']),
in_category=graphene.Argument(graphene.ID),
description='List of the shop\'s attributes.')
- categories = DjangoFilterConnectionField(
+ categories = PrefetchingConnectionField(
Category, query=graphene.String(
description=DESCRIPTIONS['category']),
level=graphene.Argument(graphene.Int),
@@ -44,15 +43,23 @@ class ProductQueries(graphene.ObjectType):
collection = graphene.Field(
Collection, id=graphene.Argument(graphene.ID),
description='Lookup a collection by ID.')
- collections = DjangoFilterConnectionField(
+ collections = PrefetchingConnectionField(
Collection, query=graphene.String(
description=DESCRIPTIONS['collection']),
description='List of the shop\'s collections.')
product = graphene.Field(
Product, id=graphene.Argument(graphene.ID),
description='Lookup a product by ID.')
- products = DjangoFilterConnectionField(
- Product, filterset_class=ProductFilterSet,
+ products = PrefetchingConnectionField(
+ Product,
+ attributes=graphene.List(
+ AttributeScalar, description='Filter products by attributes.'),
+ category=graphene.ID(description='Filter products by category.'),
+ price_lte=graphene.Float(
+ description='Filter by price less than or equal to the given value.'),
+ price_gte=graphene.Float(
+ description='Filter by price greater than or equal to the given value.'),
+ sort_by=graphene.String(description='Sort products.'),
query=graphene.String(description=DESCRIPTIONS['product']),
stock_availability=graphene.Argument(
StockAvailability,
@@ -61,15 +68,15 @@ class ProductQueries(graphene.ObjectType):
product_type = graphene.Field(
ProductType, id=graphene.Argument(graphene.ID),
description='Lookup a product type by ID.')
- product_types = DjangoFilterConnectionField(
+ product_types = PrefetchingConnectionField(
ProductType, description='List of the shop\'s product types.')
product_variant = graphene.Field(
ProductVariant, id=graphene.Argument(graphene.ID),
description='Lookup a variant by ID.')
- product_variants = DjangoFilterConnectionField(
+ product_variants = PrefetchingConnectionField(
ProductVariant, ids=graphene.List(graphene.ID),
description='Lookup multiple variants by ID')
- report_product_sales = DjangoFilterConnectionField(
+ report_product_sales = PrefetchingConnectionField(
ProductVariant,
period=graphene.Argument(
ReportingPeriod, required=True, description='Span of time.'),
@@ -94,15 +101,17 @@ class ProductQueries(graphene.ObjectType):
return graphene.Node.get_node_from_global_id(info, id, Product)
def resolve_products(
- self, info, category_id=None, stock_availability=None, query=None,
- **kwargs):
- return resolve_products(info, category_id, stock_availability, query)
+ self, info, attributes=None, category=None, stock_availability=None,
+ query=None, price_lte=None, price_gte=None, sort_by=None, **kwargs):
+ return resolve_products(
+ info, attributes, category, stock_availability, query,
+ price_lte, price_gte, sort_by)
def resolve_product_type(self, info, id):
return graphene.Node.get_node_from_global_id(info, id, ProductType)
def resolve_product_types(self, info, **kwargs):
- return resolve_product_types()
+ return resolve_product_types(info)
def resolve_product_variant(self, info, id):
return graphene.Node.get_node_from_global_id(info, id, ProductVariant)
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
index 9afd87778c..d95ccece7b 100644
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -18,8 +18,10 @@ from ..core.types import (
CountableDjangoObjectType, Money, MoneyRange, ReportingPeriod, TaxedMoney,
TaxedMoneyRange, TaxRateType)
from ..utils import get_database_id, reporting_period_to_date
+from .filters import (
+ filter_products_by_attributes, filter_products_by_price, sort_qs)
from .descriptions import AttributeDescriptions, AttributeValueDescriptions
-
+from .scalars import AttributeScalar
COLOR_PATTERN = r'^(#[0-9a-fA-F]{3}|#(?:[0-9a-fA-F]{2}){2,4}|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d\.]+%?\))$' # noqa
color_pattern = re.compile(COLOR_PATTERN)
@@ -340,7 +342,10 @@ class ProductType(CountableDjangoObjectType):
return self.variant_attributes.all()
def resolve_products(self, info, **kwargs):
- return self.prefetched_products
+ if hasattr(self, 'prefetched_products'):
+ return self.prefetched_products
+ qs = self.products.visible_to_user(info.context.user)
+ return gql_optimizer.query(qs, info)
def resolve_variant_attributes(self, info):
return self.variant_attributes.prefetch_related('values')
@@ -352,7 +357,15 @@ class ProductType(CountableDjangoObjectType):
class Collection(CountableDjangoObjectType):
products = gql_optimizer.field(
PrefetchingConnectionField(
- Product, description='List of collection products.'),
+ Product,
+ attributes=graphene.List(
+ AttributeScalar, description='Filter products by attributes.'),
+ price_lte=graphene.Float(
+ description='Filter by price less than or equal to the given value.'),
+ price_gte=graphene.Float(
+ description='Filter by price greater than or equal to the given value.'),
+ sort_by=graphene.String(description='Sort products.'),
+ description='List of collection products.'),
prefetch_related=prefetch_products)
background_image = graphene.Field(Image)
@@ -365,14 +378,34 @@ class Collection(CountableDjangoObjectType):
def resolve_background_image(self, info, **kwargs):
return self.background_image or None
- def resolve_products(self, info, **kwargs):
- return self.prefetched_products
+ def resolve_products(
+ self, info, attributes=None, price_lte=None, price_gte=None,
+ sort_by=None, **kwargs):
+
+ # FIXME: Fix prefetching products
+ # if hasattr(self, 'prefetched_products'):
+ # return self.prefetched_products
+
+ qs = self.products.visible_to_user(info.context.user)
+ qs = filter_products_by_price(qs, price_lte, price_gte)
+ if attributes:
+ qs = filter_products_by_attributes(qs, attributes)
+ qs = sort_qs(qs, sort_by)
+ return gql_optimizer.query(qs, info)
class Category(CountableDjangoObjectType):
products = gql_optimizer.field(
PrefetchingConnectionField(
- Product, description='List of products in the category.'),
+ Product,
+ attributes=graphene.List(
+ AttributeScalar, description='Filter products by attributes.'),
+ price_lte=graphene.Float(
+ description='Filter by price less than or equal to the given value.'),
+ price_gte=graphene.Float(
+ description='Filter by price greater than or equal to the given value.'),
+ sort_by=graphene.String(description='Sort products.'),
+ description='List of products in the category.'),
prefetch_related=prefetch_products)
url = graphene.String(
description='The storefront\'s URL for the category.')
@@ -408,8 +441,20 @@ class Category(CountableDjangoObjectType):
def resolve_url(self, info):
return self.get_absolute_url()
- def resolve_products(self, info, **kwargs):
- return self.prefetched_products
+ def resolve_products(
+ self, info, attributes=None, price_lte=None, price_gte=None,
+ sort_by=None, **kwargs):
+
+ # FIXME: Fix prefetching products
+ # if hasattr(self, 'prefetched_products'):
+ # return self.prefetched_products
+
+ qs = self.products.visible_to_user(info.context.user)
+ qs = filter_products_by_price(qs, price_lte, price_gte)
+ if attributes:
+ qs = filter_products_by_attributes(qs, attributes)
+ qs = sort_qs(qs, sort_by)
+ return gql_optimizer.query(qs, info)
class ProductImage(CountableDjangoObjectType):
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index bb6477481b..b0e4c6cfc1 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -239,10 +239,10 @@ type Category implements Node {
parent: Category
backgroundImage: Image
level: Int!
- children(before: String, after: String, first: Int, last: Int, id: ID, name: String): CategoryCountableConnection
- products(before: String, after: String, first: Int, last: Int, category: ID, price: Float, price_Range: Float, price_Lte: Float, price_Gte: Float, attributes: [AttributeScalar], name: String, name_Icontains: String, productType_Name: String, isPublished: Boolean, sortBy: String): ProductCountableConnection
+ children(before: String, after: String, first: Int, last: Int): CategoryCountableConnection
+ products(attributes: [AttributeScalar], priceLte: Float, priceGte: Float, sortBy: String, before: String, after: String, first: Int, last: Int): ProductCountableConnection
url: String
- ancestors(before: String, after: String, first: Int, last: Int, id: ID, name: String): CategoryCountableConnection
+ ancestors(before: String, after: String, first: Int, last: Int): CategoryCountableConnection
}
type CategoryCountableConnection {
@@ -290,7 +290,7 @@ type Collection implements Node {
id: ID!
name: String!
slug: String!
- products(before: String, after: String, first: Int, last: Int, category: ID, price: Float, price_Range: Float, price_Lte: Float, price_Gte: Float, attributes: [AttributeScalar], name: String, name_Icontains: String, productType_Name: String, isPublished: Boolean, sortBy: String): ProductCountableConnection
+ products(attributes: [AttributeScalar], priceLte: Float, priceGte: Float, sortBy: String, before: String, after: String, first: Int, last: Int): ProductCountableConnection
backgroundImage: Image
isPublished: Boolean!
}
@@ -509,7 +509,7 @@ input FulfillmentCreateInput {
type FulfillmentLine implements Node {
id: ID!
- orderLine: OrderLine!
+ orderLine: OrderLine
quantity: Int!
}
@@ -573,7 +573,8 @@ type Margin {
type Menu implements Node {
id: ID!
name: String!
- items: [MenuItem]!
+ items: [MenuItem]
+ children: [MenuItem]!
}
type MenuCountableConnection {
@@ -616,7 +617,7 @@ type MenuItem implements Node {
collection: Collection
page: Page
level: Int!
- children: [MenuItem]!
+ children: [MenuItem]
}
type MenuItemCountableConnection {
@@ -1087,11 +1088,11 @@ type Product implements Node {
chargeTaxes: Boolean!
taxRate: String!
weight: Weight
- voucherSet(before: String, after: String, first: Int, last: Int, name_Icontains: String, type: String, discountValue_Gte: Float, discountValue_Lte: Float, startDate: Date, endDate: Date, minAmountSpent_Gte: Float, minAmountSpent_Lte: Float): VoucherCountableConnection
- saleSet(before: String, after: String, first: Int, last: Int, name_Icontains: String, type_Icontains: String, value_Gte: Float, value_Lte: Float, startDate: Date, endDate: Date): SaleCountableConnection
- variants(before: String, after: String, first: Int, last: Int, id: ID): ProductVariantCountableConnection
+ voucherSet(before: String, after: String, first: Int, last: Int): VoucherCountableConnection
+ saleSet(before: String, after: String, first: Int, last: Int): SaleCountableConnection
+ variants(before: String, after: String, first: Int, last: Int): ProductVariantCountableConnection
images(before: String, after: String, first: Int, last: Int): ProductImageCountableConnection
- collections(before: String, after: String, first: Int, last: Int, name: String, name_Icontains: String, name_Istartswith: String): CollectionCountableConnection
+ collections(before: String, after: String, first: Int, last: Int): CollectionCountableConnection
url: String!
thumbnailUrl(size: Int): String
availability: ProductAvailability
@@ -1221,7 +1222,7 @@ type ProductType implements Node {
isShippingRequired: Boolean!
taxRate: TaxRateType
weight: Weight
- products(before: String, after: String, first: Int, last: Int, category: ID, price: Float, price_Range: Float, price_Lte: Float, price_Gte: Float, attributes: [AttributeScalar], name: String, name_Icontains: String, productType_Name: String, isPublished: Boolean, sortBy: String): ProductCountableConnection
+ products(before: String, after: String, first: Int, last: Int): ProductCountableConnection
productAttributes: [Attribute]
variantAttributes: [Attribute]
}
@@ -1336,18 +1337,18 @@ type ProductVariantUpdate {
}
type Query {
- attributes(query: String, inCategory: ID, before: String, after: String, first: Int, last: Int, id: ID, slug: String): AttributeCountableConnection
- categories(query: String, level: Int, before: String, after: String, first: Int, last: Int, id: ID, name: String): CategoryCountableConnection
+ attributes(query: String, inCategory: ID, before: String, after: String, first: Int, last: Int): AttributeCountableConnection
+ categories(query: String, level: Int, before: String, after: String, first: Int, last: Int): CategoryCountableConnection
category(id: ID): Category
collection(id: ID): Collection
- collections(query: String, before: String, after: String, first: Int, last: Int, name: String, name_Icontains: String, name_Istartswith: String): CollectionCountableConnection
+ collections(query: String, before: String, after: String, first: Int, last: Int): CollectionCountableConnection
product(id: ID): Product
- products(query: String, stockAvailability: StockAvailability, before: String, after: String, first: Int, last: Int, category: ID, price: Float, price_Range: Float, price_Lte: Float, price_Gte: Float, attributes: [AttributeScalar], name: String, name_Icontains: String, productType_Name: String, isPublished: Boolean, sortBy: String): ProductCountableConnection
+ products(attributes: [AttributeScalar], category: ID, priceLte: Float, priceGte: Float, sortBy: String, query: String, stockAvailability: StockAvailability, before: String, after: String, first: Int, last: Int): ProductCountableConnection
productType(id: ID): ProductType
- productTypes(before: String, after: String, first: Int, last: Int, id: ID): ProductTypeCountableConnection
+ productTypes(before: String, after: String, first: Int, last: Int): ProductTypeCountableConnection
productVariant(id: ID): ProductVariant
- productVariants(ids: [ID], before: String, after: String, first: Int, last: Int, id: ID): ProductVariantCountableConnection
- reportProductSales(period: ReportingPeriod!, before: String, after: String, first: Int, last: Int, id: ID): ProductVariantCountableConnection
+ productVariants(ids: [ID], before: String, after: String, first: Int, last: Int): ProductVariantCountableConnection
+ reportProductSales(period: ReportingPeriod!, before: String, after: String, first: Int, last: Int): ProductVariantCountableConnection
addressValidator(input: AddressValidationInput!): AddressValidationData
menu(id: ID, name: String): Menu
menus(query: String, before: String, after: String, first: Int, last: Int): MenuCountableConnection
@@ -1358,17 +1359,17 @@ type Query {
orders(query: String, created: ReportingPeriod, status: OrderStatusFilter, before: String, after: String, first: Int, last: Int): OrderCountableConnection
homepageEvents(before: String, after: String, first: Int, last: Int): OrderEventCountableConnection
page(id: ID, slug: String): Page
- pages(query: String, before: String, after: String, first: Int, last: Int, id: ID, title: String): PageCountableConnection
+ pages(query: String, before: String, after: String, first: Int, last: Int): PageCountableConnection
sale(id: ID): Sale
- sales(query: String, before: String, after: String, first: Int, last: Int, name_Icontains: String, type_Icontains: String, value_Gte: Float, value_Lte: Float, startDate: Date, endDate: Date): SaleCountableConnection
+ sales(query: String, before: String, after: String, first: Int, last: Int): SaleCountableConnection
shop: Shop
voucher(id: ID): Voucher
- vouchers(query: String, before: String, after: String, first: Int, last: Int, name_Icontains: String, type: String, discountValue_Gte: Float, discountValue_Lte: Float, startDate: Date, endDate: Date, minAmountSpent_Gte: Float, minAmountSpent_Lte: Float): VoucherCountableConnection
+ vouchers(query: String, before: String, after: String, first: Int, last: Int): VoucherCountableConnection
shippingZone(id: ID): ShippingZone
- shippingZones(before: String, after: String, first: Int, last: Int, name_Icontains: String, countries_Icontains: String, shippingMethods_Price_Gte: Float, shippingMethods_Price_Lte: Float): ShippingZoneCountableConnection
+ shippingZones(before: String, after: String, first: Int, last: Int): ShippingZoneCountableConnection
user(id: ID): User
- customers(query: String, before: String, after: String, first: Int, last: Int, isStaff: Boolean): UserCountableConnection
- staffUsers(query: String, before: String, after: String, first: Int, last: Int, isStaff: Boolean): UserCountableConnection
+ customers(query: String, before: String, after: String, first: Int, last: Int): UserCountableConnection
+ staffUsers(query: String, before: String, after: String, first: Int, last: Int): UserCountableConnection
node(id: ID!): Node
}
@@ -1388,8 +1389,8 @@ type Sale implements Node {
type: SaleType!
value: Float!
products(before: String, after: String, first: Int, last: Int): ProductCountableConnection
- categories(before: String, after: String, first: Int, last: Int, id: ID, name: String): CategoryCountableConnection
- collections(before: String, after: String, first: Int, last: Int, name: String, name_Icontains: String, name_Istartswith: String): CollectionCountableConnection
+ categories(before: String, after: String, first: Int, last: Int): CategoryCountableConnection
+ collections(before: String, after: String, first: Int, last: Int): CollectionCountableConnection
startDate: Date!
endDate: Date
}
@@ -1728,8 +1729,8 @@ type Voucher implements Node {
countries: VoucherCountries!
minAmountSpent: Money
products(before: String, after: String, first: Int, last: Int): ProductCountableConnection
- collections(before: String, after: String, first: Int, last: Int, name: String, name_Icontains: String, name_Istartswith: String): CollectionCountableConnection
- categories(before: String, after: String, first: Int, last: Int, id: ID, name: String): CategoryCountableConnection
+ collections(before: String, after: String, first: Int, last: Int): CollectionCountableConnection
+ categories(before: String, after: String, first: Int, last: Int): CategoryCountableConnection
}
type VoucherCountableConnection {
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 27e0275af2..47887c9f63 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -106,8 +106,7 @@ class ProductQuerySet(models.QuerySet):
def visible_to_user(self, user):
has_access_to_all = (
- user.is_authenticated and user.is_active and
- user.has_perm('products.manage_products'))
+ user.is_active and user.has_perm('product.manage_products'))
if has_access_to_all:
return self.all()
return self.available_products()
@@ -438,8 +437,7 @@ class CollectionQuerySet(models.QuerySet):
def visible_to_user(self, user):
has_access_to_all = (
- user.is_authenticated and user.is_active and
- user.has_perm('products.manage_products'))
+ user.is_active and user.has_perm('product.manage_products'))
if has_access_to_all:
return self.all()
return self.public()
diff --git a/saleor/static/dashboard-next/orders/types/OrderCancel.ts b/saleor/static/dashboard-next/orders/types/OrderCancel.ts
index cc67f2b9be..42271dac3e 100644
--- a/saleor/static/dashboard-next/orders/types/OrderCancel.ts
+++ b/saleor/static/dashboard-next/orders/types/OrderCancel.ts
@@ -79,8 +79,8 @@ export interface OrderCancel_orderCancel_order_fulfillments_lines_edges_node_ord
export interface OrderCancel_orderCancel_order_fulfillments_lines_edges_node {
__typename: "FulfillmentLine";
id: string;
+ orderLine: OrderCancel_orderCancel_order_fulfillments_lines_edges_node_orderLine | null;
quantity: number;
- orderLine: OrderCancel_orderCancel_order_fulfillments_lines_edges_node_orderLine;
}
export interface OrderCancel_orderCancel_order_fulfillments_lines_edges {
diff --git a/saleor/static/dashboard-next/orders/types/OrderCapture.ts b/saleor/static/dashboard-next/orders/types/OrderCapture.ts
index 75dd96d82f..c43784be65 100644
--- a/saleor/static/dashboard-next/orders/types/OrderCapture.ts
+++ b/saleor/static/dashboard-next/orders/types/OrderCapture.ts
@@ -85,8 +85,8 @@ export interface OrderCapture_orderCapture_order_fulfillments_lines_edges_node_o
export interface OrderCapture_orderCapture_order_fulfillments_lines_edges_node {
__typename: "FulfillmentLine";
id: string;
+ orderLine: OrderCapture_orderCapture_order_fulfillments_lines_edges_node_orderLine | null;
quantity: number;
- orderLine: OrderCapture_orderCapture_order_fulfillments_lines_edges_node_orderLine;
}
export interface OrderCapture_orderCapture_order_fulfillments_lines_edges {
diff --git a/saleor/static/dashboard-next/orders/types/OrderDetails.ts b/saleor/static/dashboard-next/orders/types/OrderDetails.ts
index 9f72b5c443..e19af41021 100644
--- a/saleor/static/dashboard-next/orders/types/OrderDetails.ts
+++ b/saleor/static/dashboard-next/orders/types/OrderDetails.ts
@@ -79,8 +79,8 @@ export interface OrderDetails_order_fulfillments_lines_edges_node_orderLine {
export interface OrderDetails_order_fulfillments_lines_edges_node {
__typename: "FulfillmentLine";
id: string;
+ orderLine: OrderDetails_order_fulfillments_lines_edges_node_orderLine | null;
quantity: number;
- orderLine: OrderDetails_order_fulfillments_lines_edges_node_orderLine;
}
export interface OrderDetails_order_fulfillments_lines_edges {
diff --git a/saleor/static/dashboard-next/orders/types/OrderDetailsFragment.ts b/saleor/static/dashboard-next/orders/types/OrderDetailsFragment.ts
index 25c40b0025..bb5f16ac32 100644
--- a/saleor/static/dashboard-next/orders/types/OrderDetailsFragment.ts
+++ b/saleor/static/dashboard-next/orders/types/OrderDetailsFragment.ts
@@ -79,8 +79,8 @@ export interface OrderDetailsFragment_fulfillments_lines_edges_node_orderLine {
export interface OrderDetailsFragment_fulfillments_lines_edges_node {
__typename: "FulfillmentLine";
id: string;
+ orderLine: OrderDetailsFragment_fulfillments_lines_edges_node_orderLine | null;
quantity: number;
- orderLine: OrderDetailsFragment_fulfillments_lines_edges_node_orderLine;
}
export interface OrderDetailsFragment_fulfillments_lines_edges {
diff --git a/saleor/static/dashboard-next/orders/types/OrderDraftUpdate.ts b/saleor/static/dashboard-next/orders/types/OrderDraftUpdate.ts
index 3225e3441b..d780247cb7 100644
--- a/saleor/static/dashboard-next/orders/types/OrderDraftUpdate.ts
+++ b/saleor/static/dashboard-next/orders/types/OrderDraftUpdate.ts
@@ -85,8 +85,8 @@ export interface OrderDraftUpdate_draftOrderUpdate_order_fulfillments_lines_edge
export interface OrderDraftUpdate_draftOrderUpdate_order_fulfillments_lines_edges_node {
__typename: "FulfillmentLine";
id: string;
+ orderLine: OrderDraftUpdate_draftOrderUpdate_order_fulfillments_lines_edges_node_orderLine | null;
quantity: number;
- orderLine: OrderDraftUpdate_draftOrderUpdate_order_fulfillments_lines_edges_node_orderLine;
}
export interface OrderDraftUpdate_draftOrderUpdate_order_fulfillments_lines_edges {
diff --git a/saleor/static/dashboard-next/orders/types/OrderLineAdd.ts b/saleor/static/dashboard-next/orders/types/OrderLineAdd.ts
index db0a26c4eb..1e7b9cc3a6 100644
--- a/saleor/static/dashboard-next/orders/types/OrderLineAdd.ts
+++ b/saleor/static/dashboard-next/orders/types/OrderLineAdd.ts
@@ -85,8 +85,8 @@ export interface OrderLineAdd_draftOrderLineCreate_order_fulfillments_lines_edge
export interface OrderLineAdd_draftOrderLineCreate_order_fulfillments_lines_edges_node {
__typename: "FulfillmentLine";
id: string;
+ orderLine: OrderLineAdd_draftOrderLineCreate_order_fulfillments_lines_edges_node_orderLine | null;
quantity: number;
- orderLine: OrderLineAdd_draftOrderLineCreate_order_fulfillments_lines_edges_node_orderLine;
}
export interface OrderLineAdd_draftOrderLineCreate_order_fulfillments_lines_edges {
diff --git a/saleor/static/dashboard-next/orders/types/OrderLineDelete.ts b/saleor/static/dashboard-next/orders/types/OrderLineDelete.ts
index 750270e823..05d80d6a2b 100644
--- a/saleor/static/dashboard-next/orders/types/OrderLineDelete.ts
+++ b/saleor/static/dashboard-next/orders/types/OrderLineDelete.ts
@@ -85,8 +85,8 @@ export interface OrderLineDelete_draftOrderLineDelete_order_fulfillments_lines_e
export interface OrderLineDelete_draftOrderLineDelete_order_fulfillments_lines_edges_node {
__typename: "FulfillmentLine";
id: string;
+ orderLine: OrderLineDelete_draftOrderLineDelete_order_fulfillments_lines_edges_node_orderLine | null;
quantity: number;
- orderLine: OrderLineDelete_draftOrderLineDelete_order_fulfillments_lines_edges_node_orderLine;
}
export interface OrderLineDelete_draftOrderLineDelete_order_fulfillments_lines_edges {
diff --git a/saleor/static/dashboard-next/orders/types/OrderLineUpdate.ts b/saleor/static/dashboard-next/orders/types/OrderLineUpdate.ts
index c1cb2b1019..c5df24a6ed 100644
--- a/saleor/static/dashboard-next/orders/types/OrderLineUpdate.ts
+++ b/saleor/static/dashboard-next/orders/types/OrderLineUpdate.ts
@@ -85,8 +85,8 @@ export interface OrderLineUpdate_draftOrderLineUpdate_order_fulfillments_lines_e
export interface OrderLineUpdate_draftOrderLineUpdate_order_fulfillments_lines_edges_node {
__typename: "FulfillmentLine";
id: string;
+ orderLine: OrderLineUpdate_draftOrderLineUpdate_order_fulfillments_lines_edges_node_orderLine | null;
quantity: number;
- orderLine: OrderLineUpdate_draftOrderLineUpdate_order_fulfillments_lines_edges_node_orderLine;
}
export interface OrderLineUpdate_draftOrderLineUpdate_order_fulfillments_lines_edges {
diff --git a/saleor/static/dashboard-next/orders/types/OrderRefund.ts b/saleor/static/dashboard-next/orders/types/OrderRefund.ts
index 08065691e0..0e3a6f4daf 100644
--- a/saleor/static/dashboard-next/orders/types/OrderRefund.ts
+++ b/saleor/static/dashboard-next/orders/types/OrderRefund.ts
@@ -85,8 +85,8 @@ export interface OrderRefund_orderRefund_order_fulfillments_lines_edges_node_ord
export interface OrderRefund_orderRefund_order_fulfillments_lines_edges_node {
__typename: "FulfillmentLine";
id: string;
+ orderLine: OrderRefund_orderRefund_order_fulfillments_lines_edges_node_orderLine | null;
quantity: number;
- orderLine: OrderRefund_orderRefund_order_fulfillments_lines_edges_node_orderLine;
}
export interface OrderRefund_orderRefund_order_fulfillments_lines_edges {
diff --git a/tests/api/test_graphql.py b/tests/api/test_graphql.py
index 28cc39581d..1bc5249b64 100644
--- a/tests/api/test_graphql.py
+++ b/tests/api/test_graphql.py
@@ -85,7 +85,7 @@ def test_real_query(user_api_client, product):
}
}
}
- products(first: $first, sortBy: $sortBy, attributes: $attributesFilter, price_Gte: $minPrice, price_Lte: $maxPrice) {
+ products(first: $first, sortBy: $sortBy, attributes: $attributesFilter, priceGte: $minPrice, priceLte: $maxPrice) {
...ProductListFragmentQuery
__typename
}