Data relationships for e-commerce: users, orders, addresses

Hi there

I’m in the process of developing an e-commerce Rails app but am
getting a little stuck on what models I should be working with on the
order/checkout side of things.

The app requires users to be registered and authenticated to checkout.
So I already have a User model and an Order model (which belongs to a
User). The Order model is largely similar to that used in the Agile
Rails book.

I’m using acts_as_authenticated for my User model.

At checkout a user can specify a billing and/or shipping address.
Should I have seperate models for each of these address types?

If so, are they correctly associated with the order or the user?

So my issue is how best to deal with shipping and/or billing addresses
in the scheme (schema?) of things?

I have a copy of the ecommerce Rails pdf by Ben Curtis which is very
helpful on other aspects of the various data relationships, but I’m
hooked up on the relationship between addresses, orders and users.

Any clues appreciated.

Richard S.

On 8/2/06, Richard S. [email protected] wrote:

At checkout a user can specify a billing and/or shipping address.
Should I have seperate models for each of these address types?

Depends on what your app needs. If they needed different behavior,
then you’d want to split them up. That’s probably very unlikely
though, and you can probably just go ahead with a single Address
model.

If so, are they correctly associated with the order or the user?

So my issue is how best to deal with shipping and/or billing addresses
in the scheme (schema?) of things?

Again, it all depends…but when I did this, I let users associate
unlimited addresses with their account. Each address would have a
user_id. Then my orders would have a shipping_address_id and a
billing_address_id.

Pat

On Aug 1, 2006, at 11:22 PM, Richard S. wrote:

At checkout a user can specify a billing and/or shipping address.
Should I have seperate models for each of these address types?

In my app I have an Address model that uses STI to give me
BillingAddress and ShippingAddress. Having the two subclasses makes
it easy to present the correct list of addresses to the user when
selecting the billing address and the shipping address for a
particular user.

If so, are they correctly associated with the order or the user?

My Address model belongs_to the User, and the Sale and Shipment
models belong_to an Address (well, ShippingAddress). Remember,
though, that you don’t want the address changing once a shipment has
been created that uses it, otherwise your reporting can get royally
hosed. Some people prefer to add address fields to the Shipment
model, copying the info from one table to another when the shipment
is created. I prefer to just use the id to reference back to the
address table and then prevent any updates to the address if
shipments are associated with it.

So my issue is how best to deal with shipping and/or billing addresses
in the scheme (schema?) of things?

I have a copy of the ecommerce Rails pdf by Ben Curtis which is very
helpful on other aspects of the various data relationships, but I’m
hooked up on the relationship between addresses, orders and users.

Thanks for the purchase of my book. :slight_smile: And thanks for the idea on
material I can add to help improve it.


Benjamin C.
http://www.bencurtis.com/
http://www.tesly.com/ – Collaborative test case management
http://www.agilewebdevelopment.com/ – Resources for the Rails community

Thanks Pat and Ben for your help.

And thanks Ben for the The Money Train - I’ve learnt a lot from it.

Richard

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs