Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
code mới
Browse files Browse the repository at this point in the history
  • Loading branch information
dwttlduong committed Dec 6, 2023
1 parent 338c57a commit dd37ffd
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

String pid = request.getParameter("pid"); //duong them
String quantity = request.getParameter("quantity"); // duong them
request.getRequestDispatcher("/view/user_edit_profile.jsp").forward(request, response);
}

Expand Down Expand Up @@ -59,16 +60,15 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
// request.setAttribute("success", success);
// câu gốc response.sendRedirect("../profile");





String flag = (String) session.getAttribute("flag");//dương thêm

if (flag != null) {//dương thêm
// Điều hướng đến payment.jsp
RequestDispatcher dispatcher = request.getRequestDispatcher("/view/payment.jsp");//dương thêm
dispatcher.forward(request, response);//dương thêm

String pid = (String) request.getParameter("pid");//dương thêm
String quantity = request.getParameter("quantity");//dương thêm

response.sendRedirect(request.getContextPath() + "/payment?quantity=" + quantity + "&proId=" + pid);//dương thêm
} else {//dương thêm
response.sendRedirect("../profile");
}//dương thêm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");


HttpSession session = request.getSession();
String quantityString = request.getParameter("quantity");
String proId = request.getParameter("proId");
int quantity = Integer.parseInt(quantityString);

Product p = ProductDAO.getInstance().getById(proId);
int total=p.getPrice()*quantity;
int total = p.getPrice();
request.setAttribute("total", total);
session.getAttribute("user");

request.setAttribute("pid", proId);

request.getRequestDispatcher("/view/payment.jsp").forward(request, response);

Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<servlet-name>PaymentController</servlet-name>
<servlet-class>com.bakaqc.flower.controller.PaymentController</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HomeController</servlet-name>
<url-pattern>/home</url-pattern>
Expand Down Expand Up @@ -208,6 +209,7 @@
<servlet-name>PaymentController</servlet-name>
<url-pattern>/payment</url-pattern>
</servlet-mapping>

