1

I'm trying to create a custom report. In it, I need a table with rows that would look like this:

 # Product   Order id Order date
 1 Partridge 1234567  2014-09-15
 2 Dove      1234567  2014-09-15
12 Drummer   1234567  2014-09-15
 3 Dove      2345678  2014-08-01
 4 Drummer   2345678  2014-08-01

Clearly this involves a loop over orders, and an inner loop over the items in the order. However, I haven't been able to access much of the order's data from within the item's loop. While i can see the order ID, I can't seem to access the date the order was entered; instead, entry_date gives the product's creation date, which is not what I want at all. Other attempts -- starting a second-level exp:channel:entries loop with the appropriate order ID, guessing at possible prefixes or containers for order data (like entry:entry_date or order:entry_date) haven't gotten me anywhere. The following is the code I've written for this so far.

<table>
{exp:channel:entries channel="orders"}
    {order_items variable_prefix="item_"}
        <tr>
            <td>{item:quantity}</td>
            <td>{item:title}</td>
            <td>{order_id}</td>
            <td>{entry_date}</td>
        </tr>
    {/order_items}
{/exp:channel:entries}
</table>
0

I just got an email from cartthrob support; they offered a solution: embeds. All the following code is from them.

In reports/.order_date I put:

{exp:channel:entries channel="orders" entry_id="{embed:entry_id}" limit="1"}
{entry_date format="%Y-%m-%d"}
{/exp:channel:entries}

THen I changed the relevant line in my report to say

{embed="reports/.order_date" entry_id="{order_id}"}

Inside the embed, the loops and other data from the main template don't exist; all I can see are the globals (like exp) and the parameters I pass in (order_id). Thus, using a quasi-loop within won't break anything, and I don't have to worry about anything shadowing my variables.

| improve this answer | |
  • Hi thanks for the nice post, I will apply these tips – user6749 Oct 13 '15 at 16:26

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.