Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

Greyoxide asked in Rails
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
end

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

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

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

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?
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,329+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.