def checkout(request): context = RequestContext(request) cart = request.session['cartList'] myOrder = Order() # we have an order object now myOrder.orderDate = timezone.now() # date for the order is now # these will need to come after probably - I just want to save it myOrder.shippingCost = 1 myOrder.totalCost = 2 myOrder.save() for itemlist in cart: # remember that cart is an array of arrays that have name, quantity, price storeItem = StoreItem.objects.get(itemName=itemlist[0]) orderItem = OrderItemCorrect(order=myOrder, itemID=storeItem, itemCost=storeItem.price, itemQuantity=int(itemlist[1])) orderItem.save(force_insert=True) itemsInOrder = myOrder.orderitemcorrect_set.all() # subtotal = 0 #for orderItem in order.item: # loop through a foreign key? # subtotal += orderItem.itemCost # print "Subtotal for order: ", subtotal # order.shippingCost = 0 # insert shipping calc here... maybe? # order.totalCost = order.shippingCost + subtotal # order.save() # associate order with user return render_to_response('store/checkout.html', { 'order': myOrder, 'items': itemsInOrder, 'success': True }, context)
def checkout(request): context = RequestContext(request) cart = request.session['cartList'] myOrder = Order() # we have an order object now myOrder.orderDate = timezone.now() # date for the order is now # these will need to come after probably - I just want to save it myOrder.shippingCost = 0 myOrder.totalCost = 2 myOrder.save() for itemlist in cart: # remember that cart is an array of arrays that have name, quantity, price #orderItem = OrderItemCorrect() #print "cleaning the order item model" # orderItem.full_clean() storeItem = StoreItem.objects.get(itemNameid=itemlist[0]) orderItem = OrderItemCorrect( order = myOrder, itemID = storeItem, itemCost = storeItem.price, itemQuantity = int(itemlist[1]) ) orderItem.save(force_insert=True) itemsInOrder = myOrder.orderitemcorrect_set.all() subtotal = 0 for items in itemsInOrder: subtotal += items.itemCost * items.itemQuantity boxDimensions = boxFit(itemsInOrder) needToEmail = False weight = 0 if boxDimensions == (0, 0, 0): # determined that it needs to be a manual order needToEmail = True else: weight = getWeight(itemsInOrder) # calculate weight if it can be shipped myOrder.totalCost = subtotal + myOrder.shippingCost # shipping cost is figured out at a later point myOrder.save() cents = myOrder.totalCost * 100 return render_to_response('store/checkout.html',{'weight':weight,'boxW':boxDimensions[0],'boxH':boxDimensions[1],'boxD':boxDimensions[2],'needToEmail':needToEmail,'cents':cents,'order':myOrder, 'items':itemsInOrder, 'success': True},context)
def checkout(): form = CheckoutForm() address = Shipping_Address.query.filter_by(customer_id=current_user.get_id()).first() if address: print ('Have address') resultCart = ShoppingCart.query.filter_by(c_id=current_user.get_id()).join(Product).add_columns(Product.product_id, Product.product_name, ShoppingCart.quantity) resultaddress = Shipping_Address.query.filter_by(customer_id=current_user.get_id()) first_state = (resultaddress.first()).state #getting first address's state to populate our price column prices = [] for results in resultCart: quantity = results.quantity prod_id = results.product_id Cost_per_item = ((Cost.query.filter_by(product_id = prod_id, state=first_state)).first()).price itemprice = Cost_per_item * quantity prices.append(itemprice) totalprice = 0 for price in prices: totalprice += price zipped_data = zip(resultCart, prices) #this creates an object with 2 values, to use in our table if request.method == 'POST': print('helloworld') if 'submit_button' in request.form: ShoppingCart.query.filter_by(c_id=current_user.get_id()).delete() db.session.commit() flash(f'Checkout Succesful, your order has been placed! Redirecting to home..', 'success') creditcard = (CreditCard.query.filter_by(c_id=current_user.get_id())).first() order = Order(subtotal = totalprice, card_number=creditcard.cardnumber) db.session.add(order) db.session.commit() return redirect(url_for('home')) elif 'select_address' in request.form: print ('Updating prize') select_state = str(request.form.get("Address")) print (select_state) newprices = [] for results in resultCart: quantity = results.quantity prod_id = results.product_id Cost_per_item = ((Cost.query.filter_by(product_id = prod_id, state=select_state))).one().price itemprice = Cost_per_item * quantity newprices.append(itemprice) newtotalprice = 0 for price in newprices: newtotalprice += price new_zipped_data = zip(resultCart, newprices) return render_template('checkout.html', Cart = new_zipped_data, addresslist = resultaddress, Prices = newprices, total = newtotalprice, title = 'Checkout', form=form) else: return render_template('checkout.html', Cart = zipped_data, addresslist = resultaddress, Prices = prices, total = totalprice, title = 'Checkout', form=form) print('I am here') return render_template('checkout.html', Cart = zipped_data, addresslist = resultaddress, Prices = prices, total = totalprice, title = 'Checkout', form=form) else: flash(f'No shipping Address found. Please Add one!', 'danger') return redirect(url_for('home'))
def checkout(request): context = RequestContext(request) cart = request.session['cartList'] myOrder = Order() # we have an order object now myOrder.orderDate = timezone.now() # date for the order is now # these will need to come after probably - I just want to save it myOrder.shippingCost = 1 myOrder.totalCost = 2 myOrder.save() for itemlist in cart: # remember that cart is an array of arrays that have name, quantity, price storeItem = StoreItem.objects.get(itemName=itemlist[0]) orderItem = OrderItemCorrect( order = myOrder, itemID = storeItem, itemCost = storeItem.price, itemQuantity = int(itemlist[1]) ) orderItem.save(force_insert=True) itemsInOrder = myOrder.orderitemcorrect_set.all() # subtotal = 0 #for orderItem in order.item: # loop through a foreign key? # subtotal += orderItem.itemCost # print "Subtotal for order: ", subtotal # order.shippingCost = 0 # insert shipping calc here... maybe? # order.totalCost = order.shippingCost + subtotal # order.save() # associate order with user return render_to_response('store/checkout.html',{'order':myOrder, 'items':itemsInOrder, 'success': True},context)
def checkout(request): context = RequestContext(request) cart = request.session['cartList'] myOrder = Order() # we have an order object now myOrder.orderDate = timezone.now() # date for the order is now # these will need to come after probably - I just want to save it myOrder.shippingCost = 0 myOrder.totalCost = 2 myOrder.save() for itemlist in cart: # remember that cart is an array of arrays that have name, quantity, price #orderItem = OrderItemCorrect() #print "cleaning the order item model" # orderItem.full_clean() storeItem = StoreItem.objects.get(itemNameid=itemlist[0]) orderItem = OrderItemCorrect( order = myOrder, itemID = storeItem, itemCost = storeItem.price, itemQuantity = int(itemlist[1]) ) orderItem.save(force_insert=True) itemsInOrder = myOrder.orderitemcorrect_set.all() subtotal = 0 for items in itemsInOrder: subtotal += items.itemCost * items.itemQuantity boxDimensions = boxFit(itemsInOrder) needToEmail = False weight = 0 if boxDimensions == (0, 0, 0): # determined that it needs to be a manual order needToEmail = True else: weight = getWeight(itemsInOrder) # calculate weight if it can be shipped myOrder.totalCost = subtotal + myOrder.shippingCost # shipping cost is figured out at a later point myOrder.save() # need to cast as int for stripe to accept it cents = int(myOrder.totalCost * 100) print cents return render_to_response('store/checkout.html',{'weight':weight,'boxW':boxDimensions[0],'boxH':boxDimensions[1],'boxD':boxDimensions[2],'needToEmail':needToEmail,'cents':cents,'order':myOrder, 'items':itemsInOrder, 'success': True},context)