Skip to content

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

Fix review remarks

fowczarek53b09ef85af5
diff --git a/saleor/core/analytics.py b/saleor/core/analytics.py
index e266eb8d07..0ace19075f 100644
--- a/saleor/core/analytics.py
+++ b/saleor/core/analytics.py
@@ -40,9 +40,12 @@ def _report(client_id, payloads, extra_headers=None, **extra_data):
def get_order_payloads(order):
items = [
ga.item(
- str(ol), ol.unit_price.gross, quantity=ol.quantity, item_id=ol.product_sku
+ str(order_line),
+ order_line.unit_price.gross,
+ quantity=order_line.quantity,
+ item_id=order_line.product_sku,
)
- for ol in order
+ for order_line in order
]
return ga.transaction(
order.id,
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index 520e730c7e..af70dbc903 100644
--- a/saleor/graphql/order/types.py
+++ b/saleor/graphql/order/types.py
@@ -198,6 +198,12 @@ class OrderLine(CountableDjangoObjectType):
A purchased product variant. Note: this field may be null if the
variant has been removed from stock at all.""",
)
+ translated_product_name = graphene.String(
+ required=True, description="Product name in the customer's language"
+ )
+ translated_variant_name = graphene.String(
+ required=True, description="Variant name in the customer's language"
+ )
class Meta:
description = "Represents order line of particular order."
@@ -213,8 +219,6 @@ class OrderLine(CountableDjangoObjectType):
"quantity",
"quantity_fulfilled",
"tax_rate",
- "translated_product_name",
- "translated_variant_name",
]
@staticmethod
@@ -235,6 +239,14 @@ class OrderLine(CountableDjangoObjectType):
def resolve_unit_price(root: models.OrderLine, _info):
return root.unit_price
+ @staticmethod
+ def resolve_translated_product_name(root: models.OrderLine, _info):
+ return root.translated_product_name
+
+ @staticmethod
+ def resolve_translated_variant_name(root: models.OrderLine, _info):
+ return root.translated_variant_name
+
class Order(CountableDjangoObjectType):
fulfillments = gql_optimizer.field(
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index bb7a4f35c2..346b83c0c0 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -2177,8 +2177,6 @@ type OrderLine implements Node {
id: ID!
productName: String!
variantName: String!
- translatedProductName: String!
- translatedVariantName: String!
productSku: String!
isShippingRequired: Boolean!
quantity: Int!
@@ -2188,6 +2186,8 @@ type OrderLine implements Node {
thumbnail(size: Int): Image
unitPrice: TaxedMoney
variant: ProductVariant
+ translatedProductName: String!
+ translatedVariantName: String!
}
input OrderLineCreateInput {
diff --git a/saleor/order/models.py b/saleor/order/models.py
index fa02ee834f..e536a809b1 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -408,7 +408,7 @@ class OrderLine(models.Model):
def __str__(self):
return (
- "%s (%s)" % (self.product_name, self.variant_name)
+ f"{self.product_name} ({self.variant_name})"
if self.variant_name
else self.product_name
)
diff --git a/saleor/order/templatetags/order_lines.py b/saleor/order/templatetags/order_lines.py
index 609e6711c2..ba40a92066 100644
--- a/saleor/order/templatetags/order_lines.py
+++ b/saleor/order/templatetags/order_lines.py
@@ -7,10 +7,6 @@ register = template.Library()
@register.simple_tag()
def display_translated_order_line_name(order_line: OrderLine):
- product_name = order_line.product_name
- if order_line.translated_product_name:
- product_name = order_line.translated_product_name
- variant_name = order_line.variant_name
- if order_line.translated_variant_name:
- variant_name = order_line.translated_variant_name
- return "%s (%s)" % (product_name, variant_name) if variant_name else product_name
+ product_name = order_line.translated_product_name or order_line.product_name
+ variant_name = order_line.translated_variant_name or order_line.variant_name
+ return f"{product_name} ({variant_name})" if variant_name else product_name
diff --git a/saleor/product/models.py b/saleor/product/models.py
index b081fad3a7..da349c2757 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -464,7 +464,7 @@ class ProductVariant(ModelWithMetadata):
variant_display = str(self)
product = self.product
product_display = (
- "%s (%s)" % (product, variant_display) if variant_display else str(product)
+ f"{product} ({variant_display})" if variant_display else str(product)
)
return smart_text(product_display)
diff --git a/saleor/seo/schema/email.py b/saleor/seo/schema/email.py
index 841aae0c4f..dce97e44a8 100644
--- a/saleor/seo/schema/email.py
+++ b/saleor/seo/schema/email.py
@@ -16,7 +16,7 @@ def get_product_data(line, organization):
line_name = str(line)
if line.translated_product_name:
line_name = (
- "%s (%s)" % (line.translated_product_name, line.translated_variant_name)
+ f"{line.translated_product_name} ({line.translated_variant_name})"
if line.translated_variant_name
else line.translated_product_name
)