I am trying to create cart , therefore i first check for cart if it is undefined i create cart and add objects in it ,, but even thoug i add data inside req.session.cart where cart is an array it always gives undefined ,
router.get("/cartItem/:id",(req,res)=>{
pizza.findOne({_id:req.params.id}).then((docs) => {
if(typeof req.session.cart == "undefined"){
console.log(typeof req.session.cart)
req.session.cart = []
req.session.cart.push({
message:"hello world"
})
}else{
console.log("increase quantity code !!! ")
}
})
})
cart always console.logs undefiend even though i add array of objects

Aucun commentaire:
Enregistrer un commentaire