Beispiel #1
0
def put_item(user_id, sku_id, quantity):
    product_id = sku_id
    got_it, left = sku_manager.rush(product_id)
    if not got_it:
        raise PoseidonError('In No Stock')
    sku = Sku.get(sku_id)
    price = sku.price
    CartItem.add(
        user_id=user_id, sku_id=sku_id, price=price, quantity=quantity)
    return left
Beispiel #2
0
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])
Beispiel #3
0
def delete_item(user_id, cart_item_id):
    # need add notify
    CartItem.remove(user_id, cart_item_id)
Beispiel #4
0
def get_cart(user_id):
    cart_items = CartItem.get_by_user(user_id)
    if not cart_items:
        raise PoseidonError('Cart Not Found')
    return map(serialize_model, cart_items)