Created
January 17, 2015 09:27
-
-
Save sharoonthomas/b65094a1b5f3aa87bd63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/emails/sale-confirmation-html.html b/emails/sale-confirmation-html.html | |
index 4a0ba5c..dfac4cb 100644 | |
--- a/emails/sale-confirmation-html.html | |
+++ b/emails/sale-confirmation-html.html | |
@@ -8,6 +8,94 @@ | |
{% endblock %} | |
</head> | |
<body> | |
+ {% block json_ld %} | |
+ <script type="application/ld+json"> | |
+ {{ sale.as_json_ld()|tojson|safe }} | |
+ </script> | |
+ {% endblock %} | |
{% block body %} | |
Dear {{ sale.party.name }}, | |
<br/><br/> | |
diff --git a/sale.py b/sale.py | |
index ad5ef90..3f0ed93 100644 | |
--- a/sale.py | |
+++ b/sale.py | |
@@ -18,6 +18,71 @@ class Sale: | |
email_sent = fields.Boolean('Confirmation Email Sent?', readonly="True") | |
+ def as_json_ld(self): | |
+ """ | |
+ Gmail markup for order information | |
+ | |
+ https://developers.google.com/gmail/markup/reference/order | |
+ """ | |
+ data = { | |
+ "@context": "http://schema.org", | |
+ "@type": "Order", | |
+ "merchant": { | |
+ "@type": "Organization", | |
+ "name": self.company.name | |
+ }, | |
+ "customer": { | |
+ "@type": "Person", | |
+ "name": self.party.name, | |
+ }, | |
+ "orderNumber": self.reference, | |
+ "priceCurrency": self.currency.code, | |
+ "price": self.total_amount, | |
+ "orderDate": self.sale_date.isoformat(), | |
+ "acceptedOffer": [], | |
+ } | |
+ for line in self.lines: | |
+ data["acceptedOffer"].append({ | |
+ "@type": "Offer", | |
+ "itemOffered": { | |
+ "@type": "Product", | |
+ "name": line.description, | |
+ "sku": line.product and line.product.code or '', | |
+ #"url": "http://www.amazon.com/Samsung-XE303C12-A01US-Chromebook-Wi-Fi-11-6-Inch/dp/B009LL9VDG/", | |
+ #"image": "http://ecx.images-amazon.com/images/I/81H-DO3qX0L._SX522_.jpg" | |
+ }, | |
+ "price": line.unit_price, | |
+ "priceCurrency": sale.currency.code, | |
+ "eligibleQuantity": { | |
+ "@type": "QuantitativeValue", | |
+ "value": line.quantity | |
+ }, | |
+ }) | |
+ | |
+ | |
+ "url": "https://www.amazon.ca/gp/css/summary/edit.html/orderID=123-4567890-1234567", | |
+ "orderStatus": "http://schema.org/OrderStatus/OrderProcessing", | |
+ "paymentMethod": "http://schema.org/CreditCard", | |
+ "paymentMethodId": "**** **** **** 1234", | |
+ "isGift": "false", | |
+ "discount": "0.97", | |
+ "discountCurrency": "USD", | |
+ , | |
+ "billingAddress": } | |
+ if self.invoice_address: | |
+ subdivision = self.invoice_address.subdivision | |
+ country = self.invoice_address.country | |
+ data['billingAddress'] = { | |
+ "@type": "PostalAddress", | |
+ "name": self.invoice_address.name, | |
+ "streetAddress": self.invoice_address.street, | |
+ "addressLocality": self.invoice_address.city, | |
+ "addressRegion": subdivision and subdivision.code or '', | |
+ "addressCountry": country and country.code or '' | |
+ } | |
+ | |
+ return data | |
+ | |
def send_confirmation_email(self): | |
""" | |
An email confirming that the order has been confirmed and that we are |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment