Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Looking for better approach - Add product to order with selectable product options

Rails • Asked by Greyoxide
I'm working on an app that allows merchants to order products from a wholesaler.  On a fundamental level, there are a lot of similarities to a traditional e-commerce app, but there are also some differences.

I've tried coming at this from a few directions, but Im yet to find a good solution.  Here are my models

class Merchant
  has_many :orders

class ProductLine
  has_many :products
  has_many :option_groups, as: :option_groupable

class Product
  belongs_to :product_line
  has_many :option_groups, as: :option_groupable
  has_many :options, through: :option_groups

class OptionGroup
  belongs_to :option_groupable, polymorphic: true
  has_many :options

So a merchant user will be able to log in and create an order, then add products to the order, each product will have options that can be selected.  Options are grouped into option groups.  Some option groups should allow users to select multiple options, and others should allow a user to select only one option from the group.

Typically, merchants will be ordering a relatively small set of products, in larger quantities.  So for example, a merchant may order a set of 100 of X product, with XYZ options attached.

Has anyone ever encountered a situation like this?  What approach would you recommend?

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.