Shopping cart and different kinds of discounts. Storing discounts in DB and applying it to order calculations

ぃ、小莉子 提交于 2019-12-06 02:34:32

A basic solution for the present for purchasing item or group of items requirement is to have something like a bundle and a 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 the gift item id and the bundleitem table holds all the items associated to the bundle which the user must order to qualify for the gift.

Your 'Bundle' class would contain an array of these required product items, the gift item and a method which takes a shopping cart object and checks to see whether the cart contains every required product for this particular bundle offer - something like a simple foreach within a foreach loop...

This is a simple solution things can get complex depending on the rules for these gift items e.g. if I order 2 pens and 2 lists of paper do I get 2 sharpeners? - Good luck with it!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!