Exemple #1
0
def buynow_cart(request, itemid, userid):           # Buynow button in addtocart
    if User.is_authenticated:
        login_user = User.objects.get(pk= userid)
        user = UserRegister.objects.get(user_email=login_user.email)

        ordereditem = AddToCart.objects.get(pk= itemid, cart_useremail= login_user.email)

        if Order.objects.filter(order_name= ordereditem.cart_name, order_useremail= login_user.email).exists():
            order = Order.objects.get(order_name= ordereditem.cart_name, order_useremail= login_user.email)
            return render(request, "order.html", {'order': order})

        else:
            #ordereditem = Item.objects.get(pk= itemid)
            order = Order()
            order.order_useremail = login_user.email
            order.order_name = ordereditem.cart_name
            order.order_image = ordereditem.cart_image
            order.order_price = ordereditem.cart_price
            order.order_publisher = ordereditem.cart_publisher
            order.order_description = ordereditem.cart_description
            order.order_origin = ordereditem.cart_origin
            order.order_phonenumber = user.user_phonenumber
            order.order_address = user.user_address
            order.save() 
            return render(request, "order.html", {'order': order})


    else:
        text="Please Login in to your account !!!"
        return render(request, 'note.html', {'text': text})
Exemple #2
0
def buynow(request, itemid, userid):                            # Homepage BUYNOW function
    if User.is_authenticated:
        #Request paytm to add money from user account to your account
        login_user = User.objects.get(pk= userid)
        user = UserRegister.objects.get(user_email=login_user.email)

        orderitem = Item.objects.get(pk= itemid)
        if Order.objects.filter(order_name= orderitem.item_name, order_useremail= login_user.email).exists():
            order = Order.objects.get(order_name= orderitem.item_name, order_useremail= login_user.email)
            return render(request, "order.html", {'order': order})

        else:
            ordereditem = Item.objects.get(pk= itemid)
            order = Order()
            order.order_useremail = login_user.email
            order.order_name = ordereditem.item_name
            order.order_image = ordereditem.item_image
            order.order_price = ordereditem.item_price
            order.order_publisher = ordereditem.item_publisher
            order.order_description = ordereditem.item_description
            order.order_origin = ordereditem.item_origin
            order.order_phonenumber = user.user_phonenumber
            order.order_address = user.user_address
            order.save() 
            return render(request, "order.html", {'order': order})

    else:
        text="Please Login in to your account !!!"
        return render(request, 'note.html', {'text': text})
def checkout_success(request):
    # reset the shopping cart
    cart = request.session.get('shopping_cart',{})
    customer = User.objects.get(username=request.user)

    for id, product in cart.items():
        product_object = Product.objects.get(id=id)
        newproduct = Order(
            user=customer,
            product=product_object,
        )
        newproduct.save()

    request.session['shopping_cart'] = {}
    messages.success(request, f"Your Order has been place")

    return redirect(reverse('profile'))
Exemple #4
0
 def post(self, request):
     print(request.POST)
     user = request.user
     addr = UserAddress.objects.filter(user=user,
                                       is_default=True,
                                       is_valid=True).first()
     print(addr)
     if not addr:
         data = {'status': 0, 'msg': '订单生成失败,请先设置收货地址'}
         return JsonResponse(data)
     data = {'status': 0, 'msg': '订单生成失败,请稍后重试'}
     a_id = request.POST.getlist('checkId')
     try:
         a_list = a_id[0].split(',')
     except Exception as e:
         a_list = a_id
     if a_list:
         cart_list = Cart.objects.filter(id__in=a_list)
         order = Order()
         order.user = user
         order.order_address = addr
         order.order_sn = order_sn.sn_order()
         order.goods_count = cart_list.aggregate(Sum('count'))['count__sum']
         order.order_price = cart_list.aggregate(
             Sum('total_price'))['total_price__sum']
         order.save()
         with transaction.atomic():
             for cart in cart_list:
                 order_detail = OrderDetail()
                 order_detail.order = order
                 order_detail.goods_id = cart.goods.id
                 order_detail.goods_name = cart.name
                 order_detail.goods_price = cart.price
                 order_detail.goods_number = cart.count
                 order_detail.goods_total = cart.total_price
                 order_detail.goods_image = cart.img
                 order_detail.save()
                 cart.delete()
         data['status'] = 1
         data['msg'] = '已为您成功生成订单'
     return JsonResponse(data)
Exemple #5
0
    def post(self, request, *args, **kwargs):
        print(request.POST)

        cart = Cart(request.session)

        products = [
            OrderProduct(
                product=item.product,
                price=item.price,
                quantity=item.quantity
            ) for item in cart.items
        ]
        new_order = Order(owner=request.user)

        ### PagSeguro Begin
        api = PagSeguroApiTransparent()
        api.set_sender_hash(request.POST['sender-hash'])

        sender = {
            'name': 'Joãozinho do CITi', 
            'area_code': 81, 
            'phone': 21268430, 
            'email': settings.PAGSEGURO_TEST_BUYER_EMAIL, 
            'cpf': '10683924443'
        }
        api.set_sender(**sender)

        shipping = {
            'street': 'Av. Jornalista Aníbal Fernandes', 
            'number': 1, 
            'complement': 'Centro de Informática', 
            'district': 'Cidade Universitária', 
            'postal_code': '01452002', 
            'city': 'Recife', 
            'state': 'PE', 
            'country': 'BRA',
            'cost': Decimal('0.00')
        }
        api.set_shipping(**shipping)

        if 'bank-slip' in request.POST:
            # Boleto bancário
            api.set_payment_method('boleto')
        elif 'credit-card' in request.POST:
            # Cartão de crédito
            api.set_payment_method('creditcard')

            installments = 1
            installment_amount = cart.total # Deve ser o valor da parcela obtida no browser

            data = {
                'quantity': installments, 
                'value': installment_amount, 
                'name': 'Joãozinho do CITi', 
                'birth_date': '10/02/1995', 
                'cpf': '10683924443', 
                'area_code': 81, 
                'phone': 21268430
            }
            api.set_creditcard_data(**data)

            billing = {
                'street': 'Av. Jornalista Aníbal Fernandes', 
                'number': 1, 
                'complement': 'Centro de Informática', 
                'district': 'Cidade Universitária', 
                'postal_code': '01452002', 
                'city': 'Recife', 
                'state': 'PE', 
                'country': 'BRA',
            }
            api.set_creditcard_billing_address(**billing)

            api.set_creditcard_token(request.POST['card-token'])
        
        for p in products:
            api.add_item(p.to_pagseguro())

        checkout = api.checkout()

        if checkout['success']:
            print(checkout)
        ### PagSeguro End

        new_order.save()
        for p in products:
            p.save()
            new_order.products.add(p);
        
        cart.clear()
        return HttpResponseRedirect(reverse_lazy('core:index'))