Source Code Cross Referenced for ProductStoreCartAwareEvents.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » order » shoppingcart » product » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » ofbiz » org.ofbiz.order.shoppingcart.product 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         *******************************************************************************/package org.ofbiz.order.shoppingcart.product;
019:
020:        import java.util.Map;
021:
022:        import javax.servlet.http.HttpServletRequest;
023:        import javax.servlet.http.HttpServletResponse;
024:        import javax.servlet.http.HttpSession;
025:
026:        import org.ofbiz.base.util.Debug;
027:        import org.ofbiz.base.util.UtilHttp;
028:        import org.ofbiz.entity.GenericDelegator;
029:        import org.ofbiz.entity.GenericValue;
030:        import org.ofbiz.order.shoppingcart.ShoppingCart;
031:        import org.ofbiz.order.shoppingcart.ShoppingCartEvents;
032:        import org.ofbiz.order.shoppingcart.WebShoppingCart;
033:        import org.ofbiz.product.store.ProductStoreWorker;
034:
035:        /**
036:         * ProductStoreWorker - Worker class for store related functionality
037:         */
038:        public class ProductStoreCartAwareEvents {
039:
040:            public static final String module = ProductStoreCartAwareEvents.class
041:                    .getName();
042:
043:            public static String setSessionProductStore(
044:                    HttpServletRequest request, HttpServletResponse response) {
045:                Map parameters = UtilHttp.getParameterMap(request);
046:                String productStoreId = (String) parameters
047:                        .get("productStoreId");
048:
049:                try {
050:                    ProductStoreCartAwareEvents.setSessionProductStore(
051:                            productStoreId, request);
052:                } catch (Exception e) {
053:                    String errMsg = "Problem setting new store: "
054:                            + e.toString();
055:                    Debug.logError(e, errMsg, module);
056:                    request.setAttribute("_ERROR_MESSAGE_", errMsg);
057:                    return "error";
058:                }
059:
060:                return "success";
061:            }
062:
063:            public static void setSessionProductStore(String productStoreId,
064:                    HttpServletRequest request) {
065:                if (productStoreId == null) {
066:                    return;
067:                }
068:
069:                HttpSession session = request.getSession();
070:                String oldProductStoreId = (String) session
071:                        .getAttribute("productStoreId");
072:
073:                if (productStoreId.equals(oldProductStoreId)) {
074:                    // great, nothing to do, bye bye
075:                    return;
076:                }
077:
078:                GenericDelegator delegator = (GenericDelegator) request
079:                        .getAttribute("delegator");
080:
081:                // get the ProductStore record, make sure it's valid
082:                GenericValue productStore = ProductStoreWorker.getProductStore(
083:                        productStoreId, delegator);
084:                if (productStore == null) {
085:                    throw new IllegalArgumentException(
086:                            "Cannot set session ProductStore, passed productStoreId ["
087:                                    + productStoreId
088:                                    + "] is not valid/not found.");
089:                }
090:
091:                // set the productStoreId in the session (we know is different by this point)
092:                session.setAttribute("productStoreId", productStoreId);
093:
094:                // have set the new store, now need to clear out the current catalog so the default for the new store will be used
095:                session.removeAttribute("CURRENT_CATALOG_ID");
096:
097:                // if there is no locale or currencyUom in the session, set the defaults from the store, but don't do so through the CommonEvents methods setSessionLocale and setSessionCurrencyUom because we don't want these to be put on the UserLogin entity
098:                // note that this is different from the normal default setting process because these will now override the settings on the UserLogin; this is desired when changing stores and the user should be given a chance to change their personal settings after the store change
099:                UtilHttp.setCurrencyUomIfNone(session, productStore
100:                        .getString("defaultCurrencyUomId"));
101:                UtilHttp.setLocaleIfNone(session, productStore
102:                        .getString("defaultLocaleString"));
103:
104:                // if a shoppingCart exists in the session and the productStoreId on it is different, 
105:                // - leave the old cart as-is (don't clear it, want to leave the auto-save list intact)
106:                // - but create a new cart (which will load from auto-save list if applicable) and put it in the session
107:
108:                ShoppingCart cart = ShoppingCartEvents.getCartObject(request);
109:                // this should always be different given the previous session productStoreId check, but just in case...
110:                if (!productStoreId.equals(cart.getProductStoreId())) {
111:                    // this is a really simple operation now that we have prepared all of the data, as done above in this method
112:                    cart = new WebShoppingCart(request);
113:                    session.setAttribute("shoppingCart", cart);
114:                }
115:            }
116:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.