Repository: saleor/saleor
Pull request: Distinguish OrderLine product name and variant name
I want to merge this change because resolve #4624 

<!-- Please mention all relevant issue numbers. -->

### Screenshots

<!-- If your changes affect the UI, providing "before" and "after" screenshots will
greatly reduce the amount of work needed to review your work. -->

### Pull Request Checklist

<!-- Please keep this section. It will make maintainer's life easier. -->

1. [ ] Privileged views and APIs are guarded by proper permission checks.
1. [ ] All visible strings are translated with proper context.
1. [ ] All data-formatting is locale-aware (dates, numbers, and so on).
1. [ ] Database queries are optimized and the number of queries is constant.
1. [ ] Database migration files are up to date.
1. [ ] The changes are tested.
1. [ ] GraphQL schema and type definitions are up to date.
1. [ ] Changes are mentioned in the changelog.


Problem statement:
Distinguish OrderLine product name and variant name
Currently `OrderLine` `productName` is a combination of `product.name (variant.name)`.

Proposal:
Backend should not force how to format the order line item name, ideally it should expose `productName` and `variantName` and let the frontend decide what and how to display it.

Hints from issue discussion:

Commit message: Add schema and changelog

Patch to review:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c397a8ff56d..bc793c61141 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -59,7 +59,8 @@ All notable, unreleased changes to this project will be documented in this file.
 - Change AddressValidationRules API - #4655 by @Kwaidan00
 - Refactor account deletion mutations - #4668 by @fowczarek
 - Upgraded django-prices from v1 to v2.1. Currency codes are now locked at 3 characters max by default for consistency. - #4639 by @NyanKiyoshi
-- Drop deprecated fields from api - #4684 by@fowczarek
+- Drop deprecated fields from api - #4684 by @fowczarek
+- Distinguish OrderLine product name and variant name - #4702 by @fowczarek
 
 ## 2.8.0
 
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.py
index 8a49844b9c0..23feed7dfe5 100644
--- a/saleor/checkout/utils.py
+++ b/saleor/checkout/utils.py
@@ -1028,14 +1028,21 @@ def create_line_for_order(checkout_line: "CheckoutLine", discounts) -> OrderLine
 
     quantity = checkout_line.quantity
     variant = checkout_line.variant
+    product = variant.product
     variant.check_quantity(quantity)
 
-    product_name = variant.display_product()
-    translated_product_name = variant.display_product(translated=True)
+    product_name = str(product)
+    variant_name = str(variant)
+
+    translated_product_name = str(product.translated)
+    translated_variant_name = str(variant.translated)
 
     if translated_product_name == product_name:
         translated_product_name = ""
 
