CartThrob 10 documentation for ExpressionEngine commerce teams Visit CartThrob.com
CartThrob.com

Template Example: Order Reports

Though CartThrob isn’t a solution like OSCommerce where templates can be simply swapped out, it’s helpful to have somewhere to start. The template example below is meant to be a guide, and will give you somewhere to start building an order reports page.

This template code is also included with CartThrob as one of the auto-install templates. This and other example templates can be automatically installed, along with sample channels and settings by going to the CartThrob extnsions settings page: Global Settings > Auto-Install Templates. This specific example is contained in the “reports” template group of the auto-install templates.

{assign_variable:template="cart_single_page_checkout"}
{embed=includes/.header title="Reports" }
<style type="text/css">
    .store_block table td{
        padding: 6px;
    }
</style>
</head>
<body>
    <p>NOTE: All orders and purchased items are stored with the customer's member_id set as the author of the entry. To display only information for the currently logged in member you can do something like this </p>
    <h3>{exp:channel:entries channel="orders" author_id="CURRENT_USER"}</h3>



    <h1>Reports</h1>
    <p>You can create reports in any way you'd like with CartThrob using standard EE templates.</p>
    <p>Note: CartThrob currently uses standard templates to output report information. Some business owners may want to see these reports within the context of their backend. Take a look at the following article: <a href="/tag-reference/purchase-history/order_items">Site Owner’s Completed Order Report</a></p>


    {!-- ORDERS REPORT --}
    <div class="store_block">
    <h2>Sales Report</h2>
    {!-- outputting products stored in orders channel. Like typical channels, 
        the name of the channel may vary based on your system configuration --}
        {exp:channel:entries channel="orders"}
            <h3>{title}  Purchased: {entry_date format="%m/%d/%Y"}</h3>
            {!-- The "order_items" is a custom field within the channel. 
                The order_items is a very powerful field type. It can dynamically 
                 add and store configured product information. Each new configuration 
                option will be stored in this field, regardless of the name or 
                number of configuration options. This means that you can store 
                sizes, colors, finishes, or other option data without pre-configuring 
                the field. See the article entry here on setting this up: 
                https://cartthrob.com/docs/build-a-store/orders_overview/
                and the article about outputting this data here: 
                https://cartthrob.com/docs/tag-reference/purchase-history/order_items/
              --}
            {!-- :table is a pseudo tag available for the order_items custom field. it
                outputs a table of the content stored in the order_items field. You can 
                also use the {order_items}{/order_items} variable pair for more flexibility --}
            {order_items:table}<br />

            {!-- The variables below all reference standard EE channel custom field variables --}
<pre>
Subtotal:           {order_subtotal}
Tax:                {order_tax}
Shipping:           {order_shipping}
-------------------------------------------------------------
Total:              {order_total}
</pre>


            <br />
            Transaction ID: {order_transaction_id}<br /><br />

            Customer Info: <br />
            {order_billing_first_name} {order_billing_last_name}<br />
            {order_customer_email}<br />

            <hr>
        {/exp:channel:entries}
    </div>

    {!-- PURCHASED ITEMS --}
    <div class="store_block">
    <h2>PURCHASED ITEMS</h2>
    {!-- Purchased items is a standard EE channel. There are no advanced custom fields associated
        with the Purchased items channel --}
        {exp:channel:entries channel="purchased_items" limit="20"}
            <h3>{title}</h3>
            Customer Info: {author}
            Item ID: {purchased_id}
            Quantity Purchased: {purchased_quantity}
            Order ID: {purchased_order_id}
            <hr>
        {/exp:channel:entries}
    </div>
    <div class="store_block">
        <h2>Tags used in this template</h2>
        <ul>
            <li><a href="/tag-reference/purchase-history/order_items">CartThrob Order Items Custom Field Type</a></li>
            <li><a href="/tag-reference/purchase-history/order_items#item:table">CartThrob Order Items:Table</a></li>

        </ul>
    </div>
    <div class="store_block">
        <h2>Concepts used in this template</h2>
        <ul>
            <li><a href="/build-a-store/orders_overview">Orders Channel</a></li>
            <li><a href="/build-a-store/purchased_items_overview">Purchased Items Channel</a></li>
        </ul>
    </div>
    <div class="store_block">
        {embed=includes/.footer}
    </div>
</body>
</html>

The easiest method for using this template is as part of CartThrob’s built-in auto-install templates system, but is included here as an overall sample of what some of the tags can do when put together.