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:
@@ -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, [], [], []);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user