Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/components/minishop3/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*
* Использование:
* api.php?route=/api/v1/customer/token/get
* api.php?route=/api/v1/product/list
* api.php?route=/api/v1/product/get/123
* api.php?route=/api/v1/cart/add
*
* @package MiniShop3
Expand Down
12 changes: 6 additions & 6 deletions core/components/minishop3/config/routes/web.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* WEB API Routes for MiniShop3
*
Expand Down Expand Up @@ -277,19 +278,18 @@
$controller = new \MiniShop3\Controllers\Api\Web\CustomerOrderController($modx);
return $controller->cancel($params);
}, [$tokenMiddleware]);

});

// Public catalog — no TokenMiddleware (headless storefront without customer session)
$router->group('/product', function($router) use ($modx) {

$router->get('/get/{id}', function($params) use ($modx) {
return Response::success(['message' => 'Product get endpoint - not implemented yet', 'id' => $params['id'] ?? null]);
$controller = new \MiniShop3\Controllers\Api\Web\ProductController($modx);
return $controller->get($params);
});

$router->get('/list', function($params) use ($modx) {
return Response::success(['message' => 'Product list endpoint - not implemented yet']);
$controller = new \MiniShop3\Controllers\Api\Web\ProductController($modx);
return $controller->getList($params);
});

});
$router->get('/health', function() use ($modx) {
return Response::success([
Expand Down
2 changes: 2 additions & 0 deletions core/components/minishop3/lexicon/en/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@
$_lang['ms3_repeater_validation_error'] = 'Repeater field "[[+field]]": [[+error]]';

$_lang['ms3_err_user_nf'] = 'User not found.';
$_lang['ms3_err_product_nf'] = 'Product not found.';
$_lang['ms3_err_product_id_ns'] = 'Product ID is required.';
$_lang['ms3_err_order_nf'] = 'Order with this identifier not found.';
$_lang['ms3_err_order_load'] = 'Error loading order.';
$_lang['ms3_err_status_nf'] = 'Status with this identifier not found.';
Expand Down
2 changes: 2 additions & 0 deletions core/components/minishop3/lexicon/ru/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@
$_lang['ms3_repeater_validation_error'] = 'Поле повторителя «[[+field]]»: [[+error]]';

$_lang['ms3_err_user_nf'] = 'Пользователь не найден.';
$_lang['ms3_err_product_nf'] = 'Товар не найден.';
$_lang['ms3_err_product_id_ns'] = 'Не указан ID товара.';
$_lang['ms3_err_order_nf'] = 'Заказ с таким идентификатором не найден.';
$_lang['ms3_err_order_load'] = 'Ошибка при загрузке заказа.';
$_lang['ms3_err_status_nf'] = 'Статус с таким идентификатором не найден.';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

namespace MiniShop3\Controllers\Api\Web;

use MiniShop3\Router\HttpStatus;
use MiniShop3\Router\Response;
use MiniShop3\Services\Product\ProductCatalogService;
use MODX\Revolution\modX;

/**
* Public catalog endpoints for Web API.
*
* No customer token required — same public surface as storefront SSR.
*/
class ProductController
{
protected modX $modx;

public function __construct(modX $modx)
{
$this->modx = $modx;
$this->modx->lexicon->load('minishop3:default');
}

/**
* GET /api/v1/product/get/{id}
*
* @param array<string, mixed> $params
*/
public function get(array $params = []): Response
{
$productId = (int) ($params['id'] ?? 0);

if ($productId <= 0) {
return Response::error(
$this->modx->lexicon('ms3_err_product_id_ns'),
HttpStatus::BAD_REQUEST
);
}

$product = $this->catalog()->getById($productId, $params);

if ($product === null) {
return Response::error(
$this->modx->lexicon('ms3_err_product_nf'),
HttpStatus::NOT_FOUND
);
}

return Response::success($product);
}

/**
* GET /api/v1/product/list
*
* Query: parent|category, limit, offset|page, sort, dir, query,
* context, include_options, include_content
*
* @param array<string, mixed> $params Route + query params (Router merges $_GET)
*/
public function getList(array $params = []): Response
{
$result = $this->catalog()->getList($params);

return Response::success($result);
}

private function catalog(): ProductCatalogService
{
/** @var ProductCatalogService $service */
$service = $this->modx->services->get('ms3_product_catalog');

return $service;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Cookie injection at start of handle() copies $_COOKIE['ms3_token'] → $_REQUEST['ms3_token']
* for backward compatibility with controllers reading $_REQUEST.
*
* For public endpoints (cart/get, product/get) token is optional.
* For public endpoints listed in $publicRoutes (product/*, token/get, …) token is optional.
* For non-public endpoints without token — auto-creates anonymous token.
*/
class TokenMiddleware implements MiddlewareInterface
Expand Down
4 changes: 4 additions & 0 deletions core/components/minishop3/src/ServiceRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class ServiceRegistry
'class' => \MiniShop3\Services\Product\ProductDataService::class,
'interface' => null,
],
'ms3_product_catalog' => [
'class' => \MiniShop3\Services\Product\ProductCatalogService::class,
'interface' => null,
],
'ms3_repeater_field' => [
'class' => \MiniShop3\Services\ExtraFields\RepeaterFieldService::class,
'interface' => null,
Expand Down
Loading