Skip to content

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

Move product_data to separate function

Pacu25e7c61f4aa71
diff --git a/saleor/order/emails_helpers.py b/saleor/order/emails_helpers.py
index 18855a98af..1cb94007e0 100644
--- a/saleor/order/emails_helpers.py
+++ b/saleor/order/emails_helpers.py
@@ -9,13 +9,40 @@ from ..core.utils import build_absolute_uri
def get_organization():
site = Site.objects.get_current()
- organization_data = {
+ return {
'@type': 'Organization',
'name': site.settings.brand_name}
+def get_product_data(line, currency, organization):
+ product_data = {
+ '@type': 'Offer',
+ 'itemOffered': {
+ '@type': 'Product',
+ 'name': line.product_name,
+ 'sku': line.product_sku,
+ },
+ 'price': line.unit_price_gross * line.quantity,
+ 'priceCurrency': currency,
+ 'eligibleQuantity': {
+ '@type': 'QuantitativeValue',
+ 'value': line.quantity
+ },
+ 'seller': organization}
+
+ product = line.product
+ product_url = build_absolute_uri(product.get_absolute_url())
+ product_data['itemOffered']['url'] = product_url
+
+ image = product.get_first_image()
+ if image:
+ product_data['itemOffered']['image'] = build_absolute_uri(
+ location=image.url)
+ return product_data
+
+
def get_order_confirmation_schema(order):
- """Generates schema.org markup for order confirmation message."""
+ """Generates schema.org markup for order confirmation e-mail message."""
organization = get_organization()
order_url = build_absolute_uri(order.get_absolute_url())
data = {
@@ -35,29 +62,8 @@ def get_order_confirmation_schema(order):
'orderDate': order.created}
for line in order.get_lines():
- product_data = {
- '@type': 'Offer',
- 'itemOffered': {
- '@type': 'Product',
- 'name': line.product_name,
- 'sku': line.product_sku,
- },
- 'price': line.unit_price_gross * line.quantity,
- 'priceCurrency': order.total.currency,
- 'eligibleQuantity': {
- '@type': 'QuantitativeValue',
- 'value': line.quantity
- },
- 'seller': organization}
-
- product = line.product
- if product:
- product_url = build_absolute_uri(product.get_absolute_url())
- product_data['itemOffered']['url'] = product_url
-
- image = product.get_first_image()
- if image:
- product_data['itemOffered']['image'] = build_absolute_uri(
- location=image.url)
+ product_data = get_product_data(
+ line=line, currency=order.total.currency,
+ organization=organization)
data['acceptedOffer'].append(product_data)
return json.dumps(data, cls=DjangoJSONEncoder)