⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shopping_cart.jsp

📁 Sun公司Dream项目
💻 JSP
字号:
<%@ page import="java.text.*" %>



<%@ include file="common_imports.jsp" %>



<%

    pageTitle = "Shopping Cart";



    if (jspPath == null)

        jspPath = "/shop/index.jsp";



    String error = "";

    String action = request.getParameter("shop_action");

    String couponID = null;

    float couponDisc = 0.0f;

    String couponDescr = "Discount: ";

    float total = 0.0f;

    

    if ("validate_coupon".equals(action)) {

        couponID = request.getParameter("coupon_id");

        

    } else {

        couponID = (String) sessioncache.getAttribute(sessionId,"opera.coupon_id");

    }

    

    

    if (couponID != null && !"".equals(couponID.trim())) {

        String[] couponInfo = DBUtil.getRecord("SELECT value, contentid, description FROM OPERA_COUPON_INFO WHERE couponid='" 

                                + couponID + "'", new int[] {java.sql.Types.FLOAT, java.sql.Types.VARCHAR}, null, null);

        if (couponInfo == null) {

            error += couponID + ": Invalid coupon code.<br/>";

            couponID = "";



        } else {

            if (couponInfo[1] != null && couponInfo[1].equals("total")) {

                couponDisc = Float.parseFloat(couponInfo[0]);

                sessioncache.setAttribute(sessionId, "opera.coupon_id", couponID);

            } else {

                error += couponID + ": Invalid coupon code or not applicable for total.<br/>";

                couponID = "";

            }

        }



    }        

    

    if (couponID == null) couponID = "";



    String itemSQL = "SELECT meta.description, prod.price FROM SHOP_PRODUCT prod LEFT OUTER JOIN OPERA_CONTENT_METADATA meta ON prod.contentid=meta.contentid WHERE prod.contentid=?";

    //String couponSQL = "SELECT value FROM OPERA_COUPON_INFO where couponid=? AND contentid=? AND shopid=?";

    

    DecimalFormat format = new DecimalFormat("#,##0.00");        

                

%>

<%@ include file="top_body.jsp" %>



            <td width="550" valign="top">

              <table width="530" border="0" cellspacing="0" cellpadding="0">

                <tr>

                  <td>&nbsp;</td>

                </tr>                

                <tr>

                  <td>

                    <TABLE width="100%" border="1" cellspacing="0" cellpadding="3">

                      <FORM method="POST">

                      <TR>

                        <TD align="center" class="body_text"><b>Item Name</b></TD>

                        <TD align="center" class="body_text"><b>Description</b></TD>

                        <!-- <TD align="center" class="body_text"><b>Qty</b></TD> -->

                        <TD align="center" class="body_text"><b>Coupon</b></TD>

                        <TD align="center" class="body_text"><b>Price</b></TD>

                      </TR>

