When buyers log into the Motorprise site, their open, fulfilled, and rejected orders are displayed on the home page.

Motorprise buyers can also view their orders in the My Account section of the store. Each order is displayed with its number, date, and status.

Buyers can click on any order number to see a full view of that order.

We used the following JSP code fragment from MotorpriseJSP/j22ee-apps/motorprise/web-app/en/users/orders_open.jsp to display the list of orders:

<dsp:getvalueof id="profileId" idtype="java.lang.String" bean="Profile.id">
  <%-- profileId:  <%=profileId%> --%>
  <dsp:droplet name="OrderLookup">
    <dsp:param value="<%=profileId%>" name="userId"/>
    <dsp:param name="state" value="open"/>
    <dsp:param name="startIndex" param="startIndex"/>
    <dsp:oparam name="output">
      <dsp:droplet name="ForEach">
        <dsp:param name="array" param="result"/>
        <dsp:oparam name="outputStart">
          <table border=0 width=95%>
            <tr valign=top>
              <td width=33%><span class="small"><b>Order #</b></span></td>
              <td width=33%><span class="small"><b>Date ordered</b></span></td>
              <td width=33%><span class="small"><b>Status</b></span></td>
           </tr>
           <tr>
             <td colspan=3><hr size=1 color="#666666"></td>
           </tr>

        </dsp:oparam>

        <dsp:oparam name="output">
          <tr>
            <dsp:droplet name="Switch">
            <dsp:param name="value" param="element.originOfOrder"/>
            <dsp:oparam name="default">
              <td><dsp:a href="order.jsp">
              <dsp:param name="orderId" param="element.id"/>
              <dsp:valueof param="element.id"/><dsp:param name="orderState"
                param="state"/>
              </dsp:a></td>
            </dsp:oparam>
            <dsp:oparam name="scheduledOrder">
              <td><dsp:a href="order.jsp">
              <dsp:param name="orderId" param="element.id"/>
              <dsp:valueof param="element.id"/>
              </dsp:a>(ScheduledOrder)</td>
            </dsp:oparam>
            </dsp:droplet>
            <td><dsp:valueof date="MMMMM d, yyyy"
            param="element.submittedDate"/></td>
            <td><dsp:valueof param="element.stateAsString"/></td>
          </tr>

        </dsp:oparam>
        <dsp:oparam name="outputEnd">
          <tr></tr>
          <tr>
            <td colspan=3>
                <hr size=1 color="#666666">
                Now viewing orders
                <dsp:valueof param="startRange"/> -
                <dsp:valueof param="endRange"/> out of
                <dsp:valueof param="total_count"/>
            </td>
            <td>
                <dsp:droplet name="IsEmpty">
                  <dsp:param name="value" param="previousIndex"/>
                  <dsp:oparam name="false">
                    <dsp:a href="orders_open.jsp">
                    <dsp:param name="startIndex" param="previousIndex"/>
                    Previous</dsp:a>
                  </dsp:oparam>
                </dsp:droplet>

                <dsp:droplet name="IsEmpty">
                  <dsp:param name="value" param="nextIndex"/>
                  <dsp:oparam name="false">
                    <dsp:a href="orders_open.jsp">
                    <dsp:param name="startIndex" param="nextIndex"/>
                    Next</dsp:a>
                  </dsp:oparam>
                </dsp:droplet>
            </td>
          </tr>
        </dsp:oparam>


      </dsp:droplet>
    </dsp:oparam>
    <dsp:oparam name="empty">
      <%/* no open orders for user */%>
        You have no open orders.
    </dsp:oparam>
    <dsp:oparam name="error">
      <dsp:valueof param="errorMsg"/>
    </dsp:oparam>
  </dsp:droplet>
</dsp:getvalueof>

We used the OrderLookup component to fetch the orders for the user. It takes the userId, startIndex, and state of each order to fetch and outputs a result array that contains defaultNumOrders if no numOrders parameter is given.

It’s possible that users could have hundreds of orders, so we wanted to make them easy to browse them. We decided to display orders in groups of ten, with links to go to the previous or next group. We used the parameters of OrderLookup to provide this kind of page navigation of the orders.

The number of orders returned by OrderLookup is determined using the parameter numOrders. If this value is not set, then the property defaultNumOrders determines the number of orders to return. In addition, the startIndex parameter is used to specify the index of the order from which to return the orders. We use OrderLookup to set the parameters previousIndex and nextIndex.

We also use OrderLookup to output other parameters to display only a certain number of orders at a time. Based on these parameters, we provide links for the previous and next pages to display the set of orders as shown in the above code.

If you want to display all the orders on a single page, you would set the defaultNumOrders property of OrderLookup to –1 and the output parameter result array will contain all the orders with the given state for the given user.

For more information on order states, see the ATG Commerce States section of the Working With Purchase Process Objects chapter in the ATG Commerce Programming Guide.

 
loading table of contents...