fix(product): fix error when image not found

This commit is contained in:
2025-09-25 07:57:33 +03:00
parent a3e5b8b07a
commit a381b3a6ee

View File

@@ -8,6 +8,7 @@ use Cart\Tax;
use Exception;
use Openguru\OpenCartFramework\Config\Settings;
use Openguru\OpenCartFramework\ImageTool\ImageToolInterface;
use Openguru\OpenCartFramework\Logger\LoggerInterface;
use Openguru\OpenCartFramework\OpenCart\Decorators\OcRegistryDecorator;
use Openguru\OpenCartFramework\QueryBuilder\Builder;
use Openguru\OpenCartFramework\QueryBuilder\JoinClause;
@@ -23,6 +24,7 @@ class ProductsService
private OcModelCatalogProductAdapter $ocModelCatalogProduct;
private ImageToolInterface $ocImageTool;
private OcRegistryDecorator $oc;
private LoggerInterface $logger;
public function __construct(
Builder $queryBuilder,
@@ -31,7 +33,8 @@ class ProductsService
Settings $settings,
OcModelCatalogProductAdapter $ocModelCatalogProduct,
ImageToolInterface $ocImageTool,
OcRegistryDecorator $registry
OcRegistryDecorator $registry,
LoggerInterface $logger
) {
$this->queryBuilder = $queryBuilder;
$this->currency = $currency;
@@ -40,6 +43,7 @@ class ProductsService
$this->ocModelCatalogProduct = $ocModelCatalogProduct;
$this->ocImageTool = $ocImageTool;
$this->oc = $registry;
$this->logger = $logger;
}
public function getProductsResponse(array $params): array
@@ -247,19 +251,23 @@ class ProductsService
$images = [];
foreach ($imagePaths as $imagePath) {
[$width, $height] = $this->ocImageTool->getRealSize($imagePath);
$images[] = [
'thumbnailURL' => $this->ocImageTool->resize($imagePath, $imageWidth, $imageHeight, 'placeholder.png'),
'largeURL' => $this->ocImageTool->resize(
$imagePath,
$imageFullWidth,
$imageFullHeight,
'placeholder.png'
),
'width' => $width,
'height' => $height,
'alt' => $product['product_name'],
];
try {
[$width, $height] = $this->ocImageTool->getRealSize($imagePath);
$images[] = [
'thumbnailURL' => $this->ocImageTool->resize($imagePath, $imageWidth, $imageHeight, 'placeholder.png'),
'largeURL' => $this->ocImageTool->resize(
$imagePath,
$imageFullWidth,
$imageFullHeight,
'placeholder.png'
),
'width' => $width,
'height' => $height,
'alt' => $product['product_name'],
];
} catch (Exception $e) {
$this->logger->logException($e);
}
}
$price = $this->currency->format(