feat(products-feed): replace fixed image dimensions with aspect ratio selection

- Added image aspect ratio selection (1:1, 4:5, 3:4, 2:3) to ProductsFeed block configuration in Admin panel
- Removed manual width/height input fields
- Updated ProductsFeed block in SPA to send aspect ratio parameter instead of dimensions
- Implemented backend logic to calculate image height based on selected aspect ratio and base width (300px)
- Updated default configuration for products_feed block
- Added descriptive help text for each aspect ratio option in the dropdown
This commit is contained in:
2025-12-06 15:46:37 +03:00
committed by Nikita Kiselev
parent 13e5bce8a5
commit cd060610fe
10 changed files with 99 additions and 17 deletions

View File

@@ -73,6 +73,7 @@ TEXT,
'goal_name' => '',
'data' => [
'max_page_count' => 10,
'image_aspect_ratio' => '1:1',
],
],
],

View File

@@ -8,11 +8,11 @@ use App\Services\ProductsService;
use App\Services\SettingsService;
use Exception;
use Openguru\OpenCartFramework\Exceptions\EntityNotFoundException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Openguru\OpenCartFramework\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Psr\Log\LoggerInterface;
use RuntimeException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
class ProductsHandler
{
@@ -34,11 +34,16 @@ class ProductsHandler
$maxPages = (int) $request->json('maxPages', 10);
$search = trim($request->get('search', ''));
$filters = $request->json('filters');
$width = (int) $request->json('width', 300);
$height = (int) $request->json('height', 300);
$languageId = $this->settings->config()->getApp()->getLanguageId();
$response = $this->productsService->getProductsResponse(
compact('page', 'perPage', 'search', 'filters', 'maxPages'),
$languageId,
$width,
$height,
);
return new JsonResponse($response);

View File

@@ -6,6 +6,7 @@ use Openguru\OpenCartFramework\Cache\CacheInterface;
use Openguru\OpenCartFramework\ImageTool\ImageFactory;
use Openguru\OpenCartFramework\QueryBuilder\Builder;
use Openguru\OpenCartFramework\QueryBuilder\JoinClause;
use Openguru\OpenCartFramework\Support\Arr;
use RuntimeException;
class BlocksService
@@ -17,6 +18,13 @@ class BlocksService
'products_carousel' => [self::class, 'processProductsCarousel'],
];
private static array $aspectRatiosMap = [
'1:1' => [400, 400],
'4:5' => [400, 500],
'3:4' => [400, 533],
'2:3' => [400, 600],
];
private ImageFactory $image;
private CacheInterface $cache;
private SettingsService $settings;
@@ -113,6 +121,11 @@ class BlocksService
private function processProductsFeed(array $block): array
{
[$width, $height] = $this->aspectRatioToSize(Arr::get($block, 'data.image_aspect_ratio', '1:1'));
Arr::set($block, 'data.image_width', $width);
Arr::set($block, 'data.image_height', $height);
return $block;
}
@@ -147,4 +160,9 @@ class BlocksService
return $block;
}
private function aspectRatioToSize($aspectRatio): array
{
return self::$aspectRatiosMap[$aspectRatio] ?? [400, 400];
}
}

View File

@@ -53,17 +53,22 @@ class ProductsService
/**
* @throws ImageNotFoundException
*/
public function getProductsResponse(array $params, int $languageId): array
{
public function getProductsResponse(
array $params,
int $languageId,
int $imageWidth = 300,
int $imageHeight = 300
): array {
$page = $params['page'];
$perPage = $params['perPage'];
$search = $params['search'] ?? false;
$categoryName = '';
$imageWidth = 300;
$imageHeight = 300;
$maxPages = $params['maxPages'] ?? 50;
$filters = $params['filters'] ?? [];
$imageWidth = $imageWidth ?: 300;
$imageHeight = $imageHeight ?: 300;
$customerGroupId = $this->settings->config()->getOrders()->getOcCustomerGroupId();
$currency = $this->settings->config()->getStore()->getOcDefaultCurrency();