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

Number of Items Issue Solved #93

Merged
merged 3 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions frontend/src/screens/CartScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const CartScreen = ({ match, location, history }) => {
const { cartItems } = cart

const cartItemsPrice = cartItems.reduce(
(acc, item) => acc + item.qty * item.price,
(acc, item) => acc + parseInt(item.qty) * parseInt(item.price),
0,
)
const shippingPrice =
Expand Down Expand Up @@ -79,7 +79,7 @@ const CartScreen = ({ match, location, history }) => {
<Form.Control
as="select"
size="sm"
value={item.qty}
value={parseInt(item.qty)}
onChange={(e) =>
dispatch(
addToCart(item.product, Number(e.target.value)),
Expand Down Expand Up @@ -116,7 +116,8 @@ const CartScreen = ({ match, location, history }) => {
<ListGroup variant="flush">
<ListGroup.Item>
<h5>
Subtotal ({cartItems.reduce((acc, item) => acc + item.qty, 0)})
Subtotal (
{cartItems.reduce((acc, item) => acc + parseInt(item.qty), 0)})
items
</h5>
{formatter(
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/screens/ProductScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ProductScreen = ({ match, history }) => {

const addToCartHandler = () => {
// history.push(`/cart/${match.params.id}?qty=${qty}`)
dispatch(addToCart(product._id, qty))
dispatch(addToCart(product._id, parseInt(qty)))
history.push('/cart')
}

Expand Down Expand Up @@ -123,7 +123,7 @@ const ProductScreen = ({ match, history }) => {
<Form.Control
as="select"
value={qty}
onChange={(e) => setQty(e.target.value)}
onChange={(e) => setQty(parseInt(e.target.value))}
>
{[...Array(product.countInStock).keys()].map((x) => (
<option key={x + 1} value={x + 1}>
Expand Down