fix: Custom fields delete bug — usunięcie wszystkich pól produktu nie działało
Dodano hidden marker custom_field_name_present w formularzu edycji produktu.
Zmieniono warunek w ProductRepository z array_key_exists('custom_field_name')
na array_key_exists('custom_field_name_present') — jQuery .serialize() pomijał
klucz pustej tablicy gdy wszystkie pola usunięte. Test jednostkowy dodany.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1335,8 +1335,9 @@ class ProductRepository
|
||||
$this->saveImagesOrder( $productId, $d['gallery_order'] );
|
||||
}
|
||||
|
||||
// Zapisz custom fields tylko gdy jawnie podane (partial update przez API może nie zawierać tego klucza)
|
||||
if ( array_key_exists( 'custom_field_name', $d ) ) {
|
||||
// Zapisz custom fields tylko gdy formularz edycji renderował sekcję (marker hidden field)
|
||||
// API partial update nie zawiera tego markera — custom fields pominięte
|
||||
if ( array_key_exists( 'custom_field_name_present', $d ) ) {
|
||||
$this->saveCustomFields( $productId, $d['custom_field_name'] ?? [], $d['custom_field_type'] ?? [], $d['custom_field_required'] ?? [] );
|
||||
}
|
||||
|
||||
|
||||
@@ -699,7 +699,8 @@ class ShopProductController
|
||||
|
||||
private function renderCustomFieldsBox( array $product ): string
|
||||
{
|
||||
$html = '<a href="#" class="btn btn-success" id="add_custom_field"><i class="fa fa-plus"></i> dodaj niestandardowe pole</a>';
|
||||
$html = '<input type="hidden" name="custom_field_name_present" value="1">';
|
||||
$html .= '<a href="#" class="btn btn-success" id="add_custom_field"><i class="fa fa-plus"></i> dodaj niestandardowe pole</a>';
|
||||
$html .= '<div class="additional_fields pt-3">';
|
||||
|
||||
$customFields = is_array( $product['custom_fields'] ?? null ) ? $product['custom_fields'] : [];
|
||||
|
||||
Reference in New Issue
Block a user