- Add variant CRUD endpoints (variants, create_variant, update_variant, delete_variant) - Add dictionaries/attributes endpoint with multilingual names and values - Add attribute_* filter params for product list filtering by attribute values - Enrich product detail attributes with translated names (attribute_names, value_names) - Include variants array in product detail response for parent products - Add price_brutto validation on product create - Batch-load attribute/value translations (4 queries instead of N+1) - Add 43 new unit tests (730 total, 2066 assertions) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
98 lines
2.4 KiB
PHP
98 lines
2.4 KiB
PHP
<?php
|
|
namespace api\Controllers;
|
|
|
|
use api\ApiRouter;
|
|
use Domain\Attribute\AttributeRepository;
|
|
use Domain\ShopStatus\ShopStatusRepository;
|
|
use Domain\Transport\TransportRepository;
|
|
use Domain\PaymentMethod\PaymentMethodRepository;
|
|
|
|
class DictionariesApiController
|
|
{
|
|
private $statusRepo;
|
|
private $transportRepo;
|
|
private $paymentRepo;
|
|
private $attrRepo;
|
|
|
|
public function __construct(
|
|
ShopStatusRepository $statusRepo,
|
|
TransportRepository $transportRepo,
|
|
PaymentMethodRepository $paymentRepo,
|
|
AttributeRepository $attrRepo
|
|
) {
|
|
$this->statusRepo = $statusRepo;
|
|
$this->transportRepo = $transportRepo;
|
|
$this->paymentRepo = $paymentRepo;
|
|
$this->attrRepo = $attrRepo;
|
|
}
|
|
|
|
public function statuses(): void
|
|
{
|
|
if (!ApiRouter::requireMethod('GET')) {
|
|
return;
|
|
}
|
|
|
|
$statuses = $this->statusRepo->allStatuses();
|
|
|
|
$result = [];
|
|
foreach ($statuses as $id => $name) {
|
|
$result[] = [
|
|
'id' => (int)$id,
|
|
'name' => (string)$name,
|
|
];
|
|
}
|
|
|
|
ApiRouter::sendSuccess($result);
|
|
}
|
|
|
|
public function transports(): void
|
|
{
|
|
if (!ApiRouter::requireMethod('GET')) {
|
|
return;
|
|
}
|
|
|
|
$transports = $this->transportRepo->allActive();
|
|
|
|
$result = [];
|
|
foreach ($transports as $transport) {
|
|
$result[] = [
|
|
'id' => (int)($transport['id'] ?? 0),
|
|
'name' => (string)($transport['name_visible'] ?? $transport['name'] ?? ''),
|
|
'cost' => (float)($transport['cost'] ?? 0),
|
|
];
|
|
}
|
|
|
|
ApiRouter::sendSuccess($result);
|
|
}
|
|
|
|
public function payment_methods(): void
|
|
{
|
|
if (!ApiRouter::requireMethod('GET')) {
|
|
return;
|
|
}
|
|
|
|
$methods = $this->paymentRepo->allActive();
|
|
|
|
$result = [];
|
|
foreach ($methods as $method) {
|
|
$result[] = [
|
|
'id' => (int)($method['id'] ?? 0),
|
|
'name' => (string)($method['name'] ?? ''),
|
|
];
|
|
}
|
|
|
|
ApiRouter::sendSuccess($result);
|
|
}
|
|
|
|
public function attributes(): void
|
|
{
|
|
if (!ApiRouter::requireMethod('GET')) {
|
|
return;
|
|
}
|
|
|
|
$attributes = $this->attrRepo->listForApi();
|
|
|
|
ApiRouter::sendSuccess($attributes);
|
|
}
|
|
}
|