Shopify's Order Printer app is naturally useful for printing orders. It's also useful as a source for Liquid+HTML templates that you can use in Mechanic, for generating PDF versions of orders to be emailed out.

We'll talk about this in two parts: the task script, and then the steps required for preparing an Order Printer template for use with Mechanic.

Task script

Here's a simple script you might use for this purpose, paired with a subscription to shopify/orders/create:

{% action "email" %}
    "to": {{ | json }},
    "subject": {{ options.email_subject__required | strip | json }},
    "body": {{ options.email_body__multiline_required | strip | newline_to_br | json }},
    "reply_to": {{ shop.customer_email | json }},
    "from_display_name": {{ | json }},
    "attachments": {
      {{ options.pdf_attachment_filename__required | json }}: {
        "pdf": {
          "html": {{ options.pdf_html_template__code_multiline_required | json }}
{% endaction %}

As written, this script will provide the Mechanic user with an option labeled "PDF HTML template", where code from Order Printer (or anywhere else) can be used. The rendered HTML will be converted to a PDF, which will be emailed along to the address on the order.

Preparing the template

Order Printer and Mechanic both use Liquid code for their templates. There are only a couple of changes necessary to convert Order Printer code to something Mechanic can use.

1. Change variables to order properties

Order Printer uses variables like {{ total_price }} and {{ transactions }} and {{ email }}. These are all properties of the order object, and you can access them as such in Mechanic, using variables like {{ order.total_price }} and {{ order.transactions }} and {{ }}.

Some variables from Order Printer are already given as properties of an object you can use in Mechanic. For example, {{ }} works in both Order Printer and in Shopify.

For a full list of Order Printer variables, open up a template in the app, and click the "View the Liquid variable list" link.

For a full list of order object properties in Mechanic, see our documentation.

2. Convert numeric strings to numbers

Mechanic uses API data from Shopify to power the order object. Because the Shopify API makes money figures available as strings, you may need to convert these values to numbers for parts of your template to work correctly.

For example: {% if total_price > 5000 %} would need to be converted to {% assign total_price_number = order.total_price | times: 1 %} {% if total_price > 5000 %}.

3. Check your fonts

Under the hood, we use wkhtmltopdf to generate PDFs. This engine does support web fonts, which includes fonts you may get from providers like Google Fonts.

In some cases, the code determining your font may need to be simplified. This varies, and is not always necessary; remember to check your fonts when testing, and send us a support message if you've got any questions.

Did this answer your question?