Пример #1
0
def getShoppingCartProducts(name = None, sortBy = None, minPrice = None, maxPrice = None, offset = None, limit = None, productIds = None, code=None, userId=None):

    """here caller validation"""

    if userId == None:
        raise Exception("Error in shopping cart get; userId not given")

    products = db.getProducts(name, sortBy, minPrice, maxPrice, offset, limit, productIds, code, userId)

    cart = db.getShoppingCart(userId)

    results = []
    #Assemble products with cart information
    for p in products:
        print(p)
        """Swap 'count' entry in product with count in shopping cart of customer"""
        obj = Product.serialize(p)

        """Delete 'inStock'-entry from obj since we dont need it here"""
        del obj['inStock']

        """Add 'inCart'-entry, which tells us how many products of each type our cart has"""
        obj['inCart'] = cart.products[p.productId]

        results.append(obj)

    print(results)
    
    return results
Пример #2
0
def getShoppingCart(userId):

    """here caller validation"""

    if userId == None or userId <= 0:
        raise Exception("Error in arguments while getting user's cart")

    return db.getShoppingCart(userId)
Пример #3
0
def test_cart_add():
    print("Testing cart add..")

    cart = Cart(79)

    cart.addProduct(1)
    cart.addProduct(1)
    db.updateShoppingCart(cart)

    cart2 = db.getShoppingCart(79)
    assert(cart2 is not None)

    bl.setShoppingCart(cart)
Пример #4
0
def test_cart_serialize():
    p = db.getShoppingCart(userId=49)
    
    print(p)

    print(json.dumps(Cart.serialize(p), sort_keys=True))