コンテンツへスキップ
メニュー
この質問にフラグが付けられました
4 返信
4863 ビュー

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?


アバター
破棄
最善の回答

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.

アバター
破棄
著作者

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?

著作者

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.

関連投稿 返信 ビュー 活動
1
1月 20
3827
3
5月 25
1166
3
11月 24
7869
3
9月 24
5753
0
12月 17
3705