<session-config>
<session-timeout>
15
Expand Down
16 changes: 12 additions & 4 deletions src/main/webapp/style/payment.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
body {
background-image: linear-gradient(-90deg, #E6E2AF 0%, #002F2F 100%);
background-image: white;
}

.component {
Expand All @@ -9,12 +9,12 @@ body {
padding: 1rem;

box-shadow: 2px 2px 10px #454545;
background-color: #FFFFFF;
background-color: antiquewhite;

text-align: center;
}

.credit-card h2 {
.credit-card h1 {
color: rgba(4,99,128,1);
}

Expand Down Expand Up @@ -45,7 +45,10 @@ input {
input::-webkit-input-placeholder {
color: #AAAAAA;
}

.checkout-buttons {
display: flex;
justify-content: space-between; /* Các nút sẽ được căn giữa */
}
.valid-button {
border: 0;
padding: 1rem 2rem;
Expand All @@ -54,11 +57,13 @@ input::-webkit-input-placeholder {
font-weight:bold;
margin-top:2rem;
box-shadow: 1px 1px 1px black;
text-decoration: none;
}

.valid-button:hover {
background-color: rgba(4,99,128,1);
box-shadow: none;
text-decoration: none;
}

.total {
Expand All @@ -83,4 +88,7 @@ input::-webkit-input-placeholder {
font-size: 1.5rem;
margin: 0; /* Loại bỏ margin mặc định của các trình duyệt */
white-space: nowrap; /* Ngăn chữ xuống dòng */
}
.valid-button no-underline {
text-decoration: none;
}
110 changes: 64 additions & 46 deletions src/main/webapp/view/payment.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
session.setAttribute("flag", "payment");
%>
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -39,7 +40,7 @@
Toastify({
text: "Bạn cần đăng nhập để thanh toán",
duration: 4000, // Thời gian hiển thị thông báo (miligiây)
duration: 3500, // Thời gian hiển thị thông báo (miligiây)
destination: "http://localhost:8080/flower/login", // Đường dẫn đến trang đăng nhập
newWindow: true,
close: true,
Expand All @@ -54,62 +55,79 @@
</script>
<section class="component">
<div class="total">
<h1>TOTAL</h1>
<p id="totalValue"><script>
var formattedPrice = new Intl.NumberFormat('vi-VN', {style: 'currency', currency: 'VND'}).format(${requestScope.total});
document.write(formattedPrice);
</script> </p>
<!-- <h1>TOTAL</h1>-->
<!-- <p id="totalValue"><script>
var formattedPrice = new Intl.NumberFormat('vi-VN', {style: 'currency', currency: 'VND'}).format(${requestScope.total});
document.write(formattedPrice);
</script> </p>-->

</div>
<div class="credit-card">
<h2>Payment</h2>
<% String flag_incart = (String) session.getAttribute("flag_incart");
<h1 style="color: orange;">Thanh toán</h1>

if (flag_incart != null) {
// làm trường hợp cart
session.removeAttribute("flag_incart");
} else {%>
<form>

<c:set var="u" value="${sessionScope.user}" />
<input type="text" placeholder="NAME"value="${u.fullName}" readonly />


<!-- <div class="line"><input type="text" placeholder="CARD" /> <input type="text" placeholder="NUMBER" /> <input
type="text" /> <input type="text" /></div>
<div class="line">
<input class="litle" type="text" placeholder="EXPIRY" />
<input class="tall" type="text" placeholder="CCV" />
</div>-->
<input type="text" placeholder="sdt" value="${u.phone_number}" readonly />
<input type="text" placeholder="dc" value="${u.address}" readonly />
<%
LocalDate curDate=LocalDate.now();
String date=curDate.toString();
<input type="text" placeholder="FULLNAME"value="${u.fullName}" readonly />



<input type="text" placeholder="PHONE" value="${u.phone_number}" readonly />
<input type="text" placeholder="ADDRESS" value="${u.address}" readonly />
<%
LocalDate curDate = LocalDate.now();
String date = curDate.toString();
%>
<input type="text" placeholder="date" value="<%=date%>" readonly />
<button type="submit" class="valid-button" >CHECKOUT</button>

</form>
<%}%>
<input type="text" placeholder="DATE" value="<%=date%>" readonly />
<div>
<h2>Tổng tiền:
<script>
var formattedPrice = new Intl.NumberFormat('vi-VN', {style: 'currency', currency: 'VND'}).format(${requestScope.total});
document.write(formattedPrice);
</script>
</h2>

</div>

<div class="row checkout-buttons">

<div class="col-sm-4">
<button type="button" class="valid-button" style="background-color: orange; color: black;" onclick="redirectToDetail()">Quay lại</button>
</div>

<div class="col-sm-4">
<button type="button" class="valid-button" style="background-color: orange; color: black;" onclick="redirectToEdit()">Chỉnh sửa thông tin</button>
</div>

<div class="col-sm-4">
<button type="submit" class="valid-button" style="background-color: orange; color: black">Thanh toán</button>
</div>

</div>

</form>




</div>
</section>
<script>// Thêm đoạn mã JavaScript để đồng bộ kích thước
const totalValue = document.getElementById("totalValue");
const total = document.querySelector(".total");
function updateTotalWidth() {
total.style.width = totalValue.offsetWidth + "px";
}
// Gọi hàm cập nhật kích thước khi trang tải hoặc nội dung thay đổi
window.addEventListener("load", updateTotalWidth);
window.addEventListener("resize", updateTotalWidth);
</script>

<script>
function redirectToDetail() {
var pid = "${requestScope.pid}";
window.location.href = "detail?pid=" + encodeURIComponent(pid);
}
</script>
<script>
function redirectToEdit() {
var pid = "${requestScope.pid}";
window.location.href = "profile/edit_profile?pid=" + encodeURIComponent(pid);
}
</script>

</body>

</html>
9 changes: 3 additions & 6 deletions src/main/webapp/view/product_detail.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,14 @@
</div>
code gốc </div>-->
<form action="payment" method="get"> <!-- duong them -->
<div class="col-lg-12 product-amount">
<h5>Số lượng :</h5>
<input type="number" min="1" class="form-control text-center w-100 amount" name="quantity" value="1">
</div>

<div class="col-lg-12 mt-3">
<div class="row">
<div class="col-lg-6 pb-2">
<a href="#" class="btn btn-danger w-100">Thêm vào Giỏ Hàng</a>
<a href="#" class="btn btn-success w-100">Thêm vào Giỏ Hàng</a>
</div>
<div class="col-lg-6">
<button type="submit" class="btn btn-danger w-100">Mua Ngay</button>
<button type="submit" class="btn btn-success w-100">Mua Ngay</button>

</div>
</div>
Expand Down
18 changes: 17 additions & 1 deletion src/main/webapp/view/user_edit_profile.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@
</div>

<div class="form-group">
<div class="col-xs-6 save" style="margin-bottom: 30px;">
<div class="col-xs-6 save" style="margin-bottom: 30px;">
<br />

<input type="hidden" name="quantity" value="${param.quantity}" /> <!-- duong them-->
<input type="hidden" name="pid" value="${param.pid}" /><!-- duong them-->

<button class="btn btn-lg btn-success col-xs-12 save" type="submit">
<i class=""></i> Lưu thay đổi
</button>
Expand Down Expand Up @@ -163,6 +167,18 @@

<script src="<%=request.getContextPath()%>/js/profile.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<!-- duong them-->
<script>
$(document).ready(function() {
// Đặt giá trị cho các trường input ẩn trước khi form được submit
$("#changeInfoForm").submit(function() {
$("input[name='pid']").val("${param.pid}");
$("input[name='quantity']").val("${param.quantity}");
});
});
</script> <!-- duong them-->
</body>
</html>

0 comments on commit dd37ffd

Please sign in to comment.