Skip to Content
Menu
This question has been flagged
4 Replies
3940 Views

Is there a way to find what product prom model product.product is the one that is created when a product.template is created?

I don't see any field in product.product model that would define if it's a variant or not.

How can I know what is a variant and what is the base product?


Avatar
Discard
Best Answer

There are two possibilities:

  1. A product has no attributes, so a single record is created on product.product (dummy variant) 

  2. A product has attributes so multiple records are created on product.product (one per variant)

If you add variants to a product that didn't previously have them, the single (dummy variant) record will be archived.  This is because you can't buy or sell the product but have to use a variant.

If you want to know where a record on product.product is for a variant you could check whether  product_template_attribute_value_ids is set.  If it is, it's a variant.

Avatar
Discard
Author

Sadly it's not that easy. You can have attributes and it's not a variant. There's an option on creating attributes, that it never creates a variant. I'm now guessing that the first record that is created is the base product, so I'm searching and ordering by ID ASC and using the first one.

Yes, there's an option not to create variants, or to only create them when you place an order.

Are you saying that there are records on product.product for attributes that aren't variants? Can you give an example?

Author

You're kinda right. Attributes that do not create variants have no records in the product_attribute_value_product_product_rel table but only the product template has records for lines. Records are in the product_template_attribute_value table. The ones that are on the line of the product template and the product is not a variant.

Related Posts Replies Views Activity
1
Jan 20
3134
3
Nov 24
5859
3
Sep 24
4403
0
Dec 17
2808
1
Mar 15
3721