1

I have this as a template and I am wondering is this the way you build these? The documentation is not quite clear on how the variables are meant to be formed for an html email.

Order:{hook:transaction_id}

Thank you for your purchase.

{hook:items} {hook:item:quantity} x {hook:item:title}{hook:item:product_notes}
{hook:item:price} {/hook:items}

Total: {order_total}

Email: {hook:order_customer_email}

  • And actually these don't work at all, they don't render the tags but put them in as literals. Anyone know? I have tried multiple variations to no avail. – Aaron Jun 25 '14 at 17:51
0

I have done this via stash (is there nothing it can't solve?!)

Following the basic approach of the excellent article here: https://pixelfear.com/blog/maintainable-emails-with-stash-and-postmaster

This allows one to pass the entry_id of the order to the email template.


{exp:stash:embed
  name="emails:super_receipt"
  process="start"
  stash:e_id="{hook:entry_id}"
}

(this is using the cartthrob_on_authorize hook, and I have another for cartthrob_on_processing)

In the emails:super_receipt template, I then use this to retrieve the order details and order item details (I actually use some nice encapsulated re-useable stash models for these, but basically these are just channel entries loops which pull the data from the channel and bung it into stash variables and the items into a stash list)


{exp:channel:entries channel="orders" entry_id="{stash:e_id}"  status="not closed" dynamic="no" parse="inward"}
    {!-- Order Data--}
    {exp:stash:set name="order_title"}{title}{/exp:stash:set}
    {exp:stash:set name="order_entry_id"}{entry_id}{/exp:stash:set}
    {exp:stash:set name="order_url_title"}{url_title}{/exp:stash:set}
etc.

Then printing the data in the email (partial) template so:


{!-- The layout gets filled in with the data below --}
{stash:embed:layouts_emails:layout_basic}

{!-- takes the list order_items from model_order and creates list extended_product_info --} {stash:embed:order_models:model_order_extended_product_info} {!-- Gets the basic order data --} {stash:embed:order_models:model_order}

{exp:stash:set name="email_body"}

{!-- ORDER DETAILS --}
{stash:order_title} ({stash:e_id})
<table>
    <thead>
        <tr>
            <th></th><th>Qty.</th><th>Item</th><th>Price<th>Subtotal</th>
        </tr>
    </thead>
    <tbody>

{!-- this list has all the info from cartthrob order_items--}
{exp:stash:get_list name="order_items" parse_tags="yes" parse_depth="5" sort="desc" orderby="item_price_inc_numeric" sort_type="numeric"}

etc

The beauty of this is that you can get ALL your order data, and indeed product data (e.g. pictures etc), and package it up how you need, and then have a file based (version controlled) - partial template that fills in a layout, just like you would anywhere else on your site.

It's fantastic and basically once the hook is set up you can stay out of the clunky postmaster editor (actually, it's a great editor for an embedded one, but it's no SublimeText ;)

If you didn't want to take this approach, try doing your set up as a parcel first, rather than a hook, and in the editor get it to parse an order entry so you can see what data is available easily using the editor (although it will be {parcel:entry_id} rather than {hook:whatever} of course).

Postmaster is great - the documentation for it, though, is severely lacking in some basic examples of each cool thing it can do that would really help people get going with it.

| improve this answer | |
  • I am going to give this a go, but looks like a very good option indeed. – Aaron Jun 26 '14 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.