Exemplo n.º 1
0
 def readd_to_cart(self, cart):
     """
     Re-add the items of this order back to the cart.
     """
     for order_item in self.items.all():
         extra = dict(order_item.extra)
         extra.pop('rows', None)
         cart_item = order_item.product.is_in_cart(cart, **extra)
         if cart_item:
             cart_item.quantity = max(cart_item.quantity, order_item.quantity)
         else:
             cart_item = CartItemModel(cart=cart, product=order_item.product,
                                       quantity=order_item.quantity, extra=extra)
         cart_item.save()
Exemplo n.º 2
0
 def readd_to_cart(self, cart):
     """
     Re-add the items of this order back to the cart.
     """
     for order_item in self.items.all():
         extra = dict(order_item.extra)
         extra.pop('rows', None)
         cart_item = order_item.product.is_in_cart(cart, **extra)
         if cart_item:
             cart_item.quantity = max(cart_item.quantity, order_item.quantity)
         else:
             cart_item = CartItemModel(cart=cart, product=order_item.product,
                                       quantity=order_item.quantity, extra=extra)
         cart_item.save()
Exemplo n.º 3
0
 def populate_from_cart_item(self, cart_item, request):
     super(OrderItem, self).populate_from_cart_item(cart_item, request)
     # the product's unit_price must be fetched from the product's variant
     try:
         variant = cart_item.product.get_product_variant(
             product_code=cart_item.product_code)
         self._unit_price = Decimal(variant.unit_price)
     except (KeyError, ObjectDoesNotExist) as e:
         raise CartItemModel.DoesNotExist(e)
Exemplo n.º 4
0
 def populate_from_cart_item(self, cart_item, request):
     from .smartphone import SmartPhoneModel
     super(OrderItem, self).populate_from_cart_item(cart_item, request)
     # the product code and price must be fetched from the product's markedness
     try:
         if isinstance(cart_item.product, SmartPhoneModel):
             product = cart_item.product.get_product_markedness(
                 cart_item.extra['product_code'])
         else:
             product = cart_item.product
         self.product_code = product.product_code
         self._unit_price = Decimal(product.unit_price)
     except (KeyError, ObjectDoesNotExist) as e:
         raise CartItemModel.DoesNotExist(e)
Exemplo n.º 5
0
 def populate_from_cart_item(self, cart_item, request):
     """
     From a given cart item, populate the current order item.
     If the operation was successful, the given item shall be removed from the cart.
     If a CartItem.DoesNotExist exception is raised, discard the order item.
     """
     if cart_item.quantity == 0:
         raise CartItemModel.DoesNotExist("Cart Item is on the Wish List")
     self.product = cart_item.product
     # for historical integrity, store the product's name and price at the moment of purchase
     self.product_name = cart_item.product.product_name
     self._unit_price = Decimal(cart_item.product.get_price(request))
     self._line_total = Decimal(cart_item.line_total)
     self.quantity = cart_item.quantity
     self.extra = dict(cart_item.extra)
     extra_rows = [(modifier, extra_row.data)
                   for modifier, extra_row in cart_item.extra_rows.items()]
     self.extra.update(rows=extra_rows)