0

I am making an E-commerce solution that needs to be a multi-store solution. I am seriously stuck while making the Associations between Products and it's features. As it is a multi-store solution I need dynamic feature possibilities per product. I came up with three entities: Product, FeatureKind & FeatureValue.

  • FeatureKind has the basic feature names like Size, Color, Style, etc. Also has a M:M connection to the FeatureValue entity.
  • FeatureValue obviously contains the values for the FeatureKind like Small, Medium, Green, Red, Blue, Full-Sleeved, etc.
  • Product entity is connected to FeatureKind with a M:M association.

I am having a few problems in this type of structure:

  • What if I have a Product that only has Small size, it shouldn't also show up Medium in options. What if a product only has Green color, it shouldn't also show Red and Green, and so on.
  • Secondly, What if I have a product that is available only in Green in Small size and Red in the Large size. how will that work out?

I'm sure I need to change my structure and architecture both, Luckily the project is in Symfony2 and I only have the product bundle to make.

I would be happy to post the entities here but my problem is concept and not code. If you need to see it just comment and I'll edit the question.

j0k
  • 22,600
  • 28
  • 79
  • 90
Aayush
  • 3,079
  • 10
  • 49
  • 71

1 Answers1

0

Based on your use case, Feature entity should be an STI. You can create different entities that branch out from Feature entity to map different features such as Color, Size, or Volume. You would need to create a join table to connect Product entity with Feature entity under a M:M relationship.

Read more about STI here.

/**
 * @Entity
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"feature" = "Feature", "color" = "Color", "size" = "Size"})
 */
class Feature
{
    // ...
}

/**
 * @Entity
 */
class Color extends Feature
{
    // ...
}
shiva8
  • 2,142
  • 2
  • 19
  • 24
  • Thanks for the answer, but wouldn't this method limit the features to all the entities that I'll make. I need someway in which we can dynamically generate features and their values and then connect them with the product. As it is a multi-store system I can't determine what the product would be and what kind of attributes it would have. Thanks again for your time. – Aayush Sep 11 '12 at 04:17
  • You could try to setup Feature table as a Key Value pair. – shiva8 Sep 11 '12 at 13:28