MERN Stack Project | Ecommerce Website | Add product to cart api - 08

  Рет қаралды 34,884

Rizwan Khan

Rizwan Khan

Күн бұрын

Пікірлер: 128
@ba-en1io
@ba-en1io 4 жыл бұрын
Thanks a lot! Please upload new videos everyday. We are waiting for your new uploads, thank you :)
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Sure everyday
@ethiopian_movie_new
@ethiopian_movie_new Жыл бұрын
i'm learning a lot of things bro you're insane
@RizwanKhanDeveloper
@RizwanKhanDeveloper Жыл бұрын
Thanks 😊
@habiburrehman00766
@habiburrehman00766 3 жыл бұрын
I have a problem, every thing is jsut fine items are adding to cart but item quantity is not updating when sending requests many times
@sonthanh1810
@sonthanh1810 3 жыл бұрын
thank you for video tutorial
@fidellistaz766
@fidellistaz766 4 жыл бұрын
i think its more clear especially for less advanced developers if you start with the client side , so that we see and we will understand better what you are talking about , because now you are talking about things that are in thin air ,its hard to keep up atleast for beginners
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
You have watched till this part just little of patience then after front end will begin and you are gonna love it
@fidellistaz766
@fidellistaz766 4 жыл бұрын
@@RizwanKhanDeveloper thank you ,I hope so ,
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Today is 15th August, Today is Independence of our Country, Happy Independence Day 🥳🥳🥳 Hit like if you are proud 🇮🇳 🇮🇳 🇮🇳
@MohammadBarghamadii
@MohammadBarghamadii 2 жыл бұрын
Thank you so much, Dear Rizwan khan
@RizwanKhanDeveloper
@RizwanKhanDeveloper 2 жыл бұрын
Most welcome
@aarshijethwa9112
@aarshijethwa9112 2 жыл бұрын
I am not getting the user id in the postman req.user._id is not working. Please help
@PlayForFun001
@PlayForFun001 2 жыл бұрын
Thanks a lot I was stuck here
@JahidHasan-zl7om
@JahidHasan-zl7om 3 жыл бұрын
user error in adding cart items , Like you I also required it true , thats whay it showing me validator error
@rahultirkey7950
@rahultirkey7950 2 жыл бұрын
Do you store cartItems in localStorage when user not login & then your user login/signup you send the data to database?
@vgagaleski
@vgagaleski 4 жыл бұрын
Amazing content! Keep up the good work!
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Thanks 😊
@mijael2430
@mijael2430 4 жыл бұрын
great dude, amazing content and keep forward!!
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Mijael Arancibia thank you so much
@ShashiKumar-lf4tz
@ShashiKumar-lf4tz 2 жыл бұрын
Greate teaching way, and thans for this effort, I am facing one issue when I am accessing data of cart for increasing quantity then showing enent error means nit recognize object format of cart data how can solve it, please tell me
@itdevelopment4590
@itdevelopment4590 2 жыл бұрын
done❤
@sheetallalwani1290
@sheetallalwani1290 4 жыл бұрын
we can take pdf as input? Or have to change img to doc?
@kebekebe2201
@kebekebe2201 4 жыл бұрын
i'm proud of you , thanks
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Your welcome my friend
@kebekebe2201
@kebekebe2201 4 жыл бұрын
@@RizwanKhanDeveloper can i ask you one somethings
@adityagoswami6881
@adityagoswami6881 3 жыл бұрын
controller/cart.js ( 22:33) In line number 16 what is the significance of _cart. and why execute the code ,Can anyone help ? Thank you ,your help is truly appreciated
@tanzimulhasib2833
@tanzimulhasib2833 3 жыл бұрын
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client please help
@bysinyor5709
@bysinyor5709 4 жыл бұрын
Hi Dude. thank you for tutorial .)
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Happy to help
@tiny-thanos
@tiny-thanos 2 жыл бұрын
How to add quantity of a product it many products are already there, I am trying to do it but everytime I add it my entire cart gets empty and only that product is left with its updated quantity
@yashuarushed1877
@yashuarushed1877 3 жыл бұрын
To Impletement cart we can use another approach create cart array in the user model, instead of creating a seperate cart model for that, I think this approach will be better, what is your opinion. Can you also tell me some pros and cons of not using that approach
@RizwanKhanDeveloper
@RizwanKhanDeveloper 3 жыл бұрын
Sounds good to me Pros : you can fetch the cart details along with user details Cons: payload might be large if you will have lots of item in your cart But overall it’s a good approach bro and you can do this type of thing only in mongodb not possible with relational database
@junangameplays3271
@junangameplays3271 4 жыл бұрын
Amazing, thanks so much !
@komalsutar5551
@komalsutar5551 4 жыл бұрын
Hello Rizwan, When can we have further uploads? Can you please share further videos' ASAP
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
kzbin.info/aero/PLB_Wd4-5SGAYsxD4JGaVdXll3PnoyI-AM
@carlosmober
@carlosmober 4 жыл бұрын
Hello, thanks for the video. Something is incorrect in my code: when I add a product { "cartItems": { "product": "5fbf5d2cad96aaa75d3217bc", "quantity": 1, "price": 1452 } } It accepts to add the first product more than one, the second product is added once, if i try to add again the second product it clear old product from database. Can you help?
@mustafaalhm9622
@mustafaalhm9622 2 жыл бұрын
you can use this if (item) { cart.cartItems.forEach(prod => { if(prod.product == product){ prod.quantity =prod.quantity + req.body.cartItems.quantity; cart.save(); res.status(200).json({cart}) } }); } else { Cart.findOneAndUpdate({ user: req.user._id }, { "$push": { "cartItems": req.body.cartItems } }) .exec((err, _cart) => { if (err) return res.status(400).json(err.message); if (_cart) return res.status(200).json({ _cart }); }) }
@MdShimul-xk9sz
@MdShimul-xk9sz 4 жыл бұрын
Thanks
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Your welcome ☺️
@arpitdamami7639
@arpitdamami7639 4 жыл бұрын
Hii Bro, in my case the quantity is showing 11 when send json second time
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Don’t worry just continue now we will work on cart again
@arpitnote5737
@arpitnote5737 4 жыл бұрын
@@RizwanKhanDeveloper okay bro.. thanks
@m0hit_m
@m0hit_m 3 жыл бұрын
Hello, Bro, I was also having the same problem so after an hour of finding error I got to know that in postman when I was giving JSON data I was providing quantity as a string rather than a number i.e "quantity": "1" rather than "quantity": 1 (correct)
@Eng.AwsNafea
@Eng.AwsNafea 2 жыл бұрын
Greate content. Can I ask why you dont use async await ?
@RizwanKhanDeveloper
@RizwanKhanDeveloper 2 жыл бұрын
No special reason I could have use async await. It’s upto you
@Eng.AwsNafea
@Eng.AwsNafea 2 жыл бұрын
@@RizwanKhanDeveloper Thank you, It is a really amazing videos
@komalsutar5551
@komalsutar5551 4 жыл бұрын
Can you please check for the below error?
@temuujinesukhei6445
@temuujinesukhei6445 4 жыл бұрын
Thank you for nice tutorial. I have problem. TypeError: Cannot read property 'product' of null at C:\Users\Xero\Desktop\mern-ecommerce\mern-back-end\src\controllers\cart.js:8:53 Also when i add to cart sometimes cartItem is shown null [ ]
@nathanwichman1503
@nathanwichman1503 4 жыл бұрын
Great tutorial! I have a question though. If you already have the cart from the db in the Cart.findOne, why do we need to do the Cart.findOneAndUpdate when we can just change that cart object returned from the findOne and then do cart.Save()? I did it this way after struggling to get it to work in the way you did it, and it seems to work fine. Is there any issue with this approach?
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
You can share current code and your approach in WebScript.info so I will get an idea and let you know whats good or bad
@rasheed9947
@rasheed9947 2 жыл бұрын
save load the documment in the memory but update dont
@resha4653
@resha4653 2 жыл бұрын
i don't know why. but this doesn't work for me. User can not add product again. Error of duplicate id occur
@ashikurrahmanmunna5431
@ashikurrahmanmunna5431 3 жыл бұрын
I have signed in with user account. But it is giving me user access denied message.
@obi.3965
@obi.3965 4 жыл бұрын
hi brother how to use async await in add items to the cart .i tried a lot but i am not able to find the solution.
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Why do u need to use async await
@obi.3965
@obi.3965 4 жыл бұрын
@@RizwanKhanDeveloper because in modern way, I should use async await or .then promises.
@giorgikirvalidze394
@giorgikirvalidze394 4 жыл бұрын
@@obi.3965 exports.addItemToCart = async (req, res) => { const oldCart = await Cart.findOne({ user: req.user._id }) if (!oldCart) { const cart = new Cart({ user: req.user._id, cartItems: req.body.cartItems }) const newCart = await cart.save() return res.status(201).json({ newCart }) } else { const updatedOldCart = await Cart.findOneAndUpdate({ user: req.user._id }, { "$push": { "cartItems": req.body.cartItems } }) await updatedOldCart.save() return res.status(200).json({ updatedOldCart }) } }
@codinghubfree
@codinghubfree 4 жыл бұрын
Great videos! but you are checking for existing items in carts and updating the quantity only. Suppose, the user has already added an item to the cart when the price was 10000 and if he again adding the same cart but now the price is 8000 then that might be the problem.
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Price will vary till checkout of the items and it’s not a problem it may increase or decrease before checkout ( place order ) but once order placed and confirmed then that will be the payable price regardless of change in price
@codinghubfree
@codinghubfree 4 жыл бұрын
@@RizwanKhanDeveloper on now i got it. Thanks
@gloriamarquez5998
@gloriamarquez5998 4 жыл бұрын
Excelente explicación, muchas gracias xD
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Gloria Márquez Thank you 😊 so much
@technoinfoworldwide2329
@technoinfoworldwide2329 4 жыл бұрын
in flipkart, user doesnt need to login to put the product in cart section.how to implement in both way like users can login and put product in cart as well as without login,visitors can put product in cart without login? please share the logic
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Already implemented that feature now you are watching Api videos plz continue you will see very soon
@vuhoang4181
@vuhoang4181 4 жыл бұрын
How to fix bug response will give old data ? Thanks u.
@bungmocuto6701
@bungmocuto6701 3 жыл бұрын
I can't see the video you fetch product, have you delete it? 😥
@sultanahmed2299
@sultanahmed2299 3 жыл бұрын
$set: { cartItems: { ...req.body.cartItems, quantity: item.quantity + req.body.cartItems.quantity, }, }, after sending response quantity stored as concat instead of sum (like if 22 or 11 instead of 4 or 2) why ??? can any one have any solutions
@RizwanKhanDeveloper
@RizwanKhanDeveloper 3 жыл бұрын
Use parseInt(item.quantity) + parseInt(req.body.cartItems.quantity)
@sultanahmed2299
@sultanahmed2299 3 жыл бұрын
@@RizwanKhanDeveloper Thank you very much .
@sowmya.s2671
@sowmya.s2671 3 жыл бұрын
Hii, I am getting user access denied message . Please help How to solve this
@RizwanKhanDeveloper
@RizwanKhanDeveloper 3 жыл бұрын
Ok we have two roles user and admin if you try access admin with user credentials then you will get access denied message
@csouvik21
@csouvik21 3 жыл бұрын
I am feeling it one small error input can make you dance
@daveglad3554
@daveglad3554 4 жыл бұрын
Thanks ❤️👌🏽
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Your welcome buddy
@Pushkar-Apte
@Pushkar-Apte 4 жыл бұрын
Amazing videos just loved your teaching style also I'm facing this error lately Error: slugify: string argument expected Can you help me with this one?
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Can u show request payload
@Pushkar-Apte
@Pushkar-Apte 4 жыл бұрын
@@RizwanKhanDeveloper var fs = require("fs"); var request = require("request"); var options = { method: 'POST', url: 'localhost:2000/api/product/create', headers: { 'postman-token': '3cfe6301-f438-ea36-91f1-9ff7b4ba8db3', 'cache-control': 'no-cache', 'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW', authorization: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZjZkZTFiYmU1YzAzMTFlYzBiZjE0OWEiLCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE2MDE1NTQwMDQsImV4cCI6MTYwMTU1NzYwNH0.qpcxi_RmdYlzYPPwwIsDoK8tH1OHt6oXTTnrtxd0jqg' }, formData: { 'name ': 'Samsung Galaxy M21 (Midnight Blue, 128 GB) (6 GB RAM)', quantity: '200', 'price ': '20000', description: ' 48MP (F2.0) Main Camera +8MP (F2.2) Ultra Wide Camera +5MP(F2.2) Depth Camera | 20MP (F2.2) front facing camera 16.21 centimeters (6.4-inch) FHD+ capacitive touchscreen with 2340 x 1080 pixels resolution 16M color support Memory, Storage & SIM: 4GB RAM | 64GB storage expandable up to 512GB| Dual SIM with dual standby (4G+4G) Android 10.0 operating system with 2.3GHz Exynos 9611-Octa Core processor 6000mAH lithium-ion battery', productPicture: { value: 'fs.createReadStream("16998176_10154218236780636_8472606700379293330_n.jpg")', options: { filename: '16998176_10154218236780636_8472606700379293330_n.jpg', contentType: null } }, category: '5f746b3479eb593b3c551574' } }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); });
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Slugify requires string argument here we are sending product name from request and we are converting name to slug using slugify so possibly you are not getting name properly
@Pushkar-Apte
@Pushkar-Apte 4 жыл бұрын
@@RizwanKhanDeveloper Thank you so much Rizwan Sir for your help means a lot also what could be the possible solution I tried different names and tried to convert the name to String as well
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Pushkar Apte First you console all data which is coming in request If you are getting name then are good to go
@sumitmourya8440
@sumitmourya8440 4 жыл бұрын
it also does not showing any error
@somyaranjankhatua7746
@somyaranjankhatua7746 3 жыл бұрын
23:02
@mubasharafzal7973
@mubasharafzal7973 4 жыл бұрын
Dear my qty update block is not working
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Share the piece of code which is not working in webscript.info
@mubasharafzal7973
@mubasharafzal7973 4 жыл бұрын
@@RizwanKhanDeveloper thanks for reply { "cartItems":[ { "product": "5f6ddf82864fe30b68340ac4", "quantity":"1", "price": "7002" } ] } i am sending json this way in post man when i remove array [] working properly thanks
@mubasharafzal7973
@mubasharafzal7973 4 жыл бұрын
please explain this
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Mubashar Afzal if this is a problem with code I will update it
@mubasharafzal7973
@mubasharafzal7973 4 жыл бұрын
@@RizwanKhanDeveloper no problem its ok all
@babipinker9091
@babipinker9091 4 жыл бұрын
Hello, thank's for this tutorial, but i think you are losing taraçability if you update the same cart item like this
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Please continue it will be fixed in coming videos
@paulfurniturebapon1566
@paulfurniturebapon1566 4 жыл бұрын
sir when i am adding first product to cart there is no issue but second time these error comes (node:7292) DeprecationWarning: Mongoose: `findOneAndUpdate()` and `findOneAndDelete()` without the `useFindAndModify` option set to false are deprecated. See: mongoosejs.com/docs/deprecations.html#findandmodify (Use `node --trace-deprecation ...` to show where the warning was created)
@paulfurniturebapon1566
@paulfurniturebapon1566 4 жыл бұрын
please help sir
@komalsutar5551
@komalsutar5551 4 жыл бұрын
"error": { "driver": true, "name": "MongoError", "index": 0, "code": 11000, "keyPattern": { "slug": 1 }, "keyValue": { "slug": null } } } I dont understand how to resolve this error
@RizwanKhanDeveloper
@RizwanKhanDeveloper 4 жыл бұрын
Slug value can’t be null
@apoorvbhushan6729
@apoorvbhushan6729 4 жыл бұрын
@Rizwan Khan can you reply fast
@pranaysuryavanshi3786
@pranaysuryavanshi3786 3 жыл бұрын
Getting an error Can't read property _id
@Lokeshjitta
@Lokeshjitta Жыл бұрын
{ "error": { "index": 0, "code": 11000, "keyPattern": { "slug": 1 }, "keyValue": { "slug": null } } } broo how to avoid this error
@prateekchoubey8530
@prateekchoubey8530 Жыл бұрын
Day 7
@taranshchellani3235
@taranshchellani3235 2 жыл бұрын
10:10
MERN Stack Project | Ecommerce Website | Product Creation Api - 07
42:01
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
This GitHub repository should be illegal
9:21
Mehul - Codedamn
Рет қаралды 2,6 М.
Shopping Cart In React Js For Newbies
31:52
Lun Dev
Рет қаралды 48 М.