def get_shopping_cart(self): sale = cmod.Sale.objects.filter(user=self, purchased=None).first() if sale is None: sale = cmod.Sale() sale.user = self sale.save() return sale
def get_shopping_cart(self): from catalog import models as cmod cart = cmod.Sale.objects.filter(purchased=None, user=self).first() if cart is None: cart = cmod.Sale() cart.user = self cart.save() return cart
def get_shopping_cart(self): cart = cmod.Sale.objects.filter(user=self, purchased=None).first() if cart is None: cart = cmod.Sale() cart.user = self cart.recalculate() cart.save() return cart
def get_shopping_cart(self): if cmod.Sale.objects.filter(user=self, purchased=None).count() == 0: cart = cmod.Sale(user=self, purchased=None) cart.save() else: cart = cmod.Sale.objects.get(user=self, purchased=None) return cart
def process_request(request): cart = request.user.get_shopping_cart() saleitems = cmod.SaleItem.objects.filter(sale=cart, status='A') sale = cmod.Sale() categories = cmod.Category.objects.all() context = { 'categories': categories, 'cart': cart, 'saleitems': saleitems, 'sale': sale, } return request.dmp.render('receipt.html', context)
def commit(self, user): self.user = user ship = amod.ShippingAddress() ship.user = self.user ship.shipping_address = self.cleaned_data.get('address') ship.shipping_city = self.cleaned_data.get('city') ship.shipping_state = self.cleaned_data.get('state') ship.shipping_zipcode = self.cleaned_data.get('zipcode') ship.save() # Charge the user's card: stripe.api_key = 'sk_test_GSBjiFPDdOSeRPVP9ZifNmb9' charge = stripe.Charge.create( amount=self.user.cart_total(), currency="usd", description="Example charge", source=self.cleaned_data.get('stripe_token')) # record sale sale = cmod.Sale() receipt = sale.id sale.user = user sale.sale_price = cmod.ShoppingCart.calc_subtotal(user.id) sale.save() # sale item objects cart = self.user.get_cart() for c in cart: item = cmod.SaleItem() item.sale = sale item.product = c.product item.quantity = c.quantity item.sale_price = item.calc_sale_price() item.tax_amount = 5 item.save() # sale receipt thing cmod.Sale.record_sale(self.user, cart, self.cleaned_data.get('address'), self.cleaned_data.get('city'), self.cleaned_data.get('state'), self.cleaned_data.get('zipcode'), self.cleaned_data.get('stripe_token')) return sale.id
cart.quantity = 1 cart.save() cart = cmod.ShoppingCart() cart.user = user2 cart.product = p2 cart.quantity = 1 cart.save() cart = cmod.ShoppingCart() cart.user = user3 cart.product = p4 cart.quantity = 4 cart.save() sale = cmod.Sale() sale.user = user1 sale.sale_price = cmod.ShoppingCart.calc_subtotal(p1.id) sale.total_tax = cmod.ShoppingCart.calc_tax(sale.sale_price) sale.save() sale = cmod.Sale() sale.user = user2 sale.sale_price = cmod.ShoppingCart.calc_subtotal(p1.id) sale.total_tax = cmod.ShoppingCart.calc_tax(sale.sale_price) sale.save() sale = cmod.Sale() sale.user = user3 sale.sale_price = cmod.ShoppingCart.calc_subtotal(p1.id) sale.total_tax = cmod.ShoppingCart.calc_tax(sale.sale_price)