Forum

Thread tagged as: Shop

different email templates for same status

Hello, can I check for a <perch:orderitem id="sku" /> inside an email template and render different content depending on the ordered product?

Proko Mountrichas

Proko Mountrichas 3 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can use perch:if to test the value of sku but not much beyond that.

This is not working as I would expect:

email template

<perch:if id="sku" match="eq" value="SDC_001">
                    <perch:shop id="intro_1" type="textarea" label="Introduction Basic" markdown="true" editor="markitup" size="m" />
                </perch:if>
                <perch:else />
                    <perch:shop id="intro_2" type="textarea" label="Introduction Feng Shui" markdown="true" editor="markitup" size="m" />
                </perch:if>

I tested with different SKUs and always receive the intro_1. Is it just id="sku" I should test against?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is sku available in that context? It's hard to say what's happening only seeing a tiny part of your template.

The rest is pretty much the default order_paid.html.

So later in the template the order item's info are being accessed with perch:orderitem.

<tbody>
            <perch:orderitems>
                <tr>
                    <td>
                        <perch:orderitem id="title" type="hidden" />
                    </td>
                    <td>
                        <perch:orderitem id="price_without_tax" type="hidden" format="$:%.2n" />
                    </td>
                    <td align="right">
                        <perch:orderitem id="total_without_tax" type="hidden" format="$:%.2n" />
                    </td>
                </tr>
            </perch:orderitems>

                <perch:if id="total_discounts" match="gt" value="0.00">
                <tr>
                    <td colspan="4" align="right">
                        Discount (<perch:shop id="discount_code" type="hidden" />)
                    </td>
                    <td align="right" colspan="2">
                        <perch:shop id="total_discounts" type="hidden" format="$:%.2n" />
                    </td>
                </tr>
                <tr>
                    <td colspan="4" align="right">
                        Total
                    </td>
                    <td align="right" colspan="2">
                        <perch:shop id="total_items" type="hidden" format="$:%.2n" />
                    </td>
                </tr>
                <perch:else />
                <tr>
                    <td colspan="4" align="right">
                        Total
                    </td>
                    <td align="right" colspan="2">
                        <perch:shop id="total_items" type="hidden" format="$:%.2n" />
                    </td>
                </tr>
                </perch:if>

                <perch:if id="shipping_weight" match="gt" value="0">
                    <tr>
                        <td colspan="4" align="right">
                            Shipping: <perch:shop id="shipping_method" type="hidden" /> 
                        </td>
                        <td align="right" colspan="2">
                            <perch:shop id="shipping_without_tax" type="hidden" format="$:%.2n" />
                        </td>
                    </tr>
                </perch:if>

                <tr>
                    <td colspan="4" align="right">
                        IVA(21%)
                    </td>
                    <td align="right" colspan="2">
                        <perch:shop id="total_tax" type="hidden" format="$:%.2n" />
                    </td>
                </tr>
                <tr>
                    <td colspan="4" align="right">
                        <b>Grand total</b>
                    </td>
                    <td align="right" colspan="2">
                        <b><perch:shop id="grand_total_formatted" type="hidden" /></b>
                    </td>
                </tr>
            </tbody>

I understand that the ordered item's SKU is not an exception and should also be accessed with <perch:orderitem id="sku" /> . But then I suppose I can't put this into a perch:if right?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can, but only within that context. I suspect that's not going to achieve what you're after.

Yeah and it's not scalable anyway. So I'm investigating a different approach. I want to send a POST request to a Zapier endpoint with a payload of a json object holding the order information. This will then call the Sparkpost API and send the email using a template which can include logic.

An example request

curl -v -H "Accept: application/json" \
        -H "Content-Type: application/json" \
        -X POST \
        -d '{"first_name":"Bryan","last_name":"Helmig","email":"client@test.com", "product":"T-shirt"}' \
        https://zapier.com/hooks/catch/blablah/

What is not clear to me is when exactly I'll have to make the request.

Currently I have a checkout.php page where I call the perch_shop_payment_form() and the success.php where there is only some text for now. Do I have the order information available in php in any of these steps/pages?

I hope the question makes some sense :)

I think I found it. I will try to do it in the success page with perch_shop_order for the order info and some members function for the member's info. All good for now, thanks!