Skip to content
Open
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
9 changes: 7 additions & 2 deletions src/controllers/apps/ecommerce/cart.controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export const getCart = async (userId) => {
$subtract: ["$cartTotal", "$coupon.discountValue"],
},
"$cartTotal", // if there is no coupon applied we will set cart total as out final total
,
],
},
},
Expand Down Expand Up @@ -106,9 +105,15 @@ const addItemOrUpdateItemQuantity = asyncHandler(async (req, res) => {
const { quantity = 1 } = req.body;

// fetch user cart
const cart = await Cart.findOne({
let cart = await Cart.findOne({
owner: req.user._id,
});
if(!cart){
cart = await Cart.create({
owner: req.user._id,
items: []
})
}

// See if product that user is adding exist in the db
const product = await Product.findById(productId);
Expand Down