Exemplo n.º 1
0
def cart_update(request):
	if request.method=="POST":
		#POST 값 받아오기
		item_id_list = request.POST.getlist('item_id')
		option_id_list = request.POST.getlist('option_id')
		quantity_list = request.POST.getlist('quantity')
		#있는거 번호 체크
		num_list = []
		for i, item in enumerate(quantity_list):
			if item != '0':
				num_list.append(i)
		#카트 있는지 체크
		cart_exist_check = Cart.objects.filter(user = request.user).order_by('cart_id')
		if(cart_exist_check):
			#카트 있으면 있는거에 집어넣기
			new_cart_id = cart_exist_check[0].cart_id
		else:
			#카트 없으면 카트 아이디 만들고 집어넣기
			new_cart_id = 'cart'+datetime.datetime.now().strftime ("%Y%m%d%H%M%S")+str(request.user)
		for i in num_list:
			new_cart = Cart(
				cart_id = new_cart_id, 
				user = request.user, 
				item = Item.objects.get(item_id = item_id_list[i]),
				item_option = ItemOption.objects.get(option_id = option_id_list[i]), 
				quantity=quantity_list[i],
				)
			new_cart.save()
	return HttpResponseRedirect(reverse("cart"))	
Exemplo n.º 2
0
def cart_update(request):
    if request.method == "POST":
        #POST 값 받아오기
        item_id_list = request.POST.getlist('item_id')
        option_id_list = request.POST.getlist('option_id')
        quantity_list = request.POST.getlist('quantity')
        #있는거 번호 체크
        num_list = []
        for i, item in enumerate(quantity_list):
            if item != '0':
                num_list.append(i)
        #카트 있는지 체크
        cart_exist_check = Cart.objects.filter(
            user=request.user).order_by('cart_id')
        if (cart_exist_check):
            #카트 있으면 있는거에 집어넣기
            new_cart_id = cart_exist_check[0].cart_id
        else:
            #카트 없으면 카트 아이디 만들고 집어넣기
            new_cart_id = 'cart' + datetime.datetime.now().strftime(
                "%Y%m%d%H%M%S") + str(request.user)
        for i in num_list:
            new_cart = Cart(
                cart_id=new_cart_id,
                user=request.user,
                item=Item.objects.get(item_id=item_id_list[i]),
                item_option=ItemOption.objects.get(
                    option_id=option_id_list[i]),
                quantity=quantity_list[i],
            )
            new_cart.save()
    return HttpResponseRedirect(reverse("cart"))
Exemplo n.º 3
0
def cart_update(request):
    if request.method == "POST":
        #POST 값 받아오기
        item_id_list = request.POST.getlist('item_id')
        option_id_list = request.POST.getlist('option_id')
        quantity_list = request.POST.getlist('quantity')
        buy_now_text = request.POST.get('buy_now')
        #있는거 번호 체크
        num_list = []
        for i, item in enumerate(quantity_list):
            if item != '0':
                num_list.append(i)
        #로그인여부 체크
        if not request.user.is_authenticated():
            #세션 키 이름으로 카트 존재하는지 확인
            if not request.session.session_key:
                request.session.create()
            cart_exist_check = Cart.objects.filter(
                cart_id=request.session.session_key).order_by('cart_id')
            if (cart_exist_check):
                #있으면 거기다 추가
                new_cart_id = cart_exist_check[0].cart_id
            else:
                #익명유저다 그러면
                new_cart_id = request.session.session_key
            for i in num_list:
                new_cart = Cart(
                    cart_id=new_cart_id,
                    item=Item.objects.get(item_id=item_id_list[i]),
                    item_option=ItemOption.objects.get(
                        option_id=option_id_list[i]),
                    quantity=quantity_list[i],
                )
                new_cart.save()
        else:
            #카트 있는지 체크
            cart_exist_check = Cart.objects.filter(
                user=request.user, order_flag=False).order_by('cart_id')
            if (cart_exist_check):
                #카트 있으면 있는거에 집어넣기
                new_cart_id = cart_exist_check[0].cart_id
            else:
                #카트 없으면 카트 아이디 만들고 집어넣기
                new_cart_id = 'cart' + datetime.datetime.now().strftime(
                    "%Y%m%d%H%M%S") + str(request.user)
            for i in num_list:
                new_cart = Cart(
                    cart_id=new_cart_id,
                    user=request.user,
                    item=Item.objects.get(item_id=item_id_list[i]),
                    item_option=ItemOption.objects.get(
                        option_id=option_id_list[i]),
                    quantity=quantity_list[i],
                )
                new_cart.save()
        if buy_now_text == 'buy_now':
            return redirect('order_info')
    return HttpResponseRedirect(reverse("cart"))
