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
ac519176
Commit
ac519176
authored
2 months ago
by
65160270
Browse files
Options
Downloads
Patches
Plain Diff
update-cart
parent
b59223f2
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
shop-routes/cart.js
+5
-10
5 additions, 10 deletions
shop-routes/cart.js
with
5 additions
and
10 deletions
shop-routes/cart.js
+
5
−
10
View file @
ac519176
...
...
@@ -17,22 +17,17 @@ async function calculateTotal(sessionId) {
// แสดงตะกร้าสินค้า
router
.
get
(
'
/
'
,
async
(
req
,
res
)
=>
{
try
{
if
(
!
req
.
session
.
user
)
{
return
res
.
status
(
401
).
send
(
'
Unauthorized
'
);
}
const
[
cartItems
]
=
await
pool
.
query
(
`SELECT cart_items.*, products.name, products.price, products.stock
, products.description
`SELECT cart_items.*, products.name, products.price, products.stock
FROM cart_items
JOIN products ON cart_items.product_id = products.id
WHERE
cart_items.user
_id = ?`
,
[
req
.
session
.
user
.
id
]
WHERE
session
_id = ?`
,
[
req
.
session
.
id
]
);
const
total
=
await
calculateTotal
(
req
.
session
.
user
.
id
);
const
total
=
await
calculateTotal
(
req
.
session
.
id
);
res
.
render
(
'
cart
'
,
{
cartItems
,
total
});
}
catch
(
error
)
{
console
.
error
(
"
Error fetching cart:
"
,
error
);
console
.
error
(
error
);
res
.
status
(
500
).
send
(
'
Error fetching cart
'
);
}
});
...
...
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