fix: use WC attribute ID (not name) when setting variation attributes
WooCommerce silently ignores attribute 'name' on variation updates — requires 'id' (the WC attribute ID). Built a lookup map from the parent product's wc_attributes and use 'id' in all variation payloads. Fixed in all 3 files: variant push wizard, product creation wizard, and product map direct push. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -585,6 +585,9 @@ class WooProductCreateWizard(models.TransientModel):
|
||||
'company_id': inst.company_id.id,
|
||||
})
|
||||
|
||||
# Build WC attribute ID lookup
|
||||
wc_attr_id_map = {a['name'].upper(): a['id'] for a in wc_attributes}
|
||||
|
||||
# Create variations
|
||||
variation_count = 0
|
||||
for line in self.variant_line_ids:
|
||||
@@ -592,13 +595,17 @@ class WooProductCreateWizard(models.TransientModel):
|
||||
continue
|
||||
|
||||
variant = line.product_id
|
||||
# Build variation attributes
|
||||
# Build variation attributes with WC IDs
|
||||
var_attributes = []
|
||||
for ptav in variant.product_template_attribute_value_ids:
|
||||
var_attributes.append({
|
||||
'name': ptav.attribute_id.name,
|
||||
'option': ptav.name,
|
||||
})
|
||||
attr_name = ptav.attribute_id.name
|
||||
wc_aid = wc_attr_id_map.get(attr_name.upper(), 0)
|
||||
entry = {'option': ptav.name}
|
||||
if wc_aid:
|
||||
entry['id'] = wc_aid
|
||||
else:
|
||||
entry['name'] = attr_name
|
||||
var_attributes.append(entry)
|
||||
|
||||
var_data = {
|
||||
'regular_price': str(line.sale_price),
|
||||
|
||||
Reference in New Issue
Block a user