Exemplo n.º 4
0
def add_cart(reguest):
    args={}
    args.update(csrf(reguest))
    if reguest.POST:
        args['car'] = Car.objects.get(id=reguest.POST.get('id',''))
        de=Cart(vehicle= Car.objects.get(id=reguest.POST.get('id','')),
                user=User.objects.get(id= auth.get_user(reguest).id),
                quantity=reguest.POST.get('quantity',''))
        de.save()
    return redirect('/order/cart/')
Exemplo n.º 5
0
def cart_update(request):
	if request.method=="POST":
		#POST 값 받아오기
		item_id_list = request.POST.getlist('item_id')
		option_id_list = request.POST.getlist('option_id')
		quantity_list = request.POST.getlist('quantity')
		buy_now_text = request.POST.get('buy_now')
		#있는거 번호 체크
		num_list = []
		for i, item in enumerate(quantity_list):
			if item != '0':
				num_list.append(i)
		#로그인여부 체크
		if not request.user.is_authenticated():
			#세션 키 이름으로 카트 존재하는지 확인
			if not request.session.session_key:
				request.session.create()
			cart_exist_check = Cart.objects.filter(cart_id=request.session.session_key).order_by('cart_id')
			if(cart_exist_check):
				#있으면 거기다 추가
				new_cart_id = cart_exist_check[0].cart_id
			else :			
				#익명유저다 그러면
				new_cart_id = request.session.session_key
			for i in num_list:
				new_cart = Cart(
					cart_id = new_cart_id, 
					item = Item.objects.get(item_id = item_id_list[i]),
					item_option = ItemOption.objects.get(option_id = option_id_list[i]), 
					quantity=quantity_list[i],
					)
				new_cart.save()
		else:
			#카트 있는지 체크
			cart_exist_check = Cart.objects.filter(user = request.user, order_flag=False).order_by('cart_id')
			if(cart_exist_check):
				#카트 있으면 있는거에 집어넣기
				new_cart_id = cart_exist_check[0].cart_id
			else:
				#카트 없으면 카트 아이디 만들고 집어넣기
				new_cart_id = 'cart'+datetime.datetime.now().strftime ("%Y%m%d%H%M%S")+str(request.user)
			for i in num_list:
				new_cart = Cart(
					cart_id = new_cart_id, 
					user = request.user, 
					item = Item.objects.get(item_id = item_id_list[i]),
					item_option = ItemOption.objects.get(option_id = option_id_list[i]), 
					quantity=quantity_list[i],
					)
				new_cart.save()
		if buy_now_text == 'buy_now':
			return redirect('order_info')
	return HttpResponseRedirect(reverse("cart"))	
Exemplo n.º 6
0
Arquivo: utils.py Projeto: wooshe/Shop
def getCart(request):
    try:
        cart_id = request.session['cart_id']
        cart = Cart.objects.get(id=cart_id)
        cart.sk = str(request.session.session_key)
        cart.save()
    except:
        cart = Cart()
        cart.sk = str(request.session.session_key)
        cart.save()
        request.session['cart_id'] = cart.id
    return cart
