18. Add and remove products on cart
Now we will implement the functionality to add and remove products from our cart.
Adding a product
if request.user.is_authenticated:
client = request.user.client
else :
return redirect('store')
order, created = Order.objects.get_or_create(client=client, finished=False)
item_stock = ItemStock.objects.get(product__id=product_id, size=size, color=color_id) #? In the forms we enter the color, id, and the size
item_ordered, created = OrderedItem.objects.get_or_create(order=order, itemstock=item_stock) #? adding the product to the cart
item_ordered.quantity += 1
item_ordered.save() #? Must save changes made directly to a elementModifying product quantity

Last updated