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:
Jacek
2026-04-16 22:51:57 +02:00
parent b03816e8ec
commit 1ef6dc9092
12 changed files with 318 additions and 19 deletions

View File

@@ -1292,4 +1292,25 @@ class ProductRepositoryTest extends TestCase
$this->assertFalse($result);
}
public function testSaveCustomFieldsDeletesAllWhenEmpty(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('delete')
->with(
$this->equalTo('pp_shop_products_custom_fields'),
$this->equalTo(['id_product' => 55])
);
$mockDb->expects($this->never())->method('insert');
$mockDb->expects($this->never())->method('update');
$repository = new ProductRepository($mockDb);
$method = new \ReflectionMethod(ProductRepository::class, 'saveCustomFields');
$method->setAccessible(true);
$method->invoke($repository, 55, [], [], []);
}
}