+    if translated_variant_name == variant_name:
+        translated_variant_name = ""
+
     manager = get_extensions_manager()
     total_line_price = manager.calculate_checkout_line_total(checkout_line, discounts)
     unit_price = quantize_price(
@@ -1043,7 +1050,9 @@ def create_line_for_order(checkout_line: "CheckoutLine", discounts) -> OrderLine
     )
     line = OrderLine(
         product_name=product_name,
+        variant_name=variant_name,
         translated_product_name=translated_product_name,
+        translated_variant_name=translated_variant_name,
         product_sku=variant.sku,
         is_shipping_required=variant.is_shipping_required(),
         quantity=quantity,
diff --git a/saleor/core/analytics.py b/saleor/core/analytics.py
index 448039113e5..e266eb8d076 100644
--- a/saleor/core/analytics.py
+++ b/saleor/core/analytics.py
@@ -40,10 +40,7 @@ def _report(client_id, payloads, extra_headers=None, **extra_data):
 def get_order_payloads(order):
     items = [
         ga.item(
-            ol.product_name,
-            ol.unit_price.gross,
-            quantity=ol.quantity,
-            item_id=ol.product_sku,
+            str(ol), ol.unit_price.gross, quantity=ol.quantity, item_id=ol.product_sku
         )
         for ol in order
     ]
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index 72c5dfb2231..45ab0fb7c5a 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -359,6 +359,7 @@ def create_order_lines(order, discounts, how_many=10):
     lines = []
     for dummy in range(how_many):
         variant = next(variants_iter)
+        product = variant.product
         quantity = random.randrange(1, 5)
         variant.quantity += quantity
         variant.quantity_allocated += quantity
@@ -367,7 +368,8 @@ def create_order_lines(order, discounts, how_many=10):
         lines.append(
             OrderLine(
                 order=order,
-                product_name=variant.display_product(),
+                product_name=str(product),
+                variant_name=str(variant),
                 product_sku=variant.sku,
                 is_shipping_required=variant.is_shipping_required(),
                 quantity=quantity,
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index 39c9e2a9d16..520e730c7e1 100644
--- a/saleor/graphql/order/types.py
+++ b/saleor/graphql/order/types.py
@@ -208,11 +208,13 @@ class Meta:
             "id",
             "is_shipping_required",
             "product_name",
+            "variant_name",
             "product_sku",
             "quantity",
             "quantity_fulfilled",
             "tax_rate",
             "translated_product_name",
+            "translated_variant_name",
         ]
 
     @staticmethod
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index a71cfaefca2..bb7a4f35c28 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -2176,7 +2176,9 @@ input OrderFilterInput {
 type OrderLine implements Node {
   id: ID!
   productName: String!
+  variantName: String!
   translatedProductName: String!
+  translatedVariantName: String!
   productSku: String!
   isShippingRequired: Boolean!
   quantity: Int!
diff --git a/saleor/order/migrations/0073_auto_20190829_0249.py b/saleor/order/migrations/0073_auto_20190829_0249.py
new file mode 100644
index 00000000000..27783790bc1
--- /dev/null
+++ b/saleor/order/migrations/0073_auto_20190829_0249.py
@@ -0,0 +1,34 @@
+# Generated by Django 2.2.4 on 2019-08-29 07:49
+
+from django.db import migrations, models
+
+
+def add_variant_name_to_order_line(apps, schema_editor):
+    cls = apps.get_model("order", "OrderLine")
+    order_lines = cls.objects.all()
+
+    for order_line in order_lines:
+        if order_line.variant:
+            variant_name = order_line.variant.name or order_line.variant.sku
+            order_line.variant_name = variant_name
+            order_line.product_name = order_line.variant.product.name
+            order_line.save(update_fields=["variant_name", "product_name"])
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [("order", "0072_django_price_2")]
+
+    operations = [
+        migrations.AddField(
+            model_name="orderline",
+            name="translated_variant_name",
+            field=models.CharField(blank=True, default="", max_length=255),
+        ),
+        migrations.AddField(
+            model_name="orderline",
+            name="variant_name",
+            field=models.CharField(blank=True, default="", max_length=255),
+        ),
+        migrations.RunPython(add_variant_name_to_order_line),
+    ]
diff --git a/saleor/order/models.py b/saleor/order/models.py
index ad3e54392cb..fa02ee834f5 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -360,7 +360,9 @@ class OrderLine(models.Model):
     )
     # max_length is as produced by ProductVariant's display_product method
     product_name = models.CharField(max_length=386)
+    variant_name = models.CharField(max_length=255, default="", blank=True)
     translated_product_name = models.CharField(max_length=386, default="", blank=True)
+    translated_variant_name = models.CharField(max_length=255, default="", blank=True)
     product_sku = models.CharField(max_length=32)
     is_shipping_required = models.BooleanField()
     quantity = models.IntegerField(validators=[MinValueValidator(1)])
@@ -405,7 +407,11 @@ class Meta:
         ordering = ("pk",)
 
     def __str__(self):
-        return self.product_name
+        return (
+            "%s (%s)" % (self.product_name, self.variant_name)
+            if self.variant_name
+            else self.product_name
+        )
 
     def get_total(self):
         return self.unit_price * self.quantity
diff --git a/saleor/order/templatetags/__init__.py b/saleor/order/templatetags/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/saleor/order/templatetags/order_lines.py b/saleor/order/templatetags/order_lines.py
new file mode 100644
index 00000000000..609e6711c20
--- /dev/null
+++ b/saleor/order/templatetags/order_lines.py
@@ -0,0 +1,16 @@
+from django import template
+
+from ..models import OrderLine
+
+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
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index 1aca17048ce..b76f5017f59 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -289,13 +289,20 @@ def add_variant_to_order(
     except OrderLine.DoesNotExist:
         unit_price = variant.get_price(discounts)
         unit_price = TaxedMoney(net=unit_price, gross=unit_price)
-        product_name = variant.display_product()
-        translated_product_name = variant.display_product(translated=True)
+        product = variant.product
+        product_name = str(product)
+        variant_name = str(variant)
+        translated_product_name = str(product.translated)
+        translated_variant_name = str(variant.translated)
         if translated_product_name == product_name:
             translated_product_name = ""
+        if translated_variant_name == variant_name:
+            translated_variant_name = ""
         line = order.lines.create(
             product_name=product_name,
+            variant_name=variant_name,
             translated_product_name=translated_product_name,
+            translated_variant_name=translated_variant_name,
             product_sku=variant.sku,
             is_shipping_required=variant.is_shipping_required(),
             quantity=quantity,
diff --git a/saleor/seo/schema/email.py b/saleor/seo/schema/email.py
index e725a227bc8..841aae0c4f9 100644
--- a/saleor/seo/schema/email.py
+++ b/saleor/seo/schema/email.py
@@ -13,13 +13,16 @@ def get_organization():
 
 def get_product_data(line, organization):
     gross_product_price = line.get_total().gross
+    line_name = str(line)
+    if line.translated_product_name:
+        line_name = (
+            "%s (%s)" % (line.translated_product_name, line.translated_variant_name)
+            if line.translated_variant_name
+            else line.translated_product_name
+        )
     product_data = {
         "@type": "Offer",
-        "itemOffered": {
-            "@type": "Product",
-            "name": line.translated_product_name or line.product_name,
-            "sku": line.product_sku,
-        },
+        "itemOffered": {"@type": "Product", "name": line_name, "sku": line.product_sku},
         "price": gross_product_price.amount,
         "priceCurrency": gross_product_price.currency,
         "eligibleQuantity": {"@type": "QuantitativeValue", "value": line.quantity},
diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.html
index 85fe28fb85a..138fedd0bcf 100644
--- a/templates/dashboard/order/detail.html
+++ b/templates/dashboard/order/detail.html
@@ -296,9 +296,9 @@ <h6>
                 <tr class="last-no-border">
                   <td>
                     {% if line.variant.product %}
-                      <a href="{% url 'dashboard:product-details' pk=line.variant.product.pk %}">{{ line.product_name }}</a>
+                      <a href="{% url 'dashboard:product-details' pk=line.variant.product.pk %}">{{ line }}</a>
                     {% else %}
-                      {{ line.product_name }}
+                      {{ line }}
                     {% endif %}
                     <br>
                     <span class="grey-text">
@@ -486,7 +486,7 @@ <h5 class="data-table-title">
                 {% for line in fulfillment %}
                   <tr class="last-no-border">
                     <td>
-                      {{ line.order_line.product_name }}
+                      {{ line.order_line }}
                     </td>
                     <td class="right-align">
                       {{ line.quantity }}
diff --git a/templates/dashboard/order/fulfillment.html b/templates/dashboard/order/fulfillment.html
index 00fa8816d69..8547d139836 100644
--- a/templates/dashboard/order/fulfillment.html
+++ b/templates/dashboard/order/fulfillment.html
@@ -76,9 +76,9 @@ <h5>
                 <tr>
                   <td>
                     {% if line.variant %}
-                      <a href="{% url 'dashboard:variant-details' product_pk=line.variant.product.pk variant_pk=line.variant.pk %}">{{ line.product_name }}</a>
+                      <a href="{% url 'dashboard:variant-details' product_pk=line.variant.product.pk variant_pk=line.variant.pk %}">{{ line }}</a>
                     {% else %}
-                      {{ line.product_name }}
+                      {{ line }}
                     {% endif %}
                     <br>
                     <span class="grey-text">
diff --git a/templates/dashboard/order/modal/cancel_line.html b/templates/dashboard/order/modal/cancel_line.html
index f2758a38eac..a1c24ad4631 100644
--- a/templates/dashboard/order/modal/cancel_line.html
+++ b/templates/dashboard/order/modal/cancel_line.html
@@ -41,7 +41,7 @@
       <tbody>
         <tr>
           <td>
-            {{ item.product_name }}<br>
+            {{ item }}<br>
           </td>
           <td>
             {{ item.product_sku }}
diff --git a/templates/dashboard/order/pdf/invoice.html b/templates/dashboard/order/pdf/invoice.html
index 6e1fb9de032..2ef2a6c4a1b 100644
--- a/templates/dashboard/order/pdf/invoice.html
+++ b/templates/dashboard/order/pdf/invoice.html
@@ -75,7 +75,7 @@ <h2>{% trans "Items Ordered" context "Invoice ordered items header" %}</h2>
         {% for line in order %}
           <tr>
             <td>
-              {{ line.product_name|truncatechars:30 }}<br>
+              {{ line|truncatechars:30 }}<br>
             </td>
             <td>
               {{ line.product_sku }}
diff --git a/templates/dashboard/order/pdf/packing_slip.html b/templates/dashboard/order/pdf/packing_slip.html
index 8f6c7a67054..4a4816e421e 100644
--- a/templates/dashboard/order/pdf/packing_slip.html
+++ b/templates/dashboard/order/pdf/packing_slip.html
@@ -69,7 +69,7 @@ <h2>{% trans "Items Ordered" context "Order invoice" %}</h2>
         {% for line in fulfillment %}
           <tr>
             <td>
-              {{ line.order_line.product_name }}<br>
+              {{ line.order_line }}<br>
             </td>
             <td>
               {{ line.order_line.product_sku }}
diff --git a/templates/order/_ordered_items_table.html b/templates/order/_ordered_items_table.html
index bf93a0c2b0f..6761e238b97 100644
--- a/templates/order/_ordered_items_table.html
+++ b/templates/order/_ordered_items_table.html
@@ -4,6 +4,7 @@
 {% load placeholder %}
 {% load price from taxed_prices %}
 {% load get_product_image_thumbnail from product_images %}
+{% load display_translated_order_line_name from order_lines %}
 
 {% if order.user == user %}
   <div class="order-details__addresses">
@@ -61,11 +62,11 @@ <h3>
                   data-srcset="{% get_product_image_thumbnail line.variant.get_first_image size=60 method="thumbnail" %} 1x, {% get_product_image_thumbnail line.variant.get_first_image size=120 method="thumbnail" %} 2x"
                   class="float-left lazyload lazypreload"
                   src="{% placeholder size=60 %}">
-            <span>{{ line.translated_product_name|default:line.product_name }}</span>
+            <span>{% display_translated_order_line_name line %}</span>
           </a>
         {% else %}
           <img src="{% placeholder size=60 %}" class="float-left">
-          <span>{{ line.translated_product_name|default:line.product_name }}</span>
+          <span>{% display_translated_order_line_name line %}</span>
         {% endif %}
       </div>
       <div class="col-md-4 order-details__product__description">
@@ -197,10 +198,10 @@ <h2 class="order-details__header">
           {% with variant=fulfillment_line.order_line.variant %}
             {% if variant %}
               <a class="link--clean" href="{{ variant.get_absolute_url }}">
-                <span>{{ fulfillment_line.order_line.translated_product_name|default:fulfillment_line.order_line.product_name }}</span>
+                <span>{% display_translated_order_line_name fulfillment_line.order_line %}</span>
               </a>
             {% else %}
-              <span>{{ fulfillment_line.order_line.translated_product_name|default:fulfillment_line.order_line.product_name }}</span>
+              <span>{% display_translated_order_line_name fulfillment_line.order_line%}</span>
             {% endif %}
           {% endwith %}
         </div>
diff --git a/templates/templated_email/order/confirm_fulfillment.email b/templates/templated_email/order/confirm_fulfillment.email
index 9cceac876c5..be6ee7d9710 100644
--- a/templates/templated_email/order/confirm_fulfillment.email
+++ b/templates/templated_email/order/confirm_fulfillment.email
@@ -18,7 +18,7 @@ You can track your shipment with {{ tracking_number }} code.
 {% endif %}
 
 {% for line in physical_lines %}
-{{ line.quantity }} x {{ line.order_line.product_name }}
+{{ line.quantity }} x {{ line.order_line }}
 {% endfor %}
 
 {% for line in digital_lines %}
diff --git a/templates/templated_email/order/confirm_order.email b/templates/templated_email/order/confirm_order.email
index ae8c6626aea..be7d834694b 100644
--- a/templates/templated_email/order/confirm_order.email
+++ b/templates/templated_email/order/confirm_order.email
@@ -12,7 +12,7 @@
 Thank you for your order. Below is the list of ordered products. To see your payment details please visit:
 {{ order_details_url }}{% endblocktrans %}
 {% for line in order %}
-{{ line.quantity }} x {{ line.product_name }}, {% price line.get_total display_gross=order.display_gross_prices html=False %}
+{{ line.quantity }} x {{ line }}, {% price line.get_total display_gross=order.display_gross_prices html=False %}
 {% endfor %}
 {% trans "Order summary" context "Order confirmation e-mail table header" %}:
 {% trans "Subtotal" context "Order confirmation e-mail table header" %}:           {% price order.get_subtotal display_gross=order.display_gross_prices html=False %}
diff --git a/templates/templated_email/order/update_fulfillment.email b/templates/templated_email/order/update_fulfillment.email
index 0e6a0828270..e54acd39e83 100644
--- a/templates/templated_email/order/update_fulfillment.email
+++ b/templates/templated_email/order/update_fulfillment.email
@@ -18,7 +18,7 @@ You can track your shipment with the following code: {{ tracking_number }}.
 {% endif %}
 
 {% for line in fulfillment %}
-{{ line.quantity }} x {{ line.order_line.product_name }}
+{{ line.quantity }} x {{ line.order_line }}
 {% endfor %}
 
 {% include 'templated_email/shared/_footer.email' %}
diff --git a/templates/templated_email/source/partials/_fulfillment_lines.mjml b/templates/templated_email/source/partials/_fulfillment_lines.mjml
index d05a92f689c..6491e4290e8 100644
--- a/templates/templated_email/source/partials/_fulfillment_lines.mjml
+++ b/templates/templated_email/source/partials/_fulfillment_lines.mjml
@@ -1,3 +1,6 @@
+<mj-raw>
+  {% load display_translated_order_line_name from order_lines %}
+</mj-raw>
 <mj-section>
   <mj-column>
     <mj-text>
@@ -12,7 +15,7 @@
           <tbody>
             {% for line in physical_lines %}
               <tr class="table-item-row">
-                <td>{{ line.order_line.translated_product_name|default:line.order_line.product_name }}</td>
+                <td>{% display_translated_order_line_name line.order_line %}</td>
                 <td style="text-align: right;">{{ line.quantity }}</td>
               </tr>
             {% endfor %}
@@ -30,7 +33,7 @@
           <tbody>
             {% for line in digital_lines %}
               <tr class="table-item-row">
-                <td>{{ line.order_line.translated_product_name|default:line.order_line.product_name }}</td>
+                <td>{% display_translated_order_line_name line.order_line %}</td>
                 <td style="text-align: right;">
                   <a href={{ line.order_line.digital_content_url.get_absolute_url }}>Link</a>
                 </td>
diff --git a/templates/templated_email/source/partials/_order_lines.mjml b/templates/templated_email/source/partials/_order_lines.mjml
index 439bab9af02..a1cdb3b838b 100644
--- a/templates/templated_email/source/partials/_order_lines.mjml
+++ b/templates/templated_email/source/partials/_order_lines.mjml
@@ -1,4 +1,5 @@
 <mj-raw>
+  {% load display_translated_order_line_name from order_lines %}
   {% load price from taxed_prices %}
   {% load voucher %}
 </mj-raw>
@@ -64,7 +65,7 @@
       <tbody>
         {% for line in order %}
           <tr class="table-item-row">
-            <td>{{ line.translated_product_name|default:line.product_name }}</td>
+            <td>{% display_translated_order_line_name line %}</td>
             <td style="text-align: right;">{{ line.quantity }}</td>
             <td style="text-align: right;">
               {% price line.unit_price display_gross=order.display_gross_prices html=False %}
diff --git a/tests/api/test_order.py b/tests/api/test_order.py
index 49c61901871..c0045a61873 100644
--- a/tests/api/test_order.py
+++ b/tests/api/test_order.py
@@ -324,6 +324,7 @@ def test_nested_order_events_query(
                                 quantity
                                 orderLine {
                                     productName
+                                    variantName
                                 }
                             }
                             paymentId
@@ -367,7 +368,10 @@ def test_nested_order_events_query(
     assert data["fulfilledItems"] == [
         {
             "quantity": line.quantity,
-            "orderLine": {"productName": line.order_line.product_name},
+            "orderLine": {
+                "productName": line.order_line.product_name,
+                "variantName": line.order_line.variant_name,
+            },
         }
         for line in fulfillment.lines.all()
     ]
diff --git a/tests/conftest.py b/tests/conftest.py
index 636b6223c43..9dcf9e85d60 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -751,7 +751,8 @@ def order_line(order, variant):
     net = variant.get_price()
     gross = Money(amount=net.amount * Decimal(1.23), currency=net.currency)
     return order.lines.create(
-        product_name=variant.display_product(),
+        product_name=str(variant.product),
+        variant_name=str(variant),
         product_sku=variant.sku,
         is_shipping_required=variant.is_shipping_required(),
         quantity=3,
@@ -807,7 +808,8 @@ def order_with_lines(order, product_type, category, shipping_zone):
     net = variant.get_price()
     gross = Money(amount=net.amount * Decimal(1.23), currency=net.currency)
     order.lines.create(
-        product_name=variant.display_product(),
+        product_name=str(variant.product),
+        variant_name=str(variant),
         product_sku=variant.sku,
         is_shipping_required=variant.is_shipping_required(),
         quantity=3,
@@ -833,7 +835,8 @@ def order_with_lines(order, product_type, category, shipping_zone):
     net = variant.get_price()
     gross = Money(amount=net.amount * Decimal(1.23), currency=net.currency)
     order.lines.create(
-        product_name=variant.display_product(),
+        product_name=str(variant.product),
+        variant_name=str(variant),
         product_sku=variant.sku,
         is_shipping_required=variant.is_shipping_required(),
         quantity=2,
diff --git a/tests/test_analytics.py b/tests/test_analytics.py
index 42a024e906d..681caa96248 100644
--- a/tests/test_analytics.py
+++ b/tests/test_analytics.py
@@ -25,7 +25,7 @@ def test_get_order_payloads(order_with_lines):
     for i, line in enumerate(order):
         item = data[i + 1]
         assert item["ti"] == order.pk
-        assert item["in"] == line.product_name
+        assert item["in"] == line.variant.display_product()
         assert item["ic"] == line.product_sku
         assert item["iq"] == str(int(line.quantity))
         assert item["cu"] == line.unit_price.currency
diff --git a/tests/test_order.py b/tests/test_order.py
index 79ec2c0daec..0c0ff5c6c7e 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -1,5 +1,5 @@
 from decimal import Decimal
-from unittest.mock import patch
+from unittest.mock import MagicMock, patch
 
 import pytest
 from django.urls import reverse
@@ -13,6 +13,7 @@
 from saleor.discount.utils import validate_voucher_in_order
 from saleor.order import FulfillmentStatus, OrderStatus, events as order_events, models
 from saleor.order.models import Fulfillment, Order
+from saleor.order.templatetags.order_lines import display_translated_order_line_name
 from saleor.order.utils import (
     add_variant_to_order,
     automatically_fulfill_digital_lines,
@@ -68,7 +69,9 @@ def test_add_variant_to_order_adds_line_for_new_variant(
     assert line.product_sku == variant.sku
     assert line.quantity == 1
     assert line.unit_price == TaxedMoney(net=Money(10, "USD"), gross=Money(10, "USD"))
-    assert line.translated_product_name == variant.display_product(translated=True)
+    assert line.translated_product_name == str(variant.product.translated)
+    assert line.variant_name == str(variant)
+    assert line.product_name == str(variant.product)
 
 
 @pytest.mark.parametrize("track_inventory", (True, False))
@@ -718,3 +721,32 @@ def test_get_voucher_discount_for_order_voucher_validation(
     mock_validate_voucher.assert_called_once_with(
         voucher, subtotal.gross, quantity, customer_email
     )
+
+
+@pytest.mark.parametrize(
+    "product_name, variant_name, translated_product_name, translated_variant_name,"
+    "expected_display_name",
+    [
+        ("product", "variant", "", "", "product (variant)"),
+        ("product", "", "", "", "product"),
+        ("product", "", "productPL", "", "productPL"),
+        ("product", "variant", "productPL", "", "productPL (variant)"),
+        ("product", "variant", "productPL", "variantPl", "productPL (variantPl)"),
+        ("product", "variant", "", "variantPl", "product (variantPl)"),
+    ],
+)
+def test_display_translated_order_line_name(
+    product_name,
+    variant_name,
+    translated_product_name,
+    translated_variant_name,
+    expected_display_name,
+):
+    order_line = MagicMock(
+        product_name=product_name,
+        variant_name=variant_name,
+        translated_product_name=translated_product_name,
+        translated_variant_name=translated_variant_name,
+    )
+    display_name = display_translated_order_line_name(order_line)
+    assert display_name == expected_display_name
diff --git a/tests/test_seo_schema.py b/tests/test_seo_schema.py
index 4630e614411..f54f134b035 100644
--- a/tests/test_seo_schema.py
+++ b/tests/test_seo_schema.py
@@ -31,7 +31,8 @@ def test_get_product_data_with_image(order_with_lines, product_with_image):
     line = order_with_lines.lines.first()
     variant = product_with_image.variants.first()
     line.variant = variant
-    line.product_name = variant.display_product()
+    line.product_name = str(variant.product)
+    line.variant_name = str(variant)
     line.save()
     organization = get_organization()
     result = get_product_data(line, organization)


Code review comments:
diff_hunk: @@ -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="Varinat name in the customer's language"
path: saleor/graphql/order/types.py
text: @user1:
```suggestion
        required=True, description="Variant name in the customer's language"
```