Advertisement
Guest User

Untitled

a guest
Aug 10th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. <body>
  2. <h1>Your cart</h1>
  3. <form action="/order_placed" method="get">
  4. <table id="table">
  5. <tr>
  6. <th>Product ID</th>
  7. <th>Name</th>
  8. <th>Brand</th>
  9. <th>Rating</th>
  10. <th>Price</th>
  11. <th>quantity</th>
  12.  
  13. <tr th:each="product : ${checkout}">
  14. <td th:text="${product.productId}"></td>
  15. <td th:text="${product.productName}"></td>
  16. <td th:text="${product.brand}"></td>
  17. <td th:text="${product.rating}"></td>
  18. <td th:text="${product.price}"></td>
  19. <td><input type="text" placeholder="insert quantity" id="quantity" required></td></tr>
  20. </table>
  21. <br><br>
  22. <input type="text" id="notes" name="customernotes" placeholder="Enter notes here...">
  23. <br><br>
  24. <span id="sum" style="font-size: larger"></span>
  25. <script>
  26. var table = document.getElementById("table"), sumVal = 0;
  27. for (var i = 1; i < table.rows.length; i++) {
  28. sumVal += parseInt(table.rows[i].cells[4].innerHTML);
  29. }
  30. document.getElementById("sum").innerHTML = "Total payment sum =" + sumVal;
  31. </script>
  32. <br><br>
  33. <button class="button button1" id="btn" type="submit" onclick="myfunction()">Place your order</button>
  34. <br><br>
  35. <script>
  36. function myfunction() {
  37. var tsum = document.getElementById("sum").innerHTML.split("=")[1];
  38. var cnotes = document.getElementById("notes").value;
  39. var xhttp = new XMLHttpRequest();
  40. xhttp.open("GET","/order_placed" + '?cusnotes=' + cnotes + '&totalsum=' + tsum,true);
  41. xhttp.send();
  42. }
  43. </script>
  44. </form>
  45.  
  46. @RequestMapping("/checkout")
  47. public ModelAndView checkout(@CookieValue("clientidcookie") String clientid){
  48. ModelAndView mav = new ModelAndView("checkout");
  49. Configuration cfg = new Configuration();
  50. cfg.configure("hibernate.cfg.xml");
  51. SessionFactory factory = cfg.buildSessionFactory();
  52. Session session = factory.openSession();
  53. Session session_for_db = factory.openSession();
  54.  
  55. ArrayList<CartEntity> carts = (ArrayList<CartEntity>)session.createQuery("from CartEntity ").list();
  56. ArrayList<ProductsEntity> products = (ArrayList<ProductsEntity>)session_for_db.createQuery("from ProductsEntity ").list();
  57. ArrayList<ProductsEntity> res = new ArrayList<ProductsEntity>();
  58. for(CartEntity c: carts){
  59. if (c.getClientId().equals(clientid)){
  60. for(ProductsEntity p: products){
  61. if (p.getProductId().equals(c.getProductId())){
  62. res.add(p);
  63. }
  64. }
  65. }
  66. }
  67. mav.addObject("checkout",res);
  68. session.close();
  69. factory.close();
  70. return mav;
  71. }
  72.  
  73. <?xml version='1.0' encoding='utf-8'?>
  74.  
  75.  
  76. <!DOCTYPE hibernate-configuration PUBLIC
  77. "-//Hibernate/Hibernate Configuration DTD//EN"
  78. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  79. <hibernate-configuration>
  80. <session-factory>
  81. <property name="connection.url">jdbc:mysql://localhost:3306/theprocess?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC</property>
  82. <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
  83. <property name="connection.username">root</property>
  84. <property name="connection.password">Amit4089</property>
  85. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  86. <!-- DB schema will be updated if needed -->
  87. <property name="hbm2ddl.auto">update</property>
  88. <mapping class="com.example.WebAppProcess20.Entities.ClientsEntity"/>
  89. <mapping class="com.example.WebAppProcess20.Entities.InvoicesEntity"/>
  90. <mapping class="com.example.WebAppProcess20.Entities.OrdersEntity"/>
  91. <mapping class="com.example.WebAppProcess20.Entities.OrdersitemsEntity"/>
  92. <mapping class="com.example.WebAppProcess20.Entities.ProductsEntity"/>
  93. <mapping class="com.example.WebAppProcess20.Entities.CartEntity"/>
  94. </session-factory>
  95. </hibernate-configuration>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement