Exemple #1
0
def RemoveFromCart(title):
    if InCart(title):
        Cart.delete_from_cart(title, current_user.id)
        return redirect(request.args.get('next') or url_for('show_cart', user_id=current_user.id))
    else:
        flash('{} not present in Cart'.format(title))
        return redirect(url_for('show_cart', user_id=current_user.id))
Exemple #2
0
def AddToCart(title):
    if InCart(title):
        for book in cart:
            if book['book_name'] == title:
                book['quantity'] += 1
    else:
        Cart.add_to_cart(current_user.id, title, 1)
        flash('{} added to Cart'.format(title))
        return redirect(url_for('show_cart', user_id=current_user.id))
Exemple #3
0
def UpdateCart(title):
    cart = Cart.view_cart(current_user.id)
    if cart is None:
        pass
    else:
        if request.method == 'POST':
            cart = json.loads(cart)
            for book in cart:
                print(book)
                print(request.form.get('quantity'))
                Cart.update_cart(book['cart_id'], request.form.get('quantity'))
                print(book)
                flash('Cart updated Successfully!')
    return redirect(url_for('show_cart', user_id=current_user.id))
Exemple #4
0
def confirm_user_login():
    """Confirm user account information is correct."""

    user_email = request.form.get("email")
    user_password = request.form.get("password")

    try:
        # checks if user exists
        user = User.get_user_by_email(user_email)

        # get pw from db and compare it to user input
        hash = user.password

        password_check = sha256_crypt.verify(user_password, hash)

        # if everything works, log user in and create a cart
        if password_check:

            userid = user.user_id
            session['User'] = userid

            if 'Cart' not in session:
                new_cart = Cart.create_new_cart(userid)
                session['Cart'] = new_cart.cart_id

            return jsonify({"confirmed_user": True, "user_id": userid})
        else:
            raise Exception

    except Exception:
        return jsonify({"confirmed_user": False})
Exemple #5
0
def confirm_user_login():
    """Confirm user account information is correct."""

    user_email = request.form.get("email")
    user_password = request.form.get("password")

    try:
        # checks if user exists
        user = User.get_user_by_email(user_email)

        # get pw from db and compare it to user input
        hash = user.password

        password_check = sha256_crypt.verify(user_password, hash)

        # if everything works, log user in and create a cart
        if password_check:

            userid = user.user_id
            session['User'] = userid

            if 'Cart' not in session:
                    new_cart = Cart.create_new_cart(userid)
                    session['Cart'] = new_cart.cart_id

            return jsonify({"confirmed_user": True, "user_id": userid})
        else:
            raise Exception

    except Exception:
        return jsonify({"confirmed_user": False})
def Add_To_Cart(session, product_id):
    cart = Cart(product_id)
    session.add(Cart)
    session.commit()


# add_product("A STAR","$29,999.79","star.jpg","This is a star loai gave me")
Exemple #7
0
def create_cart(item_id, user_id):
    """Create and return item that has been added to cart by session user"""

    cart = Cart(item_id=item_id, user_id=user_id)

    db.session.add(cart)
    db.session.commit()

    return cart
def Add_To_Cart(productID):
    add_to_cart = Cart(productID=productID)
    session.add(add_to_cart)
    session.commit()


# add_product("Granny Smith", 75, 'GrannySmith.jpg', "S O U R city!")
# add_product("Red Delicious", 50, 'RedDelicious.jpg', "i like to eat this apple becasue it is red")
# add_product("Golden Delicious", 25, 'GoldenDelicious.jpg', "i dont like this apple becasue it is yellow")
def add_to_cart(productID):
	product=Cart(ProductID=productID)
	session.add(product)
	session.commit()


	
# add_product("Noa's Pouch","$20,000","pouch.jpg","The original pouch that Noa wore in her clip 'Pouch'")
# delete_product(1)
Exemple #10
0
def orderMemo(user_id):
    total = 0
    cart = Cart.view_cart(user_id)
    if cart is None:
        pass
    else:
        cart = json.loads(cart)
        for i in cart:
            total += i["cart_total"]
    return render_template("order_memo.html", cart=cart, total=total)
Exemple #11
0
def delete_cart(userid, cartid):
    """Create new cart and reassign session cart."""

    # create new cart
    new_cart = Cart.create_new_cart(userid)

    # update session info to reflect new cart
    session['Cart'] = new_cart.cart_id

    flash("You successfully deleted your cart. Parting is such sweet sorrow.", "delete_cart")

    return redirect("/myrecipes/%d/cart/%d" % (session['User'], session['Cart']))
Exemple #12
0
def InCart(title):
    user = current_user
    cart = Cart.view_cart(user.id)
    if cart is not None:
        cart = json.loads(cart)
        for book in cart:
            if title == book["book_name"]:
                return True
        else:
            return False
    else:
        return False
Exemple #13
0
def delete_cart(userid, cartid):
    """Create new cart and reassign session cart."""

    # create new cart
    new_cart = Cart.create_new_cart(userid)

    # update session info to reflect new cart
    session['Cart'] = new_cart.cart_id

    flash("You successfully deleted your cart. Parting is such sweet sorrow.",
          "delete_cart")

    return redirect("/myrecipes/%d/cart/%d" %
                    (session['User'], session['Cart']))
Exemple #14
0
def place_order_demo(user_id):
    total = 0
    cart = Cart.view_cart(user_id)
    if cart is None:
        pass
    else:
        cart = json.loads(cart)
        if current_user.address is not None:

                # url = "http://localhost:5000/api/user/cart/order"
                # rp = requests.get(url=url, params=str(current_user))
                Cart.cart_order(current_user.id)
                # params = {'id':current_user.id}
                #url = "http://localhost:5000/user/{}/orders".format(current_user.id)
                #rg = requests.get(url=url)
                # order = json.loads(rg.text)
                orders = User.get_orders(current_user.id)
                for book in orders:
                    total += (book.total_amount*book.qty)
                return render_template("order_memo.html", order=orders, total=total)
        else:
            flash("Enter delivery address")
            return redirect(url_for('address_form'))
Exemple #15
0
def show_cart(user_id):
    # with open('shopping_cart.json') as cart_json:
    #    cart = json.load(cart_json)
    total = 0

    if current_user.id != user_id:
        abort(403)
    else:
        cart = Cart.view_cart(user_id)
        if cart is None:
            cart = [{"book_name":" ", "quantity":" ", "price":" ", "total":" "}]
        else:
            cart = json.loads(cart)
            for i in cart:
                total += i["total"]
        return render_template("shopping_cart.html", cart=cart, total=total)
Exemple #16
0
    def add_to_cart(self, email, name, quantity):
        """Adds the product to db."""
        self.name = name
        self.quantity = quantity
        self.email = email

        customer = db.session.query(Customer).filter(
            Customer.email == self.email).first()
        product = db.session.query(Product).filter(
            Product.name == self.name).first()

        cart = Cart(customer_id=customer.customer_id,
                    product_id=product.product_id,
                    quantity=quantity)

        db.session.add(cart)
        db.session.commit()
Exemple #17
0
def check_buy_quantity(pid, uid, c, is_cart):
    result = {'flag': 0, 'quantity': 0}
    try:
        begin = time.mktime(
            time.strptime(
                time.strftime("%Y-%m-%d", time.localtime(time.time())),
                "%Y-%m-%d"))
        end = time.mktime(
            time.strptime(
                time.strftime("%Y-%m-%d 23:59:59",
                              time.localtime(time.time())),
                "%Y-%m-%d %H:%M:%S"))
        item = OrderItem.select(
            OrderItem,
            Order).join(Order).where((Order.ordered > begin)
                                     & (Order.ordered < end)
                                     & (Order.status > 0) & (Order.status < 5)
                                     & (Order.user == uid)
                                     & (OrderItem.product == pid)
                                     & (OrderItem.item_type == 0))
        cart = Cart.select().where((Cart.product == pid) & (Cart.user == uid)
                                   & (Cart.type == 0))
        cart_c = 0
        for n in cart:
            cart_c += n.quantity
        p = Product.get(id=pid)
        quantity = 0
        for n in item:
            quantity += n.quantity
        if is_cart == 1:  # 如果等于1 表示是购物车中操作
            count = quantity + c
        else:
            count = quantity + c + cart_c
        if count > p.xgperusernum:
            result['flag'] = 1
            result['quantity'] = p.xgperusernum - quantity
        if p.xgperusernum == 0:
            result['flag'] = 0
        return result
    except Exception, ex:
        return result
Exemple #18
0
def addToCart():
    current_user = get_jwt_identity()
    if not request.is_json:
        return jsonify({"msg": "Missing JSON in request"}), 400

    product_id = request.json.get('product_id')
    if not product_id:
        return jsonify({"msg": "Missing product_id parameter"}), 400

    count = request.json.get('count')
    if not count:
        return jsonify({"msg": "Missing count parameter"}), 400

    product = Product.query.filter_by(id=product_id).first()
    if not product:
        return jsonify({"msg": "Bad productId"}), 401

    user = User.query.filter_by(id=current_user).first()

    db.session.add(Cart(current_user, product_id, count))
    db.session.commit()
    return jsonify(msg="Add " + str(product_id) + " to " + str(user.name) +
                   "'s cart successfully"), 200
Exemple #19
0
def add_to_cart(Id):
    # cartproducte_object=Cart()
    cartproduct = Cart(productID=Id)
    session.add(cartproduct)

    session.commit()
def add_to_cart(session, productID):

    item = Cart(productID=productID)
    session.add(item)
    session.commit()
Exemple #21
0
def add_to_cart(productID):
    cart_object = Cart(productID=productID)
    session.add(cart_object)
    session.commit()
Exemple #22
0
def Add_To_Cart(productID):
    Add_To_Cart = Cart(productID=productID)
    session.add(Add_To_Cart)
    session.commit()
Exemple #23
0
 def render(self):
     user = self.current_user
     client_car = self.handler.get_secure_cookie('car', None)
     list = []
     count = 0
     totalprice = 0
     carproduct = {
         'name': '',
         'price': 0,
         'oprice': 0,
         'quantity': 0,
         'imgurl': '',
         'pid': 0,
         'standardname': '',
         'sku': '',
         'psid': '',
         'is_activity': 0,
         'psid': 0,
         'gid': 0,
         'store_name': '',
         'ourprice': 0,
         'pf_price': 0
     }
     carItems = []
     giftItems = []
     if client_car:
         carItems = simplejson.loads(client_car)
     if user:
         for pro in carItems:
             cart = Cart.select().where(
                 (Cart.user == user.id) &
                 (Cart.product == pro['pid']))  # & (Cart.type != 2)
             if cart.count() > 0:
                 cart[0].quantity += int(pro['quantity'])
                 cart[0].save()
             else:
                 c1 = Cart()
                 c1.user = user.id
                 c1.product = pro['pid']
                 c1.product_standard = pro['psid']
                 c1.quantity = pro['quantity']
                 c1.save()
         cartitems = Cart.select().where(
             (Cart.user == self.current_user.id))  # & (Cart.type != 2)
         self.handler.clear_cookie('car')
         for i in cartitems:
             c = copy.deepcopy(carproduct)
             c['name'] = i.product.name
             pa = check_activity(i.product.id)
             if pa:
                 c['price'] = pa["price"]
                 c['quantity'] = 1
                 c['is_activity'] = 1
             else:
                 if i.type == 3 and i.product_offline:
                     c['price'] = i.product_offline.price
                     c['store_name'] = i.product_offline.store.name
                     totalprice += float(i.product_offline.price) * float(
                         i.quantity)
                 elif i.type == 2:
                     pr = Product_Reserve.select().where(
                         Product_Reserve.product_standard ==
                         i.product_standard)
                     if pr.count() > 0:
                         c['price'] = pr[0].price
                         totalprice += float(pr[0].price) * float(
                             i.quantity)
                 else:
                     if user.grade == 0:
                         c['price'] = i.product_standard.price
                         totalprice += float(
                             i.product_standard.price) * float(i.quantity)
                     elif user.grade == 1:
                         c['price'] = i.product_standard.ourprice
                         totalprice += float(
                             i.product_standard.ourprice) * float(
                                 i.quantity)
                     elif user.grade == 1:
                         c['price'] = i.product_standard.pf_price
                         totalprice += float(
                             i.product_standard.pf_price) * float(
                                 i.quantity)
                 c['quantity'] = i.quantity
             c['oprice'] = i.product_standard.orginalprice
             c['ourprice'] = i.product_standard.ourprice
             c['pf_price'] = i.product_standard.pf_price
             c['standardname'] = i.product_standard.name
             c['psid'] = i.product_standard.id
             c['imgurl'] = i.product.cover
             c['pid'] = i.product.id
             c['sku'] = i.product.sku
             c['psid'] = i.product_standard.id
             count += int(i.quantity)
             list.append(c)
         current_time = time.strptime(
             time.strftime('%Y-%m-%d %H:%M:%S',
                           time.localtime(time.time())),
             '%Y-%m-%d %H:%M:%S')
         giftitem = Gift.select().where(
             (Gift.user == self.current_user.id) & (Gift.status == 0)
             & (Gift.end_time > time.mktime(current_time)))
         for i in giftitem:
             c = copy.deepcopy(carproduct)
             c['name'] = i.product.name
             c['price'] = 0.0
             c['quantity'] = i.quantity
             c['oprice'] = i.product_standard.orginalprice * i.product_standard.weight / 500
             c['ourprice'] = i.product_standard.ourprice
             c['pf_price'] = i.product_standard.pf_price
             c['standardname'] = i.product_standard.name
             c['psid'] = i.product_standard.id
             c['imgurl'] = i.product.cover
             c['pid'] = i.product.id
             c['sku'] = i.product.sku
             c['is_activity'] = 1
             c['gid'] = i.id
             if i.product.status == 1:
                 c['status'] = 1
             else:
                 c['status'] = 2
             giftItems.append(c)
             count += i.quantity
     else:
         for i in carItems:
             c = copy.deepcopy(carproduct)
             p = Product.get(id=i['pid'])
             ps = ProductStandard.get(id=i['psid'])
             c['name'] = p.name
             pa = check_activity(i['pid'])
             if pa:
                 c['price'] = pa["price"]
                 c['quantity'] = 1
                 c['is_activity'] = 1
             else:
                 c['price'] = ps.price
                 c['quantity'] = i['quantity']
             c['oprice'] = ps.orginalprice
             c['standardname'] = ps.name
             c['psid'] = ps.id
             c['imgurl'] = p.cover
             c['pid'] = i['pid']
             c['sku'] = p.sku
             c['psid'] = i['psid']
             totalprice += float(ps.price) * float(i['quantity'])
             count += int(i['quantity'])
             list.append(c)
     return self.render_string("layout/mycart.html",
                               cartitems=list,
                               count=count,
                               gift_items=giftItems,
                               totalprice=totalprice)
Exemple #24
0
def add_to_cart(session, product_id):
    cart_object = Cart(product_id=product_id)
    session.add(cart_object)
    session.commit()
def add_to_cart(ProductID):

	Cart_object=Cart(
		ProductID=ProductID)
	session.add(Cart_object)
	session.commit()
Exemple #26
0
def add_cort(Productid):
    cart = Cart(Productid=Productid)
    session.add(cart)
    session.commit()
def Add_to_Cart(productID):
	cart_object = Cart()
	cart_object.productID = productID
	session.add(cart_object)
	session.commit()
def add_To_Cart(productID):

    carts = Cart(
        productID=productID)
    session.add(carts)
    session.commit()