<%

                if (cart != null && cart.size() > 0) {

                    Set items = cart.keySet();

                    Iterator iter = items.iterator();

                    Vector itemsToBeRemoved = new Vector();

                    while(iter.hasNext()) {

                        String id = (String)iter.next();

                        int[] types = {java.sql.Types.VARCHAR, java.sql.Types.FLOAT};

                        String[] params = {id};

                        String[] fields = DBUtil.getRecord(itemSQL,types, null,params);

                        float price = Float.parseFloat(fields[1]);

                        //String qtyStr = request.getParameter("pr_" + id);

                        String qtyStr = "1";

                        if (qtyStr == null) {

                            qtyStr = (String) cart.get(id);

                            //qtyStr = "0";

                        } else {

                            try {

                                Integer.parseInt(qtyStr);//verify the input

                                cart.put(id, qtyStr);

                            } catch (Exception ex) {

                                qtyStr = (String) cart.get(id);

                            }

                        }

                        int qty = 1;

                        try {

                            qty = Integer.parseInt(qtyStr);

                        } catch (Exception ex) {}

                        

                        if (qty < 1) {

                            qty = 0;

                            qtyStr ="0";

                            itemsToBeRemoved.add(id);

                            continue;

                        }                 

                        

                        price = price * qty;

                        

                        float disc = 0.0f;

                        String couponStr = request.getParameter("coupon_id_" + id);

                        

                        if (couponStr == null || "".equals(couponStr.trim())) {

                            couponStr = (String) sessioncache.getAttribute(sessionId, "opera.coupon_id_" + id);

                            

                        }                        

                        

                        if (couponStr != null && !"".equals(couponStr.trim())) {

                            String discStr = DBUtil.getField("SELECT value FROM OPERA_COUPON_INFO WHERE couponid='"

                                    + couponStr + "' AND contentid='" + id + "'", 

                                    java.sql.Types.FLOAT, null); 

                            

                            if (discStr != null) {                            

                                try {

                                    disc = Float.parseFloat(discStr);

                                    sessioncache.setAttribute(sessionId, "opera.coupon_id_" + id, couponStr);



                                } catch (Exception ex) {

                                    couponStr = "";

                                    error += couponStr + ": Invalid coupon code for " + id + ".<br/>";

                                }

                            } else {

                                error += couponStr + ": Invalid coupon code for " + id + ".<br/>";

                                couponStr = "";

                            }                                                   

                        

                        } else {

                            couponStr = "";

                        

                        }

                        price -= disc;



%>

                      <TR>

                        <TD class="body_text"><%=id%></TD>

                        <TD class="body_text"><%=fields[0]%></TD>

                        <!-- <TD class="body_text" align="center"><INPUT name="pr_<%=id%>" value="<%=qtyStr%>" size="3"></TD> -->

                        <TD class="body_text" align="center"><INPUT name="coupon_id_<%=id%>" value="<%=couponStr%>" size="5">                        

                        </TD>

                        <TD align="right" class="body_text"><%=format.format(price)%>&nbsp;&nbsp;&nbsp;</TD>

                      </TR>



<%

                        total += price;

                    }

                    

                    for (int i =0; i < itemsToBeRemoved.size();i++)

                        cart.remove(itemsToBeRemoved.get(i));

                        

                } else {

%>    

                      <TR>

                         <TD colspan="5" align="center" class="body_text">Shopping cart is empty.</TD>

                      </TR>

  

<%

                }

%>

                      <TR>

                         <TD colspan="5" align="center">&nbsp;</TD>

                      </TR>



                      <TR>

                        <INPUT type="hidden" name="shop_action" value="validate_coupon">

                        <INPUT type="hidden" name="jsp_path" value="<%=jspPath%>">

                        <TD class="body_text">Coupon code</TD>

                        <TD width="40%" class="body_text"><INPUT size="15" name="coupon_id" value="<%=couponID%>"> 

                        </TD>

                        <TD class="body_text" colspan="2"><%=couponDescr%>&nbsp;</TD>

                        <TD class="body_text" align="right"><%=(couponDisc > 0? "-":"")%><%=format.format(couponDisc)%>&nbsp;&nbsp;&nbsp;</TD>

                      </TR>

<%

                if (couponDisc > 0.0f) {

                    if (total < couponDisc)

                        total = 0;

                    else

                        total -= couponDisc;

                }

                

%>

                      <TR>

                        <TD align="center"><INPUT type="submit" name="submit" value="Update Price"></TD>

                        <TD colspan="3" class="body_text" align="right">Total: &nbsp;&nbsp;&nbsp;</TD>

                        <TD class="body_text" align="right"><%=format.format(total)%>&nbsp;&nbsp;&nbsp;</TD>

                      </TR>

                      </FORM>

                    </TABLE>

                  </TD>     

                </TR>

                <TR>

                  <TD>&nbsp;</TD>

                </TR>

                <tr>

                  <td class="body_text" style="color:red"><%=error%></td>

                </tr>                

                <TR>

                  <TD>&nbsp;</TD>

                </TR>

                <TR>

                  <TD align="center">

                    <TABLE width="100%" cellspacing="0" cellpadding="0">

                      <TR>

                        <TD class="link" align="left"><A HREF="index.jsp"><IMG SRC="images/continue_shop.gif" border="0" alt="Continue Shopping"></A></TD>

                        <TD class="link" align="right">

            <%  

                if (cart == null || cart.size() == 0) {

            %>

            &nbsp;

            <%

                } else {



                    if(isSignin) {

            %>

                        <A HREF="payment.jsp?total_purchase=<%=total%>"><img src="images/proceed_checkout.gif" border="0" alt="Proceed Checkout"/></A></TD>

            <%

                    } else {

            %>

                        <A HREF="login.jsp?jsp_path=/shop/payment.jsp&total_purchase=<%=total%>"><img src="images/proceed_checkout.gif" border="0" alt="Proceed Checkout"/></A></TD>

            <%

                    }

                }

            %>

                      </TR>

                    </TABLE> 

                  </TD>

                </TR>

                <TR>

                  <TD>&nbsp;</TD>

                </TR>

              </table>

            </td>



<%@ include file="footer.jsp" %>

⌨️ 快捷键说明

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