Exemplo n.º 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
Exemplo n.º 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])