views:

26

answers:

1

Hi

I'm building an e-commerce website. I have a Product and Order models. It's possible that a customer order a product and then the admin change its price or other fields before the customer actually get it.

A possible solution is to add a 'version' field to the Product model. When the admin update a product field I'll add a timestamp and create a new object instead of updating the old one. An Order will have a reference to a specific product version.

Does this make sense? Will overriding the Product Save method be sufficient to make it work?

Thanks

A: 

I do it this way:

Make a duplicate of the relevant product columns in the order table.

When you add a product to the order, copy everything from Product to Order (include a FK too if you want). That way the admin can do whatever they want (change product name/price/category/etc.), but the product price / name / etc. will always remain the same.

You could do a version column in product as you suggested, but that's a lot more complicated.

Seth
Copying the product fields to the order is a good idea.The only problem is that different type of products have different fields.Maybe Ill just copy everything to a text field and only the fields common to all the product types to separate fields.Thanks
pablo