views:

141

answers:

1

I want to build a shop in which the products have a little wizard through which the price then is determined. In this case I'm talking about printing products.

So for (a little) example when you come to the shop and want to print a business card, you get to decide if you want to print black and white or in color, if you want to choose thick paper or thin, if you want to print 100, 200, 500 or 1000 pieces and so on.

After all there will be a price for let's say: black and white, thick paper, 200 piece => 40,-$

In real you have many more choices to choose from. So as you can think there are many many prices, for which there is no formula.

So my question is: How can I handle the prices?

My first idea: Decorator Pattern.

But when I thought about it, it's not a very good idea. As I told there is no real formula, also I have to generate the wizard (which may be different if you want to print greeting cards). Also I want to be able to change the price trough a admin interface or add a product or add a new "decision" like "do you want glossy paper?" to a product or remove one (and still keep the prices intact).

So now I'm thinking about using a tree for each product in which I can add a level (a new decision), resort levels and so on.

Another Idea is to Build some Kind of Key-Objects through the decisions and look the price up in a Price table. A bit like a Dictionary in which I add the decisions and after all I generate a key out of it to look up the price in a price table.

So before prototyping I was wondering if I'm just blind and I don't see the obvious solution or maybe there is another way which is more elegant I don't know about?

+3  A: 
Adam Davis
Wow very impressive answer! Thank you very much.The things you mentioned "flexible up front", "any product changes go into the database, not code changes" and more are exactly what I'm looking for (and why I asked the question).I like the idea with the matrix, I just don't get one thing:
Stefan Koenig
So let's say I choose Light Paper, Red Color, Print. How do I get to the right price? In a two dimensional table I have three possible pairs Red/Print, Red/Light, Print/Light. Sadly I can't calculate the price in an evolving formula I just have one end price after all choices have been made.
Stefan Koenig
thanks this helped very much.
Stefan Koenig