非注册用户的购物车

发布于 2024-08-04 00:25:34 字数 353 浏览 4 评论 0原文

我正在制作一个涉及购物车的网站。 有两个主要要求:

  1. 用户体验人员希望登录/身份验证成为整个工作流程的最后一步。用户可以进行所有购物,并且仅在结帐时才被要求登录。

  2. 购物车不应过期(即使浏览器关闭也不会过期),除非用户(无论是否注册)结账。

在上述上下文中,我对维护购物车状态有以下问题:

我应该使用基于文件的会话还是数据库会话?请记住,这适用于未注册的用户。我担心数据库中最终会有大量记录。

另一种选择似乎是将购物车内容放入加密的 cookie 中,但 cookie 文件的大小有限制。

在这种情况下你会怎么做?我非常感谢您的回答。

I am in the process of making a website that involves a shopping cart.
There are two major requirements:

  1. The user experience guys want login/authentication to be the very last step in the entire work flow. The user gets to do all the shopping and is asked to login only at the time of checking out.

  2. The shopping cart shouldn't expire(not even on browser close) unless the user (registered or not) does check-out.

In the above context, I have the following question with respect to maintaining the cart's state:

Should I go with file based or database sessions? Please keep in mind this would be for unregistered users. My apprehension is that I'll end up having lots of records in the database.

Another option seems to be to put the cart contents in an encrypted cookie, but then there's a size limitation on the cookie file.

What would you do in this case ? I would really appreciate your answers.

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

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

发布评论

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

