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
def getProduct(pId = None, code = None): products = db.getProducts(productIds = [pId] if pId is not None else None, code = code) if len(products) > 0: return products[0] else: return None
def test_get_products_in_cart(): products = db.getProducts(userId=33) print(json.dumps(products, default=Product.serialize, sort_keys=True))
def test_products_get(): print("Testing product get..") for p in db.getProducts(sortBy='price'): print(p.productId, p.code, p.name, p.price, p.in_stock)
def getProducts(name = None, sortBy = None, minPrice = None, maxPrice = None, offset = None, limit = None, productIds = None, code=None, userId=None): if not sortBy in (None,'name', 'price'): raise Exception("Invalid parameter: sortBy; Values in 'name' or 'price' expected") return db.getProducts(name,sortBy,minPrice,maxPrice,offset,limit,productIds,code,userId)