Storing selected product options in a shopping cart in CakePHP
I am building a shopping cart in CakePHP and currently have the following relationships:
Product
HABTM (HasAndBelongsToMany)Options
Cart
HABTMProducts
Pretty standard? I'm just not sure what to do when a user selects s开发者_JS百科ome options for the product and saves it to the cart. Do I add a new model called CollectionsProductOptions
?
What's the best way to store this kind of data? Should I just serialize an array of selected options and save to the carts_products
table?
My approach was to try to stick to convention. I have a cart model, an item model, an option model and a value model (an option can have multiple values). Once I got it to there, everything fell in to place. You need to set recursion to "3" but when you read the cart, you get everything perfectly laid out.
I keep my cart products/options separate from my catalog products/options. On the cart side, an option only belongs to one product. On the catalog side, an option can belong to many products. Your approach may be different. I do this because options may change and I don't want my old sales information to change. I do this for all cart tables. The cart_products table is different than the products table. The product_options table is different than the options table, etc.
精彩评论