购物车和各种折扣。将折扣存储在数据库中并将其应用于订单计算

发布于 2024-11-04 03:51:35 字数 1227 浏览 4 评论 0原文

目前,我正在寻找对购物车/订单“应用折扣”的最佳实践。 因此,我计划实施这样的折扣:

  • 固定用户折扣(例如,我想给我最喜欢的客户 10% 的折扣)

  • 商品数量折扣(例如,您重新购买 10 支不同颜色的笔您将获得 1.5% 的折扣)

  • < p>优惠券折扣(例如,在促销活动期间,我们制作了 100 张优惠券,每张优惠券 10%。优惠券仅适用于一个订单,并在yyyy-mm-dd)

  • 购买商品或一组商品的礼物(例如,您要购买钢笔、纸张清单,商店会向您赠送磨刀器)

  • 订单总价折扣(例如,您“购买 10 支笔且没有折扣,那么您再添加 5 支笔并获得 5% 的折扣)

特定商品只能应用一笔折扣。我们总是应用最大的折扣。对用户来说最有利可图的折扣。

除此之外,管理员应该能够修改特定订单中的商品价格并取消该订单中的折扣。

坦率地说,这是我的第一个电子商务应用程序,在我看来,实现所有这些折扣是一项艰巨的任务。

好吧,现在让我告诉你我将如何实现...

  • 固定用户折扣 它只是用户表中的一个字段,其中包含有关折扣的信息。它是通过控制面板手动设置的,或者由 cron 自动设置的,用于订单总额超过该 N 的用户。

  • 商品数量折扣 我将创建额外的表来存储商品的组这样的折扣。另外,我还需要一张表来将此组与商店中的商品连接起来。

  • 优惠券折扣 只是一个包含优惠券的表格,其中包含过期日期、优惠券状态、优惠券折扣以及可能的 user_id (优惠券所有者)字段。也许我还会为商品类别实现优惠券。

  • 购买物品或一组物品的礼物这真的很痛苦,我完全不知道如何实施。请帮忙!

  • 订单总价折扣非常简单,恕我直言。

好的,现在我正在寻找在数据库中存储此类折扣的最佳实践。另外,我正在寻找 OOP 实践来将此折扣应用于购物车。任何帮助表示赞赏!

PS:抱歉这么长的帖子,但我认为这不仅对我来说很有趣。

谢谢。

Currently, I'm looking for best practice to "applying discounts" to cart/order.
So, I'm planning to implement such kind of discounts as...

  • fixed user's discount (for example, I'd like to give 10% discount to my favourite customer)

  • discount for number of items (for example, you're buying 10 different colored pens and you'll be getting discount of 1.5%)

  • discount for coupon (for example, during promo action we've produced 100 coupons with 10% discount each. Coupons work only for one order and expire on yyyy-mm-dd)

  • present for purchasing item or group of items (for example, you're buying pen, list of paper and shop presents a sharpener to you)

  • discount for total order price (for example, you're buying 10 pens and gettin no discount, then you're adding 5 more pens and getting 5% discount)

Only one discount could be applied to specific item. We're always applying biggest discount. The most profitable discount for user.

Beside that admin should be able to modify items price in specific order and cancel discounts in this order.

Frankly speaking, it is my first ecommerce application and it seems to me pretty hard task to implement all these kinds of disounts.

Ok, now let me tell you how I'm going to implement...

  • fixed user's discount It is just a field in users table which contains information about discount. It is being set manually through control panel or automatically by cron for uses having total order summ over that N.

  • discount for number of items I'm going to create additional table storing items' groups of such discounts. Also I'll need one more table to connect this groups with items in shop.

  • discount for coupon Just a table with coupons containing field with expire day, status of coupon, coupon discount and maybe user_id (owner of coupon). Probably I will also implement coupons for categories of items.

  • present for purchasing item or group of items It is real pain in the ass and I totally don't know how implement. Please help!

  • discount for total order price Pretty easy, imho.

Ok, now I looking for best practices of storing this kinds of discounts in DB. Also I'm looking for OOP practices to applying this discounts to Cart. Any help is appreciated!

PS: Sorry for such long post, but I think that it will be interesting not only for me.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪失控 2024-11-11 03:51:35

当前购买商品或商品组需求的基本解决方案是拥有类似捆绑包和捆绑商品表之类的东西。

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

您的捆绑包表包含礼品项目 ID,捆绑项目表包含与捆绑包关联的所有项目,用户必须订购这些项目才有资格获得礼物。

您的“Bundle”类将包含这些必需产品项目的数组、礼品项目和一个方法,该方法采用购物车对象并检查购物车是否包含此特定捆绑包优惠的所有必需产品 - 类似于内部的简单 foreach foreach 循环...

这是一个简单的解决方案,根据这些礼品的规则,事情可能会变得复杂,例如,如果我订购 2 支笔和 2 张纸,我会得到 2 个卷笔刀吗? - 祝你好运!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文