def order_confirmation(request): cart_manager = CartManager(request) cart_manager.load_items() cart_manager.total_cost() total_cost_for_stripe = cart_manager.total_cost_with_tax * 100 # load main image for each cart item product, should maybe redo this main img finder product_images = [] repeated = False if hasattr(cart_manager, 'cart_items'): for cart_item in cart_manager.cart_items: img_in_list = ProductImage.find_main_product_image(cart_item.product.id) repeated = False for product_image in product_images: if product_image.pk == img_in_list.pk: repeated = True break if not repeated: product_images.append(img_in_list) repeated = False if request.method == "GET": payment_confirmation = '' elif request.POST['payment_confirmation']: payment_confirmation = float(request.POST['payment_confirmation']) else: payment_confirmation = '' # deactivate this cart now cart_manager.deactivate(request) # cant delete deactiveated carts because they are needed to load order history return render(request, 'cart/order_confirmation.html', {'cart':cart_manager.cart, 'cart_items':cart_manager.cart_items, 'product_images':product_images, 'total_cost':cart_manager.total_cost,'tax':cart_manager.tax, 'total_cost_with_tax':cart_manager.total_cost_with_tax, 'total_cost_for_stripe':total_cost_for_stripe, 'payment_confirmation':payment_confirmation, 'true_string':'True'})
def product_page(request, product_id): # get cart data from cart.models import Cart cart = Cart.get_cart(request) urls_cart = request.build_absolute_uri('/api/cart/' + str(cart.id) + '/') urls_product = request.build_absolute_uri('/api/products/' + str(product_id) + '/') if request.user.is_authenticated: username = request.user.get_username() else: username = '******' #find product and give it to template main_product = Product.objects.get(id=product_id) main_image = ProductImage.find_main_product_image(product_id) other_images = ProductImage.find_product_images(product_id) return render( request, 'products/product.html', { 'product': main_product, 'main_image': main_image, 'other_images': other_images, 'cart': cart, 'urls_cart': urls_cart, 'urls_product': urls_product, 'username': username })
def order_history(request): order_history = CheckoutDetails.objects.filter(user_id = request.user.id) cart_items_list = [] product_images = [] total_costs = [] for order in order_history: cart_items = order.cart.get_items() cart_items_list.append(cart_items) #get product images repeated = False if cart_items: for cart_item in cart_items: img_in_list = ProductImage.find_main_product_image(cart_item.product.id) repeated = False for product_image in product_images: if product_image.pk == img_in_list.pk: repeated = True break if not repeated: product_images.append(img_in_list) repeated = False #get order total cost total_cost = 0.0 for cart_item in cart_items: total_cost += (float(cart_item.product.current_price) * cart_item.quantity) total_cost = round(total_cost, 2) total_cost_with_tax = total_cost*1.13 total_cost_with_tax = round(total_cost_with_tax, 2) total_costs.append(total_cost_with_tax) order_cartitem_history = zip( order_history, cart_items_list, total_costs) return render(request, 'cart/order_history.html', {'orders':order_history, 'order_cartitem_history':order_cartitem_history, 'product_images':product_images})
def product_page(request, product_id): # get cart data cart_manager = CartManager(request) # creating the urls needed by the template to make its request to the api urls_cart = request.build_absolute_uri( '/api/cart/' + urllib.parse.quote(str(cart_manager.cart.id)) + '/') urls_product = request.build_absolute_uri( '/api/products/' + urllib.parse.quote(str(product_id)) + '/') if request.user.is_authenticated: username = request.user.get_username() else: username = '' #find product and give it to template main_product = Product.objects.get(id=product_id) main_image = ProductImage.find_main_product_image(product_id) other_images = ProductImage.find_product_images(product_id) return render( request, 'products/product.html', { 'product': main_product, 'main_image': main_image, 'other_images': other_images, 'cart': cart_manager.cart, 'urls_cart': urls_cart, 'urls_product': urls_product, 'username': username })
def product_page(request, product_id): #find product and give it to template main_product = list(Product.objects.filter(id = product_id)) main_product = main_product[0] main_image = list(ProductImage.find_main_product_image(product_id)) main_image = main_image[0] other_images = ProductImage.find_product_images(product_id) return render(request, 'products/product.html', {'product':main_product, 'main_image':main_image, 'other_images':other_images})
def order_confirmation(request): cart = Cart.get_cart(request.session['cart_id']) cart_items = cart.get_items() # load main image for each cart item product product_images = [] repeated = False if cart_items: for cart_item in cart_items: img_in_list = ProductImage.find_main_product_image( cart_item.product.id) repeated = False for product_image in product_images: if product_image.pk == img_in_list.pk: repeated = True break if not repeated: product_images.append(img_in_list) repeated = False # calculate total cost total_cost = 0.0 if cart_items: for cart_item in cart_items: total_cost += (float(cart_item.product.current_price) * cart_item.quantity) total_cost = round(total_cost, 2) tax = total_cost * 0.13 tax = round(tax, 2) total_cost_with_tax = total_cost * 1.13 total_cost_with_tax = round(total_cost_with_tax, 2) total_cost_for_stripe = total_cost_with_tax * 100 if request.method == "GET": payment_confirmation = '' elif request.POST['payment_confirmation']: payment_confirmation = float(request.POST['payment_confirmation']) else: payment_confirmation = '' #reset this val # clear out cart session and make new cart and update session with new cart # note the big difference between get_cart() and Cart.get_cart() new_cart = Cart.get_cart() request.session['cart_id'] = new_cart.id return render( request, 'cart/order_confirmation.html', { 'cart': cart, 'cart_items': cart_items, 'product_images': product_images, 'total_cost': total_cost, 'tax': tax, 'total_cost_with_tax': total_cost_with_tax, 'total_cost_for_stripe': total_cost_for_stripe, 'payment_confirmation': payment_confirmation, 'true_string': 'True' })
def get(self, request): #what we need for this page it to enable it to be able to get all data from the carts, so #all the products, their costs and total cost, main photo of each product, and ability to remove items from the cart self.cart = Cart.get_cart(request) cart_items = self.cart.get_items() # load main image for each cart item product product_images = [] repeated = False if cart_items: for cart_item in cart_items: img_in_list = ProductImage.find_main_product_image( cart_item.product.id) repeated = False for product_image in product_images: if product_image.pk == img_in_list.pk: repeated = True break if not repeated: product_images.append(img_in_list) repeated = False # calculate total cost total_cost = 0.0 if cart_items: for cart_item in cart_items: total_cost += (float(cart_item.product.current_price) * cart_item.quantity) total_cost = round(total_cost, 2) tax = total_cost * 0.13 tax = round(tax, 2) total_cost_with_tax = total_cost * 1.13 total_cost_with_tax = round(total_cost_with_tax, 2) total_cost_for_stripe = total_cost_with_tax * 100 # get stipe key stripe_key = settings.STRIPE_PUBLISHABLE_KEY return render( request, 'cart/home2.html', { 'cart': self.cart, 'cart_items': cart_items, 'product_images': product_images, 'total_cost': total_cost, 'tax': tax, 'total_cost_with_tax': total_cost_with_tax, 'stripe_key': stripe_key, 'total_cost_for_stripe': total_cost_for_stripe })
def get(self, request): self.cart = Cart.get_cart(request) cart_items = self.cart.get_items() cart_product_ids = set() product_images = [] if cart_items: for cart_item in cart_items: cart_product_ids.add(cart_item.product.id) for cart_product_id in cart_product_ids: product_images.append( ProductImage.find_main_product_image(cart_product_id)) # calculate total cost total_cost = 0.0 if cart_items: for cart_item in cart_items: total_cost += (float(cart_item.product.current_price) * cart_item.quantity) total_cost = round(total_cost, 2) tax = total_cost * 0.13 tax = round(tax, 2) total_cost_with_tax = total_cost * 1.13 total_cost_with_tax = round(total_cost_with_tax, 2) total_cost_for_stripe = total_cost_with_tax * 100 # get stipe key stripe_key = settings.STRIPE_PUBLISHABLE_KEY return render( request, 'cart/home2.html', { 'cart': self.cart, 'cart_items': cart_items, 'product_images': product_images, 'total_cost': total_cost, 'tax': tax, 'total_cost_with_tax': total_cost_with_tax, 'stripe_key': stripe_key, 'total_cost_for_stripe': total_cost_for_stripe })
def get(self, request): cart_manager = CartManager(request) cart_manager.load_items() cart_manager.total_cost() total_cost_for_stripe = cart_manager.total_cost_with_tax * 100 # load product images product_images = [] if hasattr(cart_manager, 'cart_items'): cart_product_ids = set() for cart_item in cart_manager.cart_items: cart_product_ids.add(cart_item.product.id) for cart_product_id in cart_product_ids: product_images.append(ProductImage.find_main_product_image(cart_product_id)) # get stipe key stripe_key = settings.STRIPE_PUBLISHABLE_KEY return render(request, 'cart/home.html', {'cart':cart_manager.cart, 'cart_items':cart_manager.cart_items, 'product_images':product_images, 'total_cost':cart_manager.total_cost,'tax':cart_manager.tax, 'total_cost_with_tax':cart_manager.total_cost_with_tax, 'stripe_key':stripe_key, 'total_cost_for_stripe':total_cost_for_stripe})