评论(6

半边脸i 2024-08-11 00:25:34
  1. 跟踪用户。使用 GUID
    编码到 cookie 中
    n一年到期。

  2. 存放购物袋。您不想将袋子存放在饼干中,主要是因为它可能的尺寸。这就留下了将其保存到介质并从介质中检索它的选项。使用除数据库之外的任何东西就像回到过去一样,数据库擅长存储和检索数据。

  3. 管理您的购物袋。现在,
    首先,你的模式问题,如果
    你将要运行查询
    对着购物袋
    数据库(即有多少购物
    袋子里有物品x)你可能
    想要传统的关系
    架构。然而这有开销
    就插入而言。更新,
    选择(和加入)和删除
    包数据(在某些时候你会有
    永远不会再使用的袋子
    但占用了宝贵的磁盘空间
    空间)。对于一个繁忙的网站,这是一个
    每秒的交易量相当少,
    但任何数据库都应该能够
    应付。如果您不需要查询
    数据库中的购物袋,
    然后你可以将其存储为 XML。只是
    序列化包并将其转储到
    表,以 PK 作为 GUID
    存储在用户的 cookie 中。这
    会比
    传统模式,加上你可以
    总是将 XML 拆开
    未来如果确实出现需求
    用于关系模式。

这就是我们所做的(Xml Bag),我们拥有超过一百万的客户群。

  1. Tracking a user. Use a GUID
    encoded into a cookie with an
    nYear expiry.

  2. Storing a Shopping Bag. You don't want to store the bag in the cookie, mainly due its possible size. This leaves the option of persiting it to a medium and retrieving it from the medium. Using anything except a database for this would be like going back in time, databases excel at storing and retrieving data.

  3. Managing you Shopping Bag. Now, the
    question of your schema, firstly, if
    your going to be running queries
    against the shopping bags in the
    database (i.e. how many shopping
    bags contain item x) you probably
    want a traditional relational
    schema. However this has overheads
    in terms of inserting. updating,
    selecting (and joining) and deleting
    bag data (at some point you'll have
    bags that will never be used again
    but are taking up precious disk
    space). With a busy site, this is a
    fair few Traranactions Per Second,
    but any database should be able to
    cope. If you don't need to query
    the shopping bags in the database,
    then you can store it as XML. Just
    serialize the bag and dump it into a
    table, with the PK as the GUID as
    stored in the users cookie. This
    would be a lot faster than a
    traditional schema, plus you could
    always tear apart the XML in the
    future if a requirment did come up
    for a relational schema.

This is what we do (Xml Bag), and we have a million+ customer base.

梦初启 2024-08-11 00:25:34

我会选择数据库管理会话而不是文件管理会话。确保您有一个会话时间戳,以便您最终可以终止旧会话(如果已经过去 12 个月,购物者可能不会再回来购买购物车中最初的商品)。

使用数据库而不是文件来执行此操作将使非常旧的信息最终更容易过期。

请注意,数据库会话仅在其绑定到用户计算机上的 cookie 时才有效。如果用户从不同的浏览器返回商店,他们将找不到他们的会话。如果两个人共享同一台计算机,他们将找到彼此的会话。希望购物车中不会有任何可能令人尴尬的物品......

I would go with database managed sessions over file managed sessions. Make sure you have a session timestamp so that you can eventually kill old sessions (if it's been 12 months, the shopper is possibly not coming back for the items originally in the cart).

Doing this with a database instead of files will make it easier to eventually expire the very-old information.

Note that the database session will only ever be valid as long as the cookie it's tied to on the user's computer. If the user comes back to the store from a different browser, they will not find their session. If two people are sharing the same computer, they will find each other's session. Hopefully no potentially embarrassing items will be in the cart...

八巷 2024-08-11 00:25:34

将 AnonymousSessionID 存储在 cookie 中,您可以将其与数据库中的购物车关联起来。

然后,您将有一个调度程序任务在一段时间(例如一天)后删除匿名会话。这将使您的数据库清除废弃的会话。

如果用户注册,您会将他们的购物车与其帐户永久重新关联。如果用户下了订单,您就清空他们的购物车。

Store in cookies the AnonymousSessionID, with which you associate a shopping cart in the database.

Then you'll have a scheduler task to erase anonymous sessions after some time (say, a day). This will keep your database clean of abandoned sessions.

If a user registers, you reassociate their shopping cart with their account permanently. If the users makes an order, you empty their shopping cart.

薄凉少年不暖心 2024-08-11 00:25:34

如果您使用 ASP.NET,这就是我要做的:

(不要尝试将 XML 订单存储在个人资料中。i我认为这是性能问题,但理论上你可以认为)

If you're using ASP.NET here's what I'm (about) to do:

  • use a Profile to capture the users email as soon as possible (to email them if they dont complete the order). you can enable anonymous profile properties that are persisted to the aspnet database even if the user hasnt actually truly registered.
  • stick an XML bag representing an order into session. This is persisted in the database with a regular identity ID.
  • store the ID of the cart in the ASP.NET Profile. that way when the session expires you can just reload it from the ID in the profile. this has the benefit that the user never sees the cart ID in a cookie and you can easily link records between the membership/profile database and the store you're using for your orders

(dont try to store the XML order in the Profile. i think thats asking for performance issues. but in theory you could i suppose)

帅气尐潴 2024-08-11 00:25:34

根据这些规范,我将选择基于数据库的会话状态。但是您应该大量阅读有关如何在您选择的 Web 服务器中处理会话状态的内容。因为你希望能够将状态恢复到正确的人。

With those specs I would go with a database based session state. But you should do some heavy reading on how session state is handled in your web server of choice. Since you want to be able to revive the state to the correct person.

他夏了夏天 2024-08-11 00:25:34

我认为您有一些期望需要管理,或者您可能不清楚要求。

  1. 用户体验人员希望登录/身份验证成为最重要的
    整个工作流程的最后一步。这
    用户可以完成所有购物,并且
    仅在以下时间要求登录
    退房。
  2. 购物车不应过期(即使浏览器关闭也不会过期)
    除非用户(无论是否注册)
    办理退房手续。

具体来说,是否保存了匿名、未登录用户的购物车?这太疯狂了。确保这不是预期,并在设计文档中进行澄清。

I think you have some expectations to manage, or maybe you weren't clear on requirements.

  1. The user experience guys want login/authentication to be the very
    last step in the entire work flow. The
    user gets to do all the shopping and
    is asked to login only at the time of
    checking out.
  2. The shopping cart shouldn't expire(not even on browser close)
    unless the user (registered or not)
    does check-out.

Specifically, an anonymous, not logged-in user's cart being saved? That's madness. Ensure that's not an expectation and clarify it in your design documents.

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