algorithm - Shopping cart and different kinds of discounts. Storing discounts in DB and applying it to order calculations -
currently, i'm looking best practice "applying discounts" cart/order. so, i'm planning implement such kind of discounts as...
fixed user's discount (for example, i'd give 10% discount favourite customer)
discount number of items (for example, you're buying 10 different colored pens , you'll getting discount of 1.5%)
discount coupon (for example, during promo action we've produced 100 coupons 10% discount each. coupons work 1 order , expire on yyyy-mm-dd)
present purchasing item or group of items (for example, you're buying pen, list of paper , shop presents sharpener you)
discount total order price (for example, you're buying 10 pens , gettin no discount, you're adding 5 more pens , getting 5% discount)
only 1 discount applied specific item. we're applying biggest discount. profitable discount user.
beside admin should able modify items price in specific order , cancel discounts in order.
frankly speaking, first ecommerce application , seems me pretty hard task implement these kinds of disounts.
ok, let me tell how i'm going implement...
fixed user's discount field in users table contains information discount. being set manually through control panel or automatically cron uses having total order summ on n.
discount number of items i'm going create additional table storing items' groups of such discounts. i'll need 1 more table connect groups items in shop.
discount coupon table coupons containing field expire day, status of coupon, coupon discount , maybe user_id (owner of coupon). implement coupons categories of items.
present purchasing item or group of items real pain in ass , totally don't know how implement. please help!
discount total order price pretty easy, imho.
ok, looking best practices of storing kinds of discounts in db. i'm looking oop practices applying discounts cart. appreciated!
ps: sorry such long post, think interesting not me.
thank you.
a basic solution present purchasing item or group of items requirement have bundle , bundleitem table.
bundle table. id int primary key giftproductid int foreign key - product table bundleitem table. id int primary key bundleid int foreign key - bundle table requiredproductid int foreign key - product table
your bundle table contains gift item id , bundleitem table holds items associated bundle user must order qualify gift.
your 'bundle' class contain array of these required product items, gift item , method takes shopping cart object , checks see whether cart contains every required product particular bundle offer - simple foreach within foreach loop...
this simple solution things can complex depending on rules these gift items e.g. if order 2 pens , 2 lists of paper 2 sharpeners? - luck it!
Comments
Post a Comment