Okay,
Devshed have a database/PHP tutorial which shows how to set up a shopping system, and talks a bit about product catalogues here:
http://www.devshed.com/Server_Side/PHP/Commerce/Commerce1/page5.html
What you are trying to do doesn't seem as complicated as you think it is. It's essentially just a normal one-table product database, but you need some way of representing rules in another table.
We'll assume that one customer only buys one sandwich at a time. So there'll be a session_id/sandwhich_id/order_id which references this order. Then you'll be looking to insert order_lines into an order_lines table for each product part of this sandwhich. Your add-to-cart script will make changes to this order and display the current order/sandwhich.
So you can have a sandwich/order table like this:
sandwich:
sandwich_id: integer
name: varchar50
email:varchar150
delivery_address1: varchar
delivery_address2: varchar
etc etc
And then a sandwich_lines table like this:
sandwich lines:
sandwich_id: integer
product_id: integer
price: decimal (10,2)
You can put a price in this table so you can discount stuff from the product table price, based on specific rules.
One table will be a normal product table. e.g.
product:
id: integer
name: varchar(50)
description: varchar(250)
price: decimal(10,2)
type: varchar(10)
You can fill type with either BREAD, CONDIMENT,FILLER depending upon the product. Easy. You could use a few more types to be precise about different sub-classes of FILLERS etc.
Next, you need a way to represent the rules for products in the basket. You'll have to define the rules first.
e.g.
rule1: No sandwich can have more than one type of bread.
rule2: a sandwhich with the toasted bread product can't have pickles as a FILLER.
You'll need to write some helper functions for these rules in order that you can easily write boolean logic in your add-to-cart script. e.g.
function is_in_sandwich(product_id,sandwich_id)
returns true if supplied product_id is in the sandwich
function qty_bread_products(sandwich_id)
returns qty of bread products in the sandwich
Then you can implement the rules in your cart and throw error messages when these rules are broken.
e.g. rule1:
if (qty_bread_products > 1) {
echo "You screwed up - too much bread!";
die;
}
rule2: (456 is id of toasted bread)
if ((is_in_sandwich(456)) && (is_in_sandwich(789)) ) {
echo "pickles and toasted bread? are you mad?";
die;
}
For these rules, if you've got a lot of them, you could work out a way to put them in a database table. But whether you hard-code them or put them in a DB depends on how many and your system architecture. I'd hard code them as PHP is so easy to use.
Those are specific rules. If you want general rules based on the product.type value (BREAD/CONDIMENT/FILLER) then you can write similar logic functions.
All the above is my take on how you could do it, but the eventual solution is down to you. It's best to figure this sort of thing out on paper first before coding. Give that DevShed article a read and it should help you understand shopping cart basics.
Anyway, that should be enough to get you going.. have fun!
Anthony