Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add order line display name in templates
fowczarek6559bd618194
diff --git a/saleor/order/templatetags/__init__.py b/saleor/order/templatetags/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/saleor/order/templatetags/order_lines.py b/saleor/order/templatetags/order_lines.pynew file mode 100644index 0000000000..609e6711c2--- /dev/null+++ b/saleor/order/templatetags/order_lines.py@@ -0,0 +1,16 @@+from django import template++from ..models import OrderLine++register = template.Library()++[email protected]_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_namediff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.htmlindex 85fe28fb85..138fedd0bc 100644--- a/templates/dashboard/order/detail.html+++ b/templates/dashboard/order/detail.html@@ -296,9 +296,9 @@<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 @@{% 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.htmlindex 00fa8816d6..8547d13983 100644--- a/templates/dashboard/order/fulfillment.html+++ b/templates/dashboard/order/fulfillment.html@@ -76,9 +76,9 @@<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.htmlindex f2758a38ea..a1c24ad463 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.htmlindex 6e1fb9de03..2ef2a6c4a1 100644--- a/templates/dashboard/order/pdf/invoice.html+++ b/templates/dashboard/order/pdf/invoice.html@@ -75,7 +75,7 @@{% 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.htmlindex 8f6c7a6705..486c862419 100644--- a/templates/dashboard/order/pdf/packing_slip.html+++ b/templates/dashboard/order/pdf/packing_slip.html@@ -69,7 +69,7 @@{% for line in fulfillment %}<tr><td>- {{ line.order_line.product_name }}<br>+ {{ line.order_line1 }}<br></td><td>{{ line.order_line.product_sku }}diff --git a/templates/order/_ordered_items_table.html b/templates/order/_ordered_items_table.htmlindex bf93a0c2b0..6761e238b9 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 @@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 @@{% 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.emailindex 9cceac876c..be6ee7d971 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.emailindex ae8c6626ae..be7d834694 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.emailindex 0e6a082827..e54acd39e8 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.mjmlindex d05a92f689..6491e4290e 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.mjmlindex 439bab9af0..a1cdb3b838 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/test_analytics.py b/tests/test_analytics.pyindex 42a024e906..681caa9624 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_skuassert item["iq"] == str(int(line.quantity))assert item["cu"] == line.unit_price.currencydiff --git a/tests/test_order.py b/tests/test_order.pyindex 7557ba67a9..0c0ff5c6c7 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, patchimport pytestfrom django.urls import reverse@@ -13,6 +13,7 @@ from saleor.core.weight import zero_weightfrom saleor.discount.utils import validate_voucher_in_orderfrom saleor.order import FulfillmentStatus, OrderStatus, events as order_events, modelsfrom saleor.order.models import Fulfillment, Order+from saleor.order.templatetags.order_lines import display_translated_order_line_namefrom saleor.order.utils import (add_variant_to_order,automatically_fulfill_digital_lines,@@ -720,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)+++ "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_namediff --git a/tests/test_seo_schema.py b/tests/test_seo_schema.pyindex c7ea2b3efa..f54f134b03 100644--- a/tests/test_seo_schema.py+++ b/tests/test_seo_schema.py@@ -31,12 +31,13 @@ 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 = str(variant)+ line.product_name = str(variant.product)+ line.variant_name = str(variant)line.save()organization = get_organization()result = get_product_data(line, organization)assert "image" in result["itemOffered"]- assert result["itemOffered"]["name"] == str(variant)+ assert result["itemOffered"]["name"] == variant.display_product()def test_get_order_confirmation_markup(order_with_lines):