Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cloudupdate_prj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
65160270
cloudupdate_prj
Commits
99563091
Commit
99563091
authored
2 months ago
by
65160270
Browse files
Options
Downloads
Patches
Plain Diff
update-cart
parent
4a5cf9c5
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
shop-routes/cart.js
+1
-1
1 addition, 1 deletion
shop-routes/cart.js
shop-routes/product.js
+10
-3
10 additions, 3 deletions
shop-routes/product.js
views/product.ejs
+3
-1
3 additions, 1 deletion
views/product.ejs
with
14 additions
and
5 deletions
shop-routes/cart.js
+
1
−
1
View file @
99563091
...
@@ -35,6 +35,7 @@ router.get('/', async (req, res) => {
...
@@ -35,6 +35,7 @@ router.get('/', async (req, res) => {
// เพิ่มสินค้าลงตะกร้า
// เพิ่มสินค้าลงตะกร้า
router
.
post
(
'
/add
'
,
async
(
req
,
res
)
=>
{
router
.
post
(
'
/add
'
,
async
(
req
,
res
)
=>
{
const
{
productId
,
quantity
}
=
req
.
body
;
const
{
productId
,
quantity
}
=
req
.
body
;
console
.
log
(
"
Received:
"
,
{
productId
,
quantity
});
try
{
try
{
const
[[
product
]]
=
await
pool
.
query
(
const
[[
product
]]
=
await
pool
.
query
(
'
SELECT stock FROM products WHERE id = ?
'
,
[
productId
]
'
SELECT stock FROM products WHERE id = ?
'
,
[
productId
]
...
@@ -81,7 +82,6 @@ router.post('/add', async (req, res) => {
...
@@ -81,7 +82,6 @@ router.post('/add', async (req, res) => {
// อัพเดทจำนวนสินค้าในตะกร้า
// อัพเดทจำนวนสินค้าในตะกร้า
router
.
post
(
'
/update
'
,
async
(
req
,
res
)
=>
{
router
.
post
(
'
/update
'
,
async
(
req
,
res
)
=>
{
console
.
log
(
"
Received Data:
"
,
req
.
body
);
const
{
cartItemId
,
quantity
}
=
req
.
body
;
const
{
cartItemId
,
quantity
}
=
req
.
body
;
try
{
try
{
const
[[
cartItem
]]
=
await
pool
.
query
(
const
[[
cartItem
]]
=
await
pool
.
query
(
...
...
This diff is collapsed.
Click to expand it.
shop-routes/product.js
+
10
−
3
View file @
99563091
...
@@ -41,17 +41,24 @@ router.get("/add", (req, res) => {
...
@@ -41,17 +41,24 @@ router.get("/add", (req, res) => {
});
});
// เพิ่มสินค้าใหม่พร้อมรูป
// เพิ่มสินค้าใหม่พร้อมรูป
router
.
post
(
"
/add
"
,
upload
.
single
(
"
image
"
),
async
(
req
,
res
)
=>
{
// เปลี่ยนจาก "images" เป็น "image" ให้ตรงกับ name ของ input file
router
.
post
(
"
/add
"
,
upload
.
single
(
"
image
"
),
async
(
req
,
res
)
=>
{
console
.
log
(
"
req.file:
"
,
req
.
file
);
// ตรวจสอบว่า multer ได้รับไฟล์หรือไม่
console
.
log
(
"
req.file:
"
,
req
.
file
);
// ตรวจสอบว่า multer ได้รับไฟล์หรือไม่
console
.
log
(
"
req.body:
"
,
req
.
body
);
// ตรวจสอบค่าที่ส่งมาจากฟอร์ม
try
{
try
{
const
{
name
,
price
,
stock
,
description
}
=
req
.
body
;
// เพิ่ม description
const
{
name
,
price
,
stock
,
description
}
=
req
.
body
;
// ถ้าไม่มีไฟล์ที่อัปโหลด
if
(
!
req
.
file
)
{
console
.
error
(
"
No file uploaded.
"
);
return
res
.
status
(
400
).
send
(
"
No file uploaded.
"
);
}
const
imagePath
=
"
/uploads/
"
+
req
.
file
.
filename
;
const
imagePath
=
"
/uploads/
"
+
req
.
file
.
filename
;
await
pool
.
execute
(
await
pool
.
execute
(
"
INSERT INTO products (name, price, stock, description, image_url) VALUES (?, ?, ?, ?, ?)
"
,
"
INSERT INTO products (name, price, stock, description, image_url) VALUES (?, ?, ?, ?, ?)
"
,
[
name
,
price
,
stock
,
description
,
imagePath
]
// เพิ่ม description
[
name
,
price
,
stock
,
description
,
imagePath
]
);
);
res
.
redirect
(
"
/products
"
);
res
.
redirect
(
"
/products
"
);
...
...
This diff is collapsed.
Click to expand it.
views/product.ejs
+
3
−
1
View file @
99563091
...
@@ -13,7 +13,8 @@
...
@@ -13,7 +13,8 @@
<th>
ชื่อสินค้า
</th>
<th>
ชื่อสินค้า
</th>
<th>
ราคา
</th>
<th>
ราคา
</th>
<th>
จำนวน
</th>
<th>
จำนวน
</th>
<th>
จัดการ
</th>
<!-- เพิ่มคอลัมน์สำหรับปุ่มแก้ไข -->
<th>
คำบรรยาย
</th>
<th>
จัดการ
</th>
</tr>
</tr>
<
%
products.forEach(product =
>
{
%
>
<
%
products.forEach(product =
>
{
%
>
<tr>
<tr>
...
@@ -21,6 +22,7 @@
...
@@ -21,6 +22,7 @@
<td><
%=
product.name
%
></td>
<td><
%=
product.name
%
></td>
<td><
%=
product.price
%
>
บาท
</td>
<td><
%=
product.price
%
>
บาท
</td>
<td><
%=
product.stock
%
></td>
<td><
%=
product.stock
%
></td>
<td><
%=
product.description
%
></td>
</tr>
</tr>
<
%
});
%
>
<
%
});
%
>
</table>
</table>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment