Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 44ac25b063 | |||
| ee8459ca2a | |||
| 8e2e070eb7 | |||
| ec4e25946d |
@@ -357,4 +357,34 @@ class ProducerRepository
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Znajdź producenta po nazwie lub utwórz nowego (dla API).
|
||||||
|
*
|
||||||
|
* @return array{id: int, created: bool}
|
||||||
|
*/
|
||||||
|
public function ensureProducerForApi(string $name): array
|
||||||
|
{
|
||||||
|
$name = trim($name);
|
||||||
|
if ($name === '') {
|
||||||
|
return ['id' => 0, 'created' => false];
|
||||||
|
}
|
||||||
|
|
||||||
|
$existing = $this->db->get('pp_shop_producer', 'id', ['name' => $name]);
|
||||||
|
if (!empty($existing)) {
|
||||||
|
return ['id' => (int)$existing, 'created' => false];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->insert('pp_shop_producer', [
|
||||||
|
'name' => $name,
|
||||||
|
'status' => 1,
|
||||||
|
'img' => null,
|
||||||
|
]);
|
||||||
|
$id = (int)$this->db->id();
|
||||||
|
if ($id <= 0) {
|
||||||
|
return ['id' => 0, 'created' => false];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['id' => $id, 'created' => true];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -657,6 +657,7 @@ class ProductRepository
|
|||||||
'set_id' => $product['set_id'] !== null ? (int)$product['set_id'] : null,
|
'set_id' => $product['set_id'] !== null ? (int)$product['set_id'] : null,
|
||||||
'product_unit_id' => $product['product_unit_id'] !== null ? (int)$product['product_unit_id'] : null,
|
'product_unit_id' => $product['product_unit_id'] !== null ? (int)$product['product_unit_id'] : null,
|
||||||
'producer_id' => $product['producer_id'] !== null ? (int)$product['producer_id'] : null,
|
'producer_id' => $product['producer_id'] !== null ? (int)$product['producer_id'] : null,
|
||||||
|
'producer_name' => $this->resolveProducerName($product['producer_id']),
|
||||||
'date_add' => $product['date_add'],
|
'date_add' => $product['date_add'],
|
||||||
'date_modify' => $product['date_modify'],
|
'date_modify' => $product['date_modify'],
|
||||||
];
|
];
|
||||||
@@ -1121,6 +1122,21 @@ class ProductRepository
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zwraca nazwę producenta po ID (null jeśli brak).
|
||||||
|
*
|
||||||
|
* @param mixed $producerId
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
private function resolveProducerName($producerId): ?string
|
||||||
|
{
|
||||||
|
if (empty($producerId)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$name = $this->db->get('pp_shop_producer', 'name', ['id' => (int)$producerId]);
|
||||||
|
return ($name !== false && $name !== null) ? (string)$name : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Szczegóły produktu (admin) — zastępuje factory product_details().
|
* Szczegóły produktu (admin) — zastępuje factory product_details().
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -100,7 +100,8 @@ class ApiRouter
|
|||||||
$transportRepo = new \Domain\Transport\TransportRepository($db);
|
$transportRepo = new \Domain\Transport\TransportRepository($db);
|
||||||
$paymentRepo = new \Domain\PaymentMethod\PaymentMethodRepository($db);
|
$paymentRepo = new \Domain\PaymentMethod\PaymentMethodRepository($db);
|
||||||
$attrRepo = new \Domain\Attribute\AttributeRepository($db);
|
$attrRepo = new \Domain\Attribute\AttributeRepository($db);
|
||||||
return new Controllers\DictionariesApiController($statusRepo, $transportRepo, $paymentRepo, $attrRepo);
|
$producerRepo = new \Domain\Producer\ProducerRepository($db);
|
||||||
|
return new Controllers\DictionariesApiController($statusRepo, $transportRepo, $paymentRepo, $attrRepo, $producerRepo);
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ namespace api\Controllers;
|
|||||||
|
|
||||||
use api\ApiRouter;
|
use api\ApiRouter;
|
||||||
use Domain\Attribute\AttributeRepository;
|
use Domain\Attribute\AttributeRepository;
|
||||||
|
use Domain\Producer\ProducerRepository;
|
||||||
use Domain\ShopStatus\ShopStatusRepository;
|
use Domain\ShopStatus\ShopStatusRepository;
|
||||||
use Domain\Transport\TransportRepository;
|
use Domain\Transport\TransportRepository;
|
||||||
use Domain\PaymentMethod\PaymentMethodRepository;
|
use Domain\PaymentMethod\PaymentMethodRepository;
|
||||||
@@ -13,17 +14,20 @@ class DictionariesApiController
|
|||||||
private $transportRepo;
|
private $transportRepo;
|
||||||
private $paymentRepo;
|
private $paymentRepo;
|
||||||
private $attrRepo;
|
private $attrRepo;
|
||||||
|
private $producerRepo;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ShopStatusRepository $statusRepo,
|
ShopStatusRepository $statusRepo,
|
||||||
TransportRepository $transportRepo,
|
TransportRepository $transportRepo,
|
||||||
PaymentMethodRepository $paymentRepo,
|
PaymentMethodRepository $paymentRepo,
|
||||||
AttributeRepository $attrRepo
|
AttributeRepository $attrRepo,
|
||||||
|
ProducerRepository $producerRepo
|
||||||
) {
|
) {
|
||||||
$this->statusRepo = $statusRepo;
|
$this->statusRepo = $statusRepo;
|
||||||
$this->transportRepo = $transportRepo;
|
$this->transportRepo = $transportRepo;
|
||||||
$this->paymentRepo = $paymentRepo;
|
$this->paymentRepo = $paymentRepo;
|
||||||
$this->attrRepo = $attrRepo;
|
$this->attrRepo = $attrRepo;
|
||||||
|
$this->producerRepo = $producerRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function statuses(): void
|
public function statuses(): void
|
||||||
@@ -171,4 +175,34 @@ class DictionariesApiController
|
|||||||
'created' => !empty($result['created']),
|
'created' => !empty($result['created']),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function ensure_producer(): void
|
||||||
|
{
|
||||||
|
if (!ApiRouter::requireMethod('POST')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = ApiRouter::getJsonBody();
|
||||||
|
if (!is_array($body)) {
|
||||||
|
ApiRouter::sendError('BAD_REQUEST', 'Missing or invalid JSON body', 400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$name = trim((string) ($body['name'] ?? ''));
|
||||||
|
if ($name === '') {
|
||||||
|
ApiRouter::sendError('BAD_REQUEST', 'Missing name', 400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->producerRepo->ensureProducerForApi($name);
|
||||||
|
if ((int) ($result['id'] ?? 0) <= 0) {
|
||||||
|
ApiRouter::sendError('INTERNAL_ERROR', 'Failed to ensure producer', 500);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApiRouter::sendSuccess([
|
||||||
|
'id' => (int) ($result['id'] ?? 0),
|
||||||
|
'created' => !empty($result['created']),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -497,6 +497,21 @@ class ProductsApiController
|
|||||||
$d['products_related'] = $body['products_related'];
|
$d['products_related'] = $body['products_related'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Custom fields (Dodatkowe pola)
|
||||||
|
if (isset($body['custom_fields']) && is_array($body['custom_fields'])) {
|
||||||
|
$d['custom_field_name'] = [];
|
||||||
|
$d['custom_field_type'] = [];
|
||||||
|
$d['custom_field_required'] = [];
|
||||||
|
foreach ($body['custom_fields'] as $cf) {
|
||||||
|
if (!is_array($cf) || empty($cf['name'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$d['custom_field_name'][] = (string)$cf['name'];
|
||||||
|
$d['custom_field_type'][] = isset($cf['type']) ? (string)$cf['type'] : 'text';
|
||||||
|
$d['custom_field_required'][] = !empty($cf['is_required']) ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $d;
|
return $d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
docs/API.md
34
docs/API.md
@@ -219,6 +219,7 @@ Odpowiedz:
|
|||||||
"set_id": null,
|
"set_id": null,
|
||||||
"product_unit_id": 1,
|
"product_unit_id": 1,
|
||||||
"producer_id": 3,
|
"producer_id": 3,
|
||||||
|
"producer_name": "Nike",
|
||||||
"date_add": "2026-01-15 10:00:00",
|
"date_add": "2026-01-15 10:00:00",
|
||||||
"date_modify": "2026-02-19 12:00:00",
|
"date_modify": "2026-02-19 12:00:00",
|
||||||
"languages": {
|
"languages": {
|
||||||
@@ -301,11 +302,15 @@ Content-Type: application/json
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"categories": [1, 5],
|
"categories": [1, 5],
|
||||||
"products_related": [10, 20]
|
"products_related": [10, 20],
|
||||||
|
"custom_fields": [
|
||||||
|
{"name": "Napis na koszulce", "type": "text", "is_required": 1}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Wymagane: `languages` (min. 1 jezyk z `name`) oraz `price_brutto`.
|
Wymagane: `languages` (min. 1 jezyk z `name`) oraz `price_brutto`.
|
||||||
|
`custom_fields` — opcjonalne; kazdy element wymaga `name`, `type` (domyslnie `text`), `is_required` (0/1).
|
||||||
|
|
||||||
Odpowiedz (HTTP 201):
|
Odpowiedz (HTTP 201):
|
||||||
```json
|
```json
|
||||||
@@ -472,6 +477,31 @@ GET api.php?endpoint=dictionaries&action=attributes
|
|||||||
|
|
||||||
Zwraca aktywne atrybuty z wartosciami i wielojezycznymi nazwami.
|
Zwraca aktywne atrybuty z wartosciami i wielojezycznymi nazwami.
|
||||||
|
|
||||||
|
#### Znajdz lub utworz producenta
|
||||||
|
```
|
||||||
|
POST api.php?endpoint=dictionaries&action=ensure_producer
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "Nike"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Zwraca istniejacego producenta po nazwie lub tworzy nowego. Uzyc przed tworzeniem produktu, jesli producent moze nie istniec.
|
||||||
|
|
||||||
|
Odpowiedz:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": "ok",
|
||||||
|
"data": {
|
||||||
|
"id": 5,
|
||||||
|
"created": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`created: true` gdy producent zostal nowo dodany, `false` gdy juz istnial.
|
||||||
|
|
||||||
Odpowiedz:
|
Odpowiedz:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@@ -518,4 +548,4 @@ UPDATE pp_settings SET value = 'twoj-klucz-api' WHERE param = 'api_key';
|
|||||||
- Kontrolery: `autoload/api/Controllers/`
|
- Kontrolery: `autoload/api/Controllers/`
|
||||||
- `OrdersApiController` — zamowienia (5 akcji)
|
- `OrdersApiController` — zamowienia (5 akcji)
|
||||||
- `ProductsApiController` — produkty (8 akcji: list, get, create, update, variants, create_variant, update_variant, delete_variant)
|
- `ProductsApiController` — produkty (8 akcji: list, get, create, update, variants, create_variant, update_variant, delete_variant)
|
||||||
- `DictionariesApiController` — slowniki (4 akcje: statuses, transports, payment_methods, attributes)
|
- `DictionariesApiController` — slowniki (5 akcji: statuses, transports, payment_methods, attributes, ensure_producer)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace Tests\Unit\api\Controllers;
|
|||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use api\Controllers\DictionariesApiController;
|
use api\Controllers\DictionariesApiController;
|
||||||
use Domain\Attribute\AttributeRepository;
|
use Domain\Attribute\AttributeRepository;
|
||||||
|
use Domain\Producer\ProducerRepository;
|
||||||
use Domain\ShopStatus\ShopStatusRepository;
|
use Domain\ShopStatus\ShopStatusRepository;
|
||||||
use Domain\Transport\TransportRepository;
|
use Domain\Transport\TransportRepository;
|
||||||
use Domain\PaymentMethod\PaymentMethodRepository;
|
use Domain\PaymentMethod\PaymentMethodRepository;
|
||||||
@@ -14,6 +15,7 @@ class DictionariesApiControllerTest extends TestCase
|
|||||||
private $mockTransportRepo;
|
private $mockTransportRepo;
|
||||||
private $mockPaymentRepo;
|
private $mockPaymentRepo;
|
||||||
private $mockAttrRepo;
|
private $mockAttrRepo;
|
||||||
|
private $mockProducerRepo;
|
||||||
private $controller;
|
private $controller;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
@@ -22,12 +24,14 @@ class DictionariesApiControllerTest extends TestCase
|
|||||||
$this->mockTransportRepo = $this->createMock(TransportRepository::class);
|
$this->mockTransportRepo = $this->createMock(TransportRepository::class);
|
||||||
$this->mockPaymentRepo = $this->createMock(PaymentMethodRepository::class);
|
$this->mockPaymentRepo = $this->createMock(PaymentMethodRepository::class);
|
||||||
$this->mockAttrRepo = $this->createMock(AttributeRepository::class);
|
$this->mockAttrRepo = $this->createMock(AttributeRepository::class);
|
||||||
|
$this->mockProducerRepo = $this->createMock(ProducerRepository::class);
|
||||||
|
|
||||||
$this->controller = new DictionariesApiController(
|
$this->controller = new DictionariesApiController(
|
||||||
$this->mockStatusRepo,
|
$this->mockStatusRepo,
|
||||||
$this->mockTransportRepo,
|
$this->mockTransportRepo,
|
||||||
$this->mockPaymentRepo,
|
$this->mockPaymentRepo,
|
||||||
$this->mockAttrRepo
|
$this->mockAttrRepo,
|
||||||
|
$this->mockProducerRepo
|
||||||
);
|
);
|
||||||
|
|
||||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||||
|
|||||||
BIN
updates/0.30/ver_0.319.zip
Normal file
BIN
updates/0.30/ver_0.319.zip
Normal file
Binary file not shown.
26
updates/0.30/ver_0.319_manifest.json
Normal file
26
updates/0.30/ver_0.319_manifest.json
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"changelog": "FIX - usunięcie shopPRO eksportu produktów; API produktu: dodano custom_fields i security_information",
|
||||||
|
"version": "0.319",
|
||||||
|
"files": {
|
||||||
|
"added": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"deleted": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"modified": [
|
||||||
|
"autoload/Domain/Integrations/IntegrationsRepository.php",
|
||||||
|
"autoload/Domain/Product/ProductRepository.php",
|
||||||
|
"autoload/admin/Controllers/IntegrationsController.php",
|
||||||
|
"autoload/admin/Controllers/ShopProductController.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"checksum_zip": "sha256:99e07eb85aeca1c96607e95c90408bfbc166d97c0b999cc9eb033c6a4f208b97",
|
||||||
|
"sql": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"date": "2026-02-24",
|
||||||
|
"directories_deleted": [
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
BIN
updates/0.30/ver_0.320.zip
Normal file
BIN
updates/0.30/ver_0.320.zip
Normal file
Binary file not shown.
26
updates/0.30/ver_0.320_manifest.json
Normal file
26
updates/0.30/ver_0.320_manifest.json
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"changelog": "NEW - API: endpoint ensure_producer (znajdź lub utwórz producenta); GET product zwraca producer_name",
|
||||||
|
"version": "0.320",
|
||||||
|
"files": {
|
||||||
|
"added": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"deleted": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"modified": [
|
||||||
|
"autoload/Domain/Producer/ProducerRepository.php",
|
||||||
|
"autoload/Domain/Product/ProductRepository.php",
|
||||||
|
"autoload/api/ApiRouter.php",
|
||||||
|
"autoload/api/Controllers/DictionariesApiController.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"checksum_zip": "sha256:eb38b6f260768c25d331de60098eba647a897972c211b37b39314c8a3f954bf3",
|
||||||
|
"sql": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"date": "2026-02-24",
|
||||||
|
"directories_deleted": [
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
|||||||
<?
|
<?
|
||||||
$current_ver = 319;
|
$current_ver = 321;
|
||||||
|
|
||||||
for ($i = 1; $i <= $current_ver; $i++)
|
for ($i = 1; $i <= $current_ver; $i++)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user