Exemplo n.º 1
0
 def add(
     self,
     product,
     unit_price,
     quantity,
 ):
     try:
         item = models.Item.objects.get(
             cart=self.cart,
             product=product,
         )
     except models.Item.DoesNotExist:
         item = models.Item()
         item.cart = self.cart
         item.product = product
         item.unit_price = unit_price
         item.quantity = quantity
         item.save()
     else:
         item = models.Item.objects.get(
             cart=self.cart,
             product=product,
         )
         item.quantity = item.quantity + 1
         item.save()
Exemplo n.º 2
0
 def add(self, product, unit_price, quantity=1):
     try:
         item = models.Item.objects.get(
             cart=self.cart,
             product=product,
         )
     except models.Item.DoesNotExist:
         item = models.Item()
         item.cart = self.cart
         item.product = product
         item.unit_price = unit_price
         item.quantity = quantity
         item.save()
     else:  #ItemAlreadyExists
         item.unit_price = unit_price
         item.quantity += int(quantity)
         item.save()