Beispiel #1
0
    def get_shopping_cart(self):
        cart = cmod.Order.objects.filter(status = 'cart', user=self).first()

        if cart is None:
            cart = cmod.Order()
            cart.user=self
            cart.save()
        return cart
 def get_shopping_cart(self):
     try:
         cart = cmod.Order.objects.get(status='cart', user=self)
     except:
         cart = cmod.Order(status='cart', user=self)
         cart.save()
         tax = cmod.OrderItem(order=cart,
                              product=cmod.Product.objects.get(name="Tax"),
                              quantity=1)
         tax.save()
     return cart
Beispiel #3
0
 def get_shopping_cart(self):
     order = cmod.Order.objects.all()
     order = order.filter(user=User.objects.get(email=self.email)).filter(status="cart").first()
     if order is None:
         print("New Order Created")
         o = cmod.Order()
         o.status = "cart"
         o.user = self
         o.save()
         return o
     else:
         print("Order not created")
         return order
Beispiel #4
0
    def get_shopping_cart(self):
        # get cart items
        cart = self.orders.filter(status='cart').first()
        if cart is None:
            new_cart = cmod.Order()
            new_cart.order_date = datetime.datetime.now()
            new_cart.status = 'cart'
            new_cart.user = self
            cart = new_cart
            cart.save()
        cart.recalculate()

        return cart
Beispiel #5
0
 def commit(self):
     
     if self.request.user.get_shopping_cart() is None:
         order = cmod.Order()
         order.user = self.request.user
         order.save()
         tax = cmod.OrderItem()
         tax.product = cmod.Product.objects.filter(name='Sales Tax').first()
         tax.quantity = 1
         tax.order = order
         tax.save()
         
     order1 = self.request.user.get_shopping_cart()
     lineItem = order1.get_item(product = self.request.product, create=True)
     lineItem.quantity = self.cleaned_data.get('quantity')
     lineItem.recalculate()
     lineItem.save()
Beispiel #6
0
    def get_shopping_cart(self):
        '''Get shopping cart. Create a new one if not already created '''
        cart = cmod.Order.objects.filter(status='cart',
                                         user_id=self.id).first()
        if cart is None:
            cart = cmod.Order()
            cart.user = self

            cart.save()

            # create tax product
            tax_product = cmod.Product.objects.get(id=75)
            tax_item = cmod.OrderItem()
            tax_item.product = tax_product
            tax_item.description = tax_product.Description
            cart.get_item(product=tax_product, create=True)

        return cart
Beispiel #7
0
    def get_shopping_cart(self):

        o1 = cmod.Order.objects.filter(user=self, name='Shopping Cart').first()
        if o1 is None:
            #create a new order
            o1 = cmod.Order()
            o1.user = self
            o1.order_date = datetime.now()
            o1.name = 'Shopping Cart'
            o1.status = 'cart'
            o1.save()

            #add the tax product
            # tax_product = cmod.Product.objects.filter(name='TaxAmount').first()
            # p1 = o1.get_item(tax_product,True)
            # p1.description = 'TaxAmount'
            # p1.save()
        return o1