예제 #1
0
def get_product(product_id):
    product = Product.get(product_id)
    if not product:
        raise PoseidonError('Product Not Found')
    sku = Sku.get_by_product(product_id)
    product = serialize_model(product)
    product.update(
        **serialize_model(sku))
    return product
예제 #2
0
파일: order.py 프로젝트: importcjj/poseidon
def create_order(user_id):
    cart_items = CartItem.get_by_user(user_id)
    if not cart_items:
        raise PoseidonError('Invalid Cart')
    order_price = sum([i.price * i.quantity for i in cart_items])
    order = Order.new(user_id, order_price)

    for cart_item in cart_items:
        sku_id = cart_item.sku_id
        sku = Sku.get(sku_id)
        # one match one
        product_id = sku_id
        product = Product.get(product_id)
        if not sku:
            raise PoseidonError('Invalid sku')
        item_price = cart_item.price * cart_item.quantity
        OrderItem.new(order_id=order.id,
                      user_id=user_id,
                      item_name=product.name,
                      item_quantity=cart_item.quantity,
                      item_price=item_price)
    CartItem.mremove(user_id, [item.id for item in cart_items])
예제 #3
0
def create_product(number):
    for pid in range(1, number + 1):
        name = u"我是商品{}".format(pid)
        description = u"编号:{}".format(pid)
        Product.new(name=name, description=description)
예제 #4
0
def get_chunk(offset, limit):
    products = Product.chunk(offset, limit)
    return map(serialize_model, products)