Add Up Cart Totals - Django Wednesdays ECommerce 19
ฝัง
- เผยแพร่เมื่อ 4 ก.ค. 2024
- In this video we'll add a Cart Total to our Shopping Cart Summary Page.
As items get added, changed, and deleted from our Shopping Cart, we need to keep a running total of the amount of money in the cart.
We also need to determine if an item is on sale, and add accordingly..
#django #codemy #JohnElder
Timecodes
0:00 - Introduction
1:04 - Add Totals Prompt
2:30 - Add Totals To Views.py
2:52 - Create Total In Cart.py
3:46 - Get Products From DB
5:05 - Add Up Running Total
7:59 - Add Total To Cart Summary Page
8:25 - On Sale Price
10:18 - Conclusion
▶ Watch Django Wednesdays Ecommerce Playlist ✅ Subscribe To My TH-cam Channel:
bit.ly/3OBQJfN bit.ly/2IGzvOR
▶ See More At: ✅ Join My Facebook Group:
Codemy.com bit.ly/2GFmOBz
▶ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
Take 50% off with coupon code: youtube50 bit.ly/2VC9WUN
▶ Get The Code
bit.ly/47xAhWJ
Thanks so much John! once again great video :)
Glad you liked it!
Best wishes and a Happy New Year, my friend! I wish you lots of content in the new year. 😁❤
Thanks! To you too!
Thank you so much John...I really love it."My best wishes to you and your family'.It helps me alot and clearly understand your explanation.Could you please teach us how to customize orders by allowing customers to select any quantity they want, instead of limiting their selections and adding session key expire date?
Welcome!
❤This is not normal comment this is real comment I love it
ha
Hello John!
When I add some product in to the cart and remove the first product I added to the cart the totals become 0 even if I have some products in the cart.
And I have tried to check my code and your but don’t se any different things what can I do
Put it away for a few days, don't look at it. Then after a few days compare your code to mine and the error will jump right out at you. You're too close to it right now to see your mistake.
@@Codemycom thank you John 🙏🏽
My problem is TypeError can’t multiply sequence by non -int of type decimal.Decimal
what did you do differently from the video?
for some reason i had the same problem but i solved doing this
def cart_total(self):
# Get product IDS
product_ids = self.cart.keys()
# Lookup those keys in our products database model
products = Product.objects.filter(id__in=product_ids)
# Get quantities
quantities = self.cart
# Start counting at 0
total = Decimal('0.0') # Inicialize total como Decimal
for key, value in quantities.items():
# Convert key string into int so we can do math
key = int(key)
for product in products:
if product.id == key:
qty = Decimal(value) # Converta value para Decimal
if product.is_sale:
total += product.sale_price * qty
else:
total += product.price * qty
return total
Any hints or suggestions on using this code which shows individual product total which eventually get added to the final total please ?
Of course we add the individual to the final total...
@@Codemycom Trying to implement this where we could display the individual product total which finally adds up to the final total... Any suggestions on the videos I could rewatch to implement this please ?
@@MrNakul1988 You have all that information on the page already...just do some basic math and output it.
💙💙💙💚💚💚
🙂