shoppingcarttable.jsp

来自「实现一个网络购物」· JSP 代码 · 共 245 行

JSP
245
字号
<%  String formScript = "function changeIt(url) {"
                + "\nvar href = \"&pst=\";"
                + "\nvar valM = document.shoppingcart.elements[\"memberid\"].value;"
                + "\nhref += \"|valM=\" + escape(valM);";
                
// ************************** the membershipshorm ***************************

%><table colspan="6" width="100%" cellspacing="0" cellpadding="0">
<form name="shoppingcart" method="post" target="" onKeyPress="javascript:useEnterKey();"
    action="javascript:changeIt('<mm:url referids="portal"  page="<%= "index.jsp?page=bestel&t=change" %>" />');">
<tr>
<td class="nav" width="100%"><% 
    if(productsIterator.size()==0) {
        %>Your shoppingcart is empty.<br>
         <%@include file="../includes/relatedshoplinks.jsp" %><%
    } else {
        %>Shopping Cart Items<%
    } %></td>
<td><%@include file="../includes/membershipsform.jsp" %></td>
</tr>
<tr>
<td><img src="media/spacer.gif" width="1" height="10" border="0" alt=""></td>
   
</tr>
</table>
<%
// ************************** the table with products ***************************
if(productsIterator.size()>0) {

formScript += "\nvar valD = document.shoppingcart.elements[\"donation\"].value;"
        + "\nif(valD!='') { href += \"|valD=\" + escape(valD); }";
%><table width="100%" cellspacing="0" cellpadding="0">
    <tr><td colspan="6" class="titlebar"><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td></tr>
    <tr>
        <td class="cartheader">PRODUCT DESCRIPTION </td>
        <td class="cartheader">QUANTITY</td>
        <td class="cartheader">CHANGE<br>QUANTITY</td>
        <% if(memberId.equals("")) {
            %><td class="cartheader" style="text-align:right;padding-right:22px;padding-left:0px;">PRICE</td><% 
        } else {
            %><td class="cartheader" style="text-align:right;padding-left:0px;">MEMBERS PRICE</td><%
        } %>
        <td class="cartheader" style="text-align:right;">TOTAL</td>
        <td class="cartheader">REMOVE<br>THIS PRODUCT</td>
    </tr>
    <tr><td colspan="6" width="100%" class="titlebar"><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td></tr><%

    String rowParity = "even";
    while(productsIterator.size()>0) { 
        String thisProduct = (String) productsIterator.firstKey();
        int numberOfItems = Integer.parseInt((String) productsIterator.get(thisProduct));
        productsIterator.remove(thisProduct);
        if(rowParity.equals("even")) { rowParity = "odd"; } else { rowParity = "even"; }
        int price = 0;
        int discount = 0;
        
        formScript += "\nvar val" + thisProduct + " = document.shoppingcart.elements[\"numberof" + thisProduct + "\"].value;\n"
                + "if(val" + thisProduct + "!='') { href += \"|valP" + thisProduct + "=\" + escape(val" + thisProduct + "); } \n"; 
        
        %><mm:node number="<%= thisProduct %>" notfound="skipbody"
        ><%@include file="../includes/getprice.jsp"
        %><%@include file="../includes/getdiscount.jsp" 
        %><tr>
            <td class="cart<%= rowParity %>" style="text-align:left;padding-right:0px;">
            <mm:list nodes="<%= thisProduct %>" path="products,posrel,productgroups,posrel,pages" max="1"
            ><mm:field name="pages.number" jspvar="pages_number" vartype="String" write="false"
            ><a class="nav" href="javascript:changeIt('<mm:url referids="portal"  page="<%= "index.jsp?page=" + pages_number + "&u=" + thisProduct %>" 
                    />');"><mm:field name="products.title" /></a><br>
            </mm:field
            ></mm:list></td>
            <td class="cart<%= rowParity %>" style="padding-right:0px;">
            <table cellspacing="0" cellpadding="0" width="100%">
                <tr>
                <td width="45%"><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
                <td class="titlebar" style="vertical-align:middle;padding-left:1px;padding-right:1px;"><input type="text" name="numberof<%= thisProduct %>" class="cart" value="<%= numberOfItems %>"></td>
                <td width="45%" background="media/pointer.gif" style="background-repeat:repeat-x;background-position: right center;"><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
                </tr>
            </table>
            </td>
            <td class="cart<%= rowParity %>" style="padding-left:0px;">
            <table cellspacing="0" cellpadding="0" width="100%">
                <tr>
                <td width="45%" background="media/pointer.gif" style="background-repeat:repeat-x;background-position: right center;"><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
                <td style="vertical-align:middle;"><a href="javascript:changeIt('<mm:url referids="portal" 
                    page="<%= "index.jsp?page=bestel&t=change" %>" />');" 
                    ><img src="../mmbase/style/images/next.gif" border="0" alt="aantal wijzigen"></a></td>
                <td width="45%"><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
                </tr>
            </table>
            </td>
            <td class="cart<%= rowParity %>" style="font-size:12px;padding-right:19px;padding-left:0px;text-align:right;"><% 
                if(price!=-1) { 
                    %>&euro;&nbsp;<%= nf.format(((double) price )/100) %><%
                } else { 
                    %>unspecified<% 
                } %></td>
            <td class="cart<%= rowParity %>" style="font-size:12px;padding-right:5px;padding-left:0px;text-align:right;"><% 
                if(price!=-1) { 
                    int total = price*numberOfItems;
                    if(totalSum!=-1) totalSum += total;
                    %>&euro;&nbsp;<%= nf.format(((double) total  )/100) %><%
                } else {
                    totalSum = -1;
                    %>unspecified<% 
                } %></td>
            <td class="cart<%= rowParity %>"><a href="javascript:changeIt('<mm:url referids="portal" 
                page="<%= "index.jsp?page=bestel&u=" + thisProduct + "&t=delete" %>" />');" 
                ><img src="../mmbase/style/images/delete.gif" border="0" alt="verwijder dit artikel"></a></td>
            </tr>
            <tr><td colspan="6" width="100%" class="titlebar"><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td></tr>
        <%
        if(discount>0) {
            if(rowParity.equals("even")) { rowParity = "odd"; } else { rowParity = "even"; }
            int totaldiscount = discount*numberOfItems;
            if(totalSum!=-1) totalSum -= totaldiscount;
            %><tr>
            <td class="cart<%= rowParity %>" style="text-align:left;" colspan="3">Korting op <mm:field name="title" /></td>
            <td class="cart<%= rowParity %>" style="font-size:12px;padding-right:19px;padding-left:0px;text-align:right;">&euro;&nbsp;<%= nf.format(((double) discount  )/100) %></td>
            <td class="cart<%= rowParity %>" style="font-size:12px;padding-right:5px;padding-left:0px;text-align:right;">&euro;&nbsp;<%= nf.format(((double) totaldiscount  )/100) %></td>
            <td class="cart<%= rowParity %>"><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
            </tr>
            <tr><td colspan="6" width="100%" class="titlebar"><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td></tr><%
        } 
        %></mm:node><%
    } 
// ************************** subtotal ***************************
%>
<tr>
    <td><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
    <td colspan="3" class="carteven"  style="text-align:left;">
        <span style="font-size:12px;font-weight:bold;">SUBTOTAL</span></td>
    <td class="carteven" style="font-size:12px;padding-right:5px;text-align:right;"><% 
        if(totalSum!=-1) { 
            %>&euro;&nbsp;<%= nf.format(((double) totalSum  )/100) %><%
        } else {
            %>unspecified<% 
        } %></td>
    <td><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
</tr>
<%@include file="../includes/getgeneraldiscount.jsp" %><%

// ************************** general discounts ***************************
if(generaldiscount>0) {
    %><tr>
        <td><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
        <td colspan="3" class="carteven"  style="text-align:left;">
            <span style="font-size:12px;font-weight:bold;">DISCOUNT</span></td>
        <td class="carteven" style="font-size:12px;padding-right:5px;padding-left:0px;text-align:right;"><% 
            if(totalSum!=-1) { 
                %>&euro;&nbsp;<%= nf.format(((double) generaldiscount  )/100) %><%
            } else {
                %>unspecified<% 
            } %></td>
        <td><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
    </tr><%
}
// ************************** shipping costs and donation ***************************
%><tr>
    <td><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
    <td colspan="3" class="carteven"  style="text-align:left;padding-top:0px;">
        <span style="font-size:12px;font-weight:bold;">SHIPPING COSTS</span></td>
    <td class="carteven" style="font-size:12px;padding-right:5px;padding-left:0px;text-align:right;padding-top:0px;">
        &euro;&nbsp;<%= nf.format(((double) shippingCosts)/100) %></td>
    <td><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
</tr>
<tr>
    <td><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
    <td colspan="3" class="carteven"  style="text-align:left;padding-top:0px;">
        <span style="font-size:12px;font-weight:bold;">DONATION</span><br>
            
    </td>
    <td class="carteven" style="padding:0px;">
        <table cellspacing="0" cellpadding="0" width="100%">
            <tr>
            <td style="text-align:right;padding-right:2px;width:99%;">&euro;</td>
            <td class="titlebar" style="vertical-align:middle;padding-left:1px;padding-right:1px;">
                <input type="text" name="donation" class="cart" style="width:43px;text-align:right;" value="<%= nf.format(((double) donation)/100) %>"></td>
            </tr>
        </table>
    </td>
    <td class="carteven" style="padding:0px;padding-top:1px;">
        <table cellspacing="0" cellpadding="0" width="100%">
            <tr>
            <td background="media/pointer.gif" style="width:10%;background-repeat:repeat-x;background-position: right center;"></td>
            <td style="vertical-align:middle;"><a href="javascript:changeIt('<mm:url referids="portal" 
                page="<%= "index.jsp?page=bestel&t=change" %>" />');">
                <img src="../mmbase/style/images/next.gif" border="0" alt="bevestig extra gift"></a></td>
            <td style="vertical-align:middle;font-size:10px;padding-left:2px;padding-right:2px;"><a href="javascript:changeIt('<mm:url referids="portal" 
                page="<%= "index.jsp?page=bestel&t=change" %>" />');" class="nav">Confirm Donation</a></td>
            </tr>
        </table>
    </td>
</tr>
<tr>
    <td><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
    <td colspan="3" class="titlebar"><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
    <td>
        <table cellspacing="0" cellpadding="0" width="80%" align="right"><tr>
            <td style="background-color:#000000;"><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
        </tr></table>
    </td>
    <td><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
</tr>
<tr>
    <td><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
    <td colspan="3" class="carteven"  style="text-align:left;"><span style="font-size:12px;font-weight:bold;">TOTAL</span></td>
    <td class="carteven" style="font-size:12px;font-weight:bold;padding-right:5px;padding-left:0px;text-align:right;"><% 
        if(totalSum!=-1) { 
            totalSum += shippingCosts + donation;
            %>&euro;&nbsp;<%= nf.format(((double) totalSum  )/100) %><%
        } else {
            %>unspecified<% 
        } %>
    </td>
    <td><img src="media/spacer.gif" width="1" height="1" border="0" alt=""></td>
</tr>
</table>
<table width="100%" cellspacing="0" cellpadding="0">
    <tr>
        <td width="80%"><img src="media/spacer.gif" height="1" width="1" border="0" alt=""></td>
        <td width="8"><img src="media/spacer.gif" height="1" width="8" border="0" alt=""></td>
        <td width="180" class="titlebar"><img src="media/spacer.gif" height="1" width="180" border="0" alt=""></td>
    </tr>
    <tr>
        <td width="80%"><img src="media/spacer.gif" height="1" width="1" border="0" alt=""></td>
        <td width="8"><img src="media/spacer.gif" height="1" width="8" border="0" alt=""></td>
        <td width="180"><%@include file="../includes/relatedshoplinks.jsp"%></td>
    </tr>
</form>
</table><%
}

formScript += "if(url!=null) { document.location =  url + href; return false; } else { return href; }"
        + "\n}";
%>
<script language="javascript" type="text/javascript">
<%= "<!--" %>
<%= formScript %>
function useEnterKey() 
{   if (window.event.keyCode == 13) changeIt('<mm:url referids="portal" page="<%= "index.jsp?page=bestel&t=change" %>" />');
} 
<%= "//-->" %>
</script> 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?