feat: bulk delete in product archive (v0.327)

- Add bulk_delete_permanent() endpoint (POST ids[], returns JSON)
- Checkbox column + bulk action bar with count label
- Select-all in table header, confirmation dialog before delete
- 2 new tests for bulk_delete_permanent method signature

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 20:37:22 +01:00
parent c59501603d
commit 0a14c92109
5 changed files with 201 additions and 0 deletions

View File

@@ -92,6 +92,7 @@ class ProductArchiveController
. $skuEanHtml;
$rows[] = [
'_checkbox' => '<input type="checkbox" class="js-bulk-check" value="' . $id . '" aria-label="Zaznacz produkt">',
'lp' => $lp++ . '.',
'product' => $productCell,
'price_brutto' => $priceBrutto !== '' ? $priceBrutto : '-',
@@ -123,6 +124,7 @@ class ProductArchiveController
$viewModel = new \admin\ViewModels\Common\PaginatedTableViewModel(
[
['key' => '_checkbox', 'label' => '', 'class' => 'text-center table-col-bulk-check', 'sortable' => false, 'raw' => true],
['key' => 'lp', 'label' => 'Lp.', 'class' => 'text-center', 'sortable' => false],
['key' => 'product', 'sort_key' => 'name', 'label' => 'Nazwa', 'sortable' => true, 'raw' => true],
['key' => 'price_brutto', 'sort_key' => 'price_brutto', 'label' => 'Cena', 'class' => 'text-center', 'sortable' => true],
@@ -190,4 +192,40 @@ class ProductArchiveController
header( 'Location: /admin/product_archive/list/' );
exit;
}
public function bulk_delete_permanent(): void
{
header( 'Content-Type: application/json; charset=utf-8' );
$rawIds = isset( $_POST['ids'] ) && is_array( $_POST['ids'] ) ? $_POST['ids'] : [];
$ids = [];
foreach ( $rawIds as $raw ) {
$id = (int) $raw;
if ( $id > 0 ) {
$ids[] = $id;
}
}
if ( empty( $ids ) ) {
echo json_encode( ['success' => false, 'message' => 'Nie wybrano żadnych produktów.'] );
exit;
}
$deleted = 0;
$errors = [];
foreach ( $ids as $id ) {
if ( $this->productRepository->delete( $id ) ) {
$deleted++;
} else {
$errors[] = $id;
}
}
echo json_encode( [
'success' => empty( $errors ),
'deleted' => $deleted,
'errors' => $errors,
] );
exit;
}
}