Exemplo n.º 7
0
 def create_or_update_cart(self, order, items):
     for item in items['all']:
         product = item['product']
         item['order'] = order.id
         item['product'] = product.id
         cart_item = CartSerializer(data=item)
         if not cart_item.is_valid():
             raise ValidationError(cart_item.errors)
         data = cart_item.data
         data['order'] = order
         data['product'] = product
         data['price'] = product.price
         item_obj = Cart(**data)
         item_obj.save()
Exemplo n.º 8
0
def checkout(request):
    if request.method == 'POST':
        dataDictionary = json.loads(request.body)
        # print dataDictionary

        mallId = dataDictionary['mallId']
        userId = dataDictionary['userId']
        cart = dataDictionary['cart']

        user = User.objects.get(id=userId)
        mall = Mall.objects.get(id=mallId)
        order = Order(user=user, mall=mall)

        generateUniqueTransactionId(order)

        mall = Mall.objects.get(id=mallId)

        items = Item.objects.filter(mall_id=mall.id)
        itemList = []
        for item in items:
            dic = {
                "itemId": item.id,
                "itemName": item.itemName,
                "description": item.description,
                "price": item.price,
                "unit": item.unit,
                "barcode": item.barcode
            }
            itemList.append(dic)

        amountToPay = 0
        for cartItem in cart:
            item = Item.objects.get(id=cartItem['itemId'])
            cartObject = Cart(item=item,
                              quantity=cartItem['quantity'],
                              order=order)
            cartObject.save()
            amountToPay += item.price * cartItem['quantity']

        args = {
            "success": True,
            "transactionId": order.transactionId,
            "amountToPay": amountToPay,
            "message": "Order created sussessfully"
        }
        return HttpResponse(json.dumps(args), content_type="application/json")
    else:
        status = {"status": False, "message": "Send Post request"}
        return HttpResponse(json.dumps(status),
                            content_type="application/json")
Exemplo n.º 9
0
def add_to_cart(request):
    itemId = request.GET.get('itemId')
    carts = Cart.objects.filter(item_id=itemId).filter(user=request.user)
    if carts.exists():
        cart_obj = carts.first()
        cart_obj.num = cart_obj.num + 1
    else:
        cart_obj = Cart()
        cart_obj.item_id = itemId
        cart_obj.user = request.user
    cart_obj.save()
    data = {
        'status': 200,
        'msg': "An item has been added to cart successfully!",
        'num': cart_obj.num,
    }
    return JsonResponse(data=data)
Exemplo n.º 10
0
def checkout(request):
    if request.method == 'POST':
        dataDictionary = json.loads(request.body)
        # print dataDictionary

        mallId = dataDictionary['mallId']
        userId = dataDictionary['userId']
        cart = dataDictionary['cart']

        user = User.objects.get(id = userId)
        mall = Mall.objects.get(id = mallId)
        order = Order(user = user,mall = mall)

        generateUniqueTransactionId(order)



        mall = Mall.objects.get(id = mallId)

        items = Item.objects.filter(mall_id = mall.id)
        itemList = []
        for item in items:
            dic = {"itemId":item.id,"itemName":item.itemName, "description":item.description, "price":item.price,"unit":item.unit,"barcode": item.barcode}
            itemList.append(dic)

        amountToPay = 0
        for cartItem in cart:
            item = Item.objects.get(id = cartItem['itemId'])
            cartObject = Cart(item = item, quantity = cartItem['quantity'],order = order)
            cartObject.save()
            amountToPay += item.price *cartItem['quantity']

        args = { "success": True, "transactionId":order.transactionId, "amountToPay":amountToPay, "message":"Order created sussessfully"}
        return HttpResponse(json.dumps(args), content_type = "application/json")
    else:
        status = {"status" :False,"message": "Send Post request" }
        return HttpResponse(json.dumps(status), content_type = "application/json")