Peter Peter Pumpkin Eater
2006-Jun-07 08:59 UTC
[Rails] trouble wtih webstore schema, handling product variations
Hi Railers, Does anyone have any guidance on setting up a simple way to handle product variations (e.g garment size/color)? Initially, I had thought that I would make a variation model which defined the extra bits, but it seems quite inflexible especially so if a store were to sell non-clothing items that also had variants of one flavor or another. product has_many variations title description price variations variation belongs_to garment has_many images size color sku would it make more sense for the variation model to subclass the product and add additional table columns? As an aside, is anyone else having problems with the list and their GMail account? I have not received a message since 8h PST. -- Posted via http://www.ruby-forum.com/.
Chris T
2006-Jun-07 13:47 UTC
[Rails] trouble wtih webstore schema, handling product variations
I used STI for something slightly similar for something where each item was a type of model, but it had additional characteristics depending on whether it was a mainmodel or modelvariation (actually had three levels -- parentmodel, mainmodel, and modelvariation). class Modeltype < ActiveRecord::Base .. end class Modelvar < Modeltype .. end I''ve then got a one-to-many self-referential relationship on the model to define the relationship. However, re-reading your post, wondering if in your case you have a many-many relationship between products and possible product variations: a product can have many variations, and presumably some of those variations -- e.g. extra large -- can be associated with other products. So what about variation HABTM products variation_group (e.g. size, colour) variation_specs (e.g. red, small) I guess you could even make variation an STI if the variations required different details. IF you used has_many through the join table could contain the SKU. Then again I could be talking rot -- had a fruitless morning trying to sort out a mixin prob... p.s. Yup, I''ve had the same prob with gmail. Seems OK now though. Peter Peter Pumpkin Eater wrote:> Hi Railers, > > Does anyone have any guidance on setting up a simple way to handle > product variations (e.g garment size/color)? Initially, I had thought > that I would make a variation model which defined the extra bits, but it > seems quite inflexible especially so if a store were to sell > non-clothing items that also had variants of one flavor or another. > > product > has_many variations > title > description > price > variations > > variation > belongs_to garment > has_many images > size > color > sku > > would it make more sense for the variation model to subclass the product > and add additional table columns? > > > As an aside, is anyone else having problems with the list and their > GMail account? I have not received a message since 8h PST. > >
Sean O''Hara
2006-Jun-07 15:11 UTC
[Rails] trouble wtih webstore schema, handling product variations
Hi Peter, I am pretty much a newb, but I had basically the same problem. In my schema I have Products and 3 sub products that inherit from Products using STI. And I have an Options class (similar to your Variations) that belongs_to one of the sub product classes (because the other two will never need options). What I did is create to different methods for adding items to a cart. The first is add_to_cart, the second is add_option_to_cart. And an option contains a Product object or reference. Basically I did it this way because I just didn''t think that Options had enough in common with Products for them to inherit from Product. I would however be interested in knowing if there''s a simpler way of doing this that doesn''t require using two different functions to add to the cart (and subsequently dealing with the items in the cart when it''s time to submit an order). Here''s my models... class Product < ActiveRecord::Base has_many :line_items t.column "price_ca", :integer t.column "price_us", :integer t.column "catalog_number", :string t.column "type", :string t.column "form", :string t.column "order_number", :integer t.column "title", :string t.column "has_option", :boolean, :default => false, :null => false t.column "quantity", :integer t.column "created_at", :datetime t.column "updated_at", :datetime end class HardProduct < Product has_many :options end class Option < ActiveRecord::Base belongs_to :hard_product has_many :line_items t.column "hard_product_id", :integer t.column "description", :string t.column "quantity", :integer end Take care, Sean On 7-Jun-06, at 1:50 AM, Peter Peter Pumpkin Eater wrote:> Hi Railers, > > Does anyone have any guidance on setting up a simple way to handle > product variations (e.g garment size/color)? Initially, I had thought > that I would make a variation model which defined the extra bits, > but it > seems quite inflexible especially so if a store were to sell > non-clothing items that also had variants of one flavor or another. > > product > has_many variations > title > description > price > variations > > variation > belongs_to garment > has_many images > size > color > sku > > would it make more sense for the variation model to subclass the > product > and add additional table columns? > > > As an aside, is anyone else having problems with the list and their > GMail account? I have not received a message since 8h PST. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Peter Peter Pumpkin Eater
2006-Jun-08 04:29 UTC
[Rails] Re: trouble wtih webstore schema, handling product variation
Thank you both, you have given me some good ideas on how to tackle this =) Sean O''Hara wrote:> Hi Peter, > > I am pretty much a newb, but I had basically the same problem. In my > schema I have Products and 3 sub products that inherit from Products > using STI. And I have an Options class (similar to your Variations) > that belongs_to one of the sub product classes (because the other two > will never need options). What I did is create to different methods > for adding items to a cart. The first is add_to_cart, the second is > add_option_to_cart. And an option contains a Product object or > reference. Basically I did it this way because I just didn''t think > that Options had enough in common with Products for them to inherit > from Product.-- Posted via http://www.ruby-forum.com/.