Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <body>
- <h1>Your cart</h1>
- <form action="/order_placed" method="get">
- <table id="table">
- <tr>
- <th>Product ID</th>
- <th>Name</th>
- <th>Brand</th>
- <th>Rating</th>
- <th>Price</th>
- <th>quantity</th>
- <tr th:each="product : ${checkout}">
- <td th:text="${product.productId}"></td>
- <td th:text="${product.productName}"></td>
- <td th:text="${product.brand}"></td>
- <td th:text="${product.rating}"></td>
- <td th:text="${product.price}"></td>
- <td><input type="text" placeholder="insert quantity" id="quantity" required></td></tr>
- </table>
- <br><br>
- <input type="text" id="notes" name="customernotes" placeholder="Enter notes here...">
- <br><br>
- <span id="sum" style="font-size: larger"></span>
- <script>
- var table = document.getElementById("table"), sumVal = 0;
- for (var i = 1; i < table.rows.length; i++) {
- sumVal += parseInt(table.rows[i].cells[4].innerHTML);
- }
- document.getElementById("sum").innerHTML = "Total payment sum =" + sumVal;
- </script>
- <br><br>
- <button class="button button1" id="btn" type="submit" onclick="myfunction()">Place your order</button>
- <br><br>
- <script>
- function myfunction() {
- var tsum = document.getElementById("sum").innerHTML.split("=")[1];
- var cnotes = document.getElementById("notes").value;
- var xhttp = new XMLHttpRequest();
- xhttp.open("GET","/order_placed" + '?cusnotes=' + cnotes + '&totalsum=' + tsum,true);
- xhttp.send();
- }
- </script>
- </form>
- @RequestMapping("/checkout")
- public ModelAndView checkout(@CookieValue("clientidcookie") String clientid){
- ModelAndView mav = new ModelAndView("checkout");
- Configuration cfg = new Configuration();
- cfg.configure("hibernate.cfg.xml");
- SessionFactory factory = cfg.buildSessionFactory();
- Session session = factory.openSession();
- Session session_for_db = factory.openSession();
- ArrayList<CartEntity> carts = (ArrayList<CartEntity>)session.createQuery("from CartEntity ").list();
- ArrayList<ProductsEntity> products = (ArrayList<ProductsEntity>)session_for_db.createQuery("from ProductsEntity ").list();
- ArrayList<ProductsEntity> res = new ArrayList<ProductsEntity>();
- for(CartEntity c: carts){
- if (c.getClientId().equals(clientid)){
- for(ProductsEntity p: products){
- if (p.getProductId().equals(c.getProductId())){
- res.add(p);
- }
- }
- }
- }
- mav.addObject("checkout",res);
- session.close();
- factory.close();
- return mav;
- }
- <?xml version='1.0' encoding='utf-8'?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD//EN"
- "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <property name="connection.url">jdbc:mysql://localhost:3306/theprocess?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC</property>
- <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
- <property name="connection.username">root</property>
- <property name="connection.password">Amit4089</property>
- <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
- <!-- DB schema will be updated if needed -->
- <property name="hbm2ddl.auto">update</property>
- <mapping class="com.example.WebAppProcess20.Entities.ClientsEntity"/>
- <mapping class="com.example.WebAppProcess20.Entities.InvoicesEntity"/>
- <mapping class="com.example.WebAppProcess20.Entities.OrdersEntity"/>
- <mapping class="com.example.WebAppProcess20.Entities.OrdersitemsEntity"/>
- <mapping class="com.example.WebAppProcess20.Entities.ProductsEntity"/>
- <mapping class="com.example.WebAppProcess20.Entities.CartEntity"/>
- </session-factory>
- </hibernate-configuration>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement