db.define_table('product',
   Field('name'),
   Field('price'))

pen = db.product.insert(name="Pen", price="8 if cart[pen]>4 else 10 if 
cart[pen]>2 else 12")

cart = {pen: 3} # 3 pens in cart

cart_total = sum(eval(p.price, cart) for p in 
db(db.product.name.belongs(cart.keys())).select())




On Friday, 26 December 2014 09:39:15 UTC-6, 黄祥 wrote:
>
> hi,
>
> i face the similar problem (even more complex) designing the table for it.
>
> condition 1 : time base promotion
> promotion price will occured during the valid date (start, end)
> e.g. on 1 dec 2014 - 31 dec 2014 the price for product B will be $10, 
> usually normal price is $12
>
> condition 2 : quantity base promotion
> promotion price will occured when the quantity order is more than quantity 
> that have been set
> e.g. buy 3 products B the price will be $10, when buy 1 of product B the 
> price is $12 or buy 5 products B the price will be $8, when buy 1 of 
> product B the price is $12
>
> condition 3 : product base promotion
> promotion that offer free product when another product is ordered.
> e.g. buy 3 products B get 1 product C or buy 5 products B get 2 product C 
> and 1 product D
>
> condition 4 : combination of all 3 aboves
> e.g. on 1 dec 2014 - 31 dec 2014 buy 3 products B get 1 product C
>
> my question is how do i design my table relation for that in web2py way? 
> i've seen examples of presta shop add ons for that, but don't know how to 
> do it using web2py way, any idea how to achieve that?
>
> thanks and best regards,
> stifan
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to