Remove backward compatibility fields from product forms
Remove automatic addition of ProductName and Price fields when they're not defined as custom AR fields. This ensures tenants using only custom fields won't see unwanted default fields in their products. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -108,29 +108,6 @@ def add_product(tenant_id):
|
||||
"fieldType": field['fieldType']
|
||||
})
|
||||
|
||||
# Handle backward compatibility fields
|
||||
if '_name' not in [f['fieldName'] for f in custom_fields]:
|
||||
name = request.form.get('name', '')
|
||||
if name:
|
||||
product_data.append({
|
||||
"fieldName": "_name",
|
||||
"label": "Product Name",
|
||||
"value": name,
|
||||
"editable": "true",
|
||||
"fieldType": "TEXT"
|
||||
})
|
||||
|
||||
if '_price' not in [f['fieldName'] for f in custom_fields]:
|
||||
price = request.form.get('price', '')
|
||||
if price:
|
||||
product_data.append({
|
||||
"fieldName": "_price",
|
||||
"label": "Sale Price",
|
||||
"value": f"${price}",
|
||||
"editable": "true",
|
||||
"fieldType": "TEXT"
|
||||
})
|
||||
|
||||
# Save to database
|
||||
ProductModel.save(product_id, tenant_id, product_data, image_data, image_mime_type)
|
||||
|
||||
@@ -235,25 +212,6 @@ def edit_product(tenant_id, product_id):
|
||||
|
||||
updated_product.append(existing_field)
|
||||
|
||||
# Handle backward compatibility fields
|
||||
if '_name' not in [f['fieldName'] for f in custom_fields]:
|
||||
name = request.form.get('name', '')
|
||||
if name:
|
||||
for field in products[product_id]:
|
||||
if field["fieldName"] == "_name":
|
||||
field["value"] = name
|
||||
updated_product.append(field)
|
||||
break
|
||||
|
||||
if '_price' not in [f['fieldName'] for f in custom_fields]:
|
||||
price = request.form.get('price', '')
|
||||
if price:
|
||||
for field in products[product_id]:
|
||||
if field["fieldName"] == "_price":
|
||||
field["value"] = f"${price}"
|
||||
updated_product.append(field)
|
||||
break
|
||||
|
||||
# Save to database
|
||||
ProductModel.save(product_id, tenant_id, updated_product, image_data, image_mime_type)
|
||||
|
||||
|
||||
@@ -62,25 +62,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
<!-- Fallback fields for backward compatibility -->
|
||||
{% if not custom_fields|selectattr('fieldName', 'equalto', '_name')|list %}
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Product Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name">
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if not custom_fields|selectattr('fieldName', 'equalto', '_price')|list %}
|
||||
<div class="mb-3">
|
||||
<label for="price" class="form-label">Price</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text">$</span>
|
||||
<input type="text" class="form-control" id="price" name="price" pattern="[0-9]+(\.[0-9]{1,2})?" placeholder="49.99">
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<div class="d-flex justify-content-between">
|
||||
<a href="/{{ tenant_id }}/" class="btn btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary">Add Product</button>
|
||||
|
||||
@@ -60,35 +60,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
<!-- Fallback fields for backward compatibility -->
|
||||
{% if not custom_fields|selectattr('fieldName', 'equalto', '_name')|list %}
|
||||
{% for field in product %}
|
||||
{% if field.fieldName == '_name' %}
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Product Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" value="{{ field.value }}">
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if not custom_fields|selectattr('fieldName', 'equalto', '_price')|list %}
|
||||
{% for field in product %}
|
||||
{% if field.fieldName == '_price' %}
|
||||
<div class="mb-3">
|
||||
<label for="price" class="form-label">Price</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text">$</span>
|
||||
{% set price_value = field.value|replace('$', '') %}
|
||||
<input type="text" class="form-control" id="price" name="price"
|
||||
pattern="[0-9]+(\.[0-9]{1,2})?" value="{{ price_value }}" placeholder="49.99">
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
<div class="d-flex justify-content-between">
|
||||
<a href="/{{ tenant_id }}/" class="btn btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary">Update Product</button>
|
||||
|
||||
Reference in New Issue
Block a user