Skip to content

Coupon Batch Report#


Description#

This batch report will allow you to select a range of orders and view some metrics about the used on those orders.

To use, create a new batch report with the code below. Then under order processing, select 1 or more orders, click on batch actions -> Batch Report -> Select the coupon report from the list.

Snippet#

<mvt:foreach iterator="order" array="admin_order:orders">
    <mvt:foreach iterator="coupon" array="order:coupons">
        <mvt:comment>
            :code
            :coupon_id
            :order_id
            :total (discount applied to order)
        </mvt:comment>
        <mvt:assign name="l.settings:found_pos"
            value="miva_array_search( g.coupon_array, 1, l.coupon_record, 'l.coupon_record:code EQ l.settings:coupon:code')" />
        <mvt:if expr="l.settings:found_pos NE 0">
            <mvt:comment>
                Coupon Code Found in Array, Update Values
            </mvt:comment>
            <mvt:assign name="g.current_coupon_total" value="miva_variable_value('g.coupon_array[' $ l.settings:found_pos $ ']:total')" />
            <mvt:assign name="g.updated_coupon_total" value="g.current_coupon_total + l.settings:coupon:total" />
            <mvt:assign name="g.current_order_numbers" value="miva_variable_value('g.coupon_array[' $ l.settings:found_pos $ ']:order_id')" />
            <mvt:assign name="g.updated_order_numbers" value="g.current_order_numbers  $ ',' $ l.settings:coupon:order_id" />
            <mvt:assign name="l.settings:coupon:total" value="g.updated_coupon_total" />
            <mvt:assign name="l.settings:coupon:order_id" value="g.updated_order_numbers" />
            <mvt:comment>
                Work around for update limitations. Delete array index value then re-add it with updated values
            </mvt:comment>
            <mvt:assign name="l.array_count" value="miva_array_delete( g.coupon_array, l.settings:found_pos, 1 )" />
            <mvt:assign name="l.array_count" value="miva_array_insert( g.coupon_array, l.settings:coupon, -1 )" />
        <mvt:else>
            <mvt:assign name="l.array_count" value="miva_array_insert( g.coupon_array, l.settings:coupon, -1 )" />
        </mvt:if>
    </mvt:foreach>
</mvt:foreach>
<mvt:comment>Output Data to the Screen</mvt:comment>
<table>
    <tr>
        <th>Coupon Code</th>
        <th>Coupon Description</th>
        <th>Orders Which Used Coupon</th>
        <th>Total Discount (across all orders selected)</th>
        <th>Number of Times Used</th>
    </tr>
    <mvt:foreach iterator="coupon" array="global:coupon_array">
    <mvt:if expr="pos1 MOD 2 EQ 0">
        <tr bgcolor="#CCC">
    <mvt:else>
        <tr>
    </mvt:if>
            <td> &mvt:coupon:code;</td>
            <td> &mvt:coupon:descrip;</td>
            <td>
                <mvt:comment>Create Link to Orders</mvt:comment>
                <div style="max-height:200px; overflow: scroll;">
                    <mvt:assign name="l.settings:counter" value="1" />
                    <mvt:assign name="l.settings:order_id"
                        value="gettoken(l.settings:coupon:order_id, ',' , l.settings:counter )" />
                    <mvt:while expr="NOT ISNULL l.settings:order_id">
                        <a href="&mvt:global:adminurl;Screen=MORD&Store_Code=&mvt:store:code;&Order_ID=&mvte:order_id;" target="_blank">&mvt:order_id;</a><br>
                        <mvt:assign name="l.settings:counter" value="l.settings:counter + 1" />
                        <mvt:assign name="l.settings:order_id" value="gettoken(l.settings:coupon:order_id, ',' , l.settings:counter )" />
                    </mvt:while>
                </div>
            </td>
            <td>
                <mvt:comment>Format Currency</mvt:comment>
                <mvt:do name="l.settings:coupon:total" file="g.module_store_module_currency" value="CurrencyModule_AddFormatting( g.Store:currncy_mod, l.settings:coupon:total )" />
                &mvt:coupon:total;
            </td>
            <td>
                <mvt:eval expr="l.settings:counter -1" />
            </td>
        </tr>
    </mvt:foreach>
</table>

Functions Used#

  • gettoken
  • CurrencyModule_AddFormatting