Exemplo n.º 1
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.º 2
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.